jdk/src/solaris/sample/dtrace/hotspot_jni/CriticalSection_slow.d
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *   - Neither the name of Sun Microsystems nor the names of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Usage:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *    1. CriticalSection_slow.d -c "java ..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *    2. CriticalSection_slow.d -p JAVA_PID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The script inspect a JNI application for Critical Section violations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Critical section is the space between calls to JNI methods:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *   - GetPrimitiveArrayCritical and ReleasePrimitiveArrayCritical; or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   - GetStringCritical and ReleaseStringCritical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Inside a critical section, native code must not call other JNI functions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * or any system call that may cause the current thread to block and wait
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * for another Java thread. (For example, the current thread must not call
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * read on a stream being written by another Java thread.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#pragma D option quiet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#pragma D option destructive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#pragma D option defaultargs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#pragma D option bufsize=16m
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
#pragma D option aggrate=100ms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
self int in_critical_section;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
self string critical_section_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
self char *str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
self string class_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
self string method_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
self string signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
self int indent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
self int JAVA_STACK_DEEP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
int CRITICAL_SECTION_VIOLATION_CNT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
:::BEGIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    SAMPLE_NAME = "critical section violation checks";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    printf("BEGIN %s\n", SAMPLE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
hotspot$target:::*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
/!self->JAVA_STACK_DEEP/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    self->JAVA_STACK_DEEP = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
hotspot$target:::method-return
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
/self->JAVA_STACK_DEEP > 0/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    self->JAVA_STACK_DEEP --;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
hotspot$target:::method-entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    self->JAVA_STACK_DEEP ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    self->str_ptr = (char*) copyin(arg1, arg2+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    self->str_ptr[arg2] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    self->method_name = strjoin( (string) self->str_ptr, ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    self->str_ptr = (char*) copyin(arg3, arg4+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    self->str_ptr[arg4] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    self->method_name = strjoin(self->method_name, (string) self->str_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    self->method_name = strjoin(self->method_name, ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    self->str_ptr = (char*) copyin(arg5, arg6+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    self->str_ptr[arg6] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    self->method_name = strjoin(self->method_name, (string) self->str_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    self->JAVA_STACK[self->JAVA_STACK_DEEP] = self->method_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
/*    printf("%-10u%*s%s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *      curcpu->cpu_id, self->indent, "", self->method_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *   Multiple pairs of GetPrimitiveArrayCritical/ReleasePrimitiveArrayCritical,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *   GetStringCritical/ReleaseStringCritical may be nested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
hotspot_jni$target:::*_entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
/self->in_critical_section > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
  probename != "GetPrimitiveArrayCritical_entry" &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
  probename != "GetStringCritical_entry" &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  probename != "ReleasePrimitiveArrayCritical_entry" &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  probename != "ReleaseStringCritical_entry" &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
  probename != "GetPrimitiveArrayCritical_return" &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
  probename != "GetStringCritical_return" &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  probename != "ReleasePrimitiveArrayCritical_return" &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
  probename != "ReleaseStringCritical_return"/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    printf("JNI call %s made from JNI critical region '%s' from %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        probename, self->critical_section_name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        self->JAVA_STACK[self->JAVA_STACK_DEEP]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    CRITICAL_SECTION_VIOLATION_CNT ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
syscall:::entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
/pid == $target && self->in_critical_section > 0/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    printf("system call %s made in JNI critical region '%s' from %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        probefunc, self->critical_section_name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        self->JAVA_STACK[self->JAVA_STACK_DEEP]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    CRITICAL_SECTION_VIOLATION_CNT ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
hotspot_jni$target:::ReleasePrimitiveArrayCritical_entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
hotspot_jni$target:::ReleaseStringCritical_entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
/self->in_critical_section > 0/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    self->in_critical_section --;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
hotspot_jni$target:::GetPrimitiveArrayCritical_return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    self->in_critical_section ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    self->critical_section_name = "GetPrimitiveArrayCritical";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
hotspot_jni$target:::GetStringCritical_return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    self->in_critical_section ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    self->critical_section_name = "GetStringCritical";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
:::END
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    printf("%d critical section violations have been discovered\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        CRITICAL_SECTION_VIOLATION_CNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    printf("\nEND of %s\n", SAMPLE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
}