jdk/src/sample/solaris/dtrace/hotspot/monitors.d
author hseigel
Wed, 01 Mar 2017 08:00:02 -0500
changeset 46194 5596e6f63072
parent 25859 3317bb8137f4
permissions -rw-r--r--
8172307: Remove ununsed JVM API JVM_GetModuleByPackageName() Summary: Remove get_module_by_package_name() etc., and unneeded test. Reviewed-by: sspitsyn, gtriantafill
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
#!/usr/sbin/dtrace -Zs
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     3
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    16
 *   - Neither the name of Oracle nor the names of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Usage:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *   1. monitors.d -c "java ..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *   2. monitors.d -p JAVA_PID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The script traces monitor related probes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Notes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *  - These probes are disabled by default since it incurs performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *    overhead to the application. To trace the monitor-* probes, you need
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *    to turn on the ExtendedDTraceProbes VM option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *    You can either start the application with -XX:+ExtendedDTraceProbes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *    option or use the jinfo command to enable it at runtime as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *       jinfo -flag +ExtendedDTraceProbes <java_pid>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#pragma D option quiet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#pragma D option destructive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#pragma D option defaultargs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#pragma D option aggrate=100ms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
self string thread_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
self char* str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
:::BEGIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    SAMPLE_NAME = "hotspot monitors tracing";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    printf("BEGIN %s\n\n", SAMPLE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * hotspot:::thread-start, hotspot:::thread-stop probe arguments:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *  arg0: char*,        thread name passed as mUTF8 string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *  arg1: uintptr_t,    thread name length
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *  arg2: uintptr_t,    Java thread id
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *  arg3: uintptr_t,    native/OS thread id
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *  arg4: uintptr_t,    is a daemon or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
hotspot$target:::thread-start
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    self->str_ptr = (char*) copyin(arg0, arg1+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    self->str_ptr[arg1] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    self->thread_name = (string) self->str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    printf("thread-start: id=%d, is_daemon=%d, name=%s, os_id=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            arg2, arg4, self->thread_name, arg3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    threads[arg2] = self->thread_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
hotspot$target:::thread-stop
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    self->str_ptr = (char*) copyin(arg0, arg1+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    self->str_ptr[arg1] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    self->thread_name = (string) self->str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    printf("thread-stop: id=%d, is_daemon=%d, name=%s, os_id=%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            arg2, arg4, self->thread_name, arg3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * hotspot::monitor-contended-enter, hotspot::monitor-contended-entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *  arg0: uintptr_t,    the Java thread identifier for the thread peforming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *                          the monitor operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *  arg1: uintptr_t,    a unique, but opaque identifier for the specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *                          monitor that the action is performed upon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *  arg2: char*,        a pointer to mUTF-8 string data which contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *                          name of the class of the object being acted upon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *  arg3: uintptr_t,    the length of the class name (in bytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
hotspot$target:::monitor-contended-enter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /* (uintptr_t thread_id, uintptr_t monitor_id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
       char* obj_class_name, uintptr_t obj_class_name_len) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    self->str_ptr = (char*) copyin(arg2, arg3+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    self->str_ptr[arg3] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    self->class_name = (string) self->str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    monitors[arg1] = self->class_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    monitors_enter[arg1] = arg0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    printf("%s: -> enter monitor (%d) %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        threads[arg0], arg1, monitors[arg1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
hotspot$target:::monitor-contended-entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /* (uintptr_t thread_id, uintptr_t monitor_id, char* obj_class_name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        uintptr_t obj_class_name_len) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    monitors_entered[arg1] = arg0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    printf("%s: <- entered monitor (%d) %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        threads[arg0], arg1, monitors[arg1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
:::END
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    printf("\nEND of %s\n", SAMPLE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
syscall::rexit:entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
syscall::exit:entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
/pid == $target/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
   exit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
}