jdk/src/sample/solaris/dtrace/hotspot_jni/CriticalSection.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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     4
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    17
 *   - Neither the name of Oracle nor the names of its
2
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.d -c "java ..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *    2. CriticalSection.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
int CRITICAL_SECTION_VIOLATION_CNT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
:::BEGIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    SAMPLE_NAME = "critical section violation checks";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    printf("BEGIN %s\n", SAMPLE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *   Multiple pairs of GetPrimitiveArrayCritical/ReleasePrimitiveArrayCritical,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *   GetStringCritical/ReleaseStringCritical may be nested
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
hotspot_jni$target:::*_entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
/self->in_critical_section > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  probename != "GetPrimitiveArrayCritical_entry" &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  probename != "GetStringCritical_entry" &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
  probename != "ReleasePrimitiveArrayCritical_entry" &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  probename != "ReleaseStringCritical_entry" &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  probename != "GetPrimitiveArrayCritical_return" &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
  probename != "GetStringCritical_return" &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  probename != "ReleasePrimitiveArrayCritical_return" &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  probename != "ReleaseStringCritical_return"/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    printf("\nJNI call %s made from JNI critical region '%s'\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        probename, self->critical_section_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    printf("Jstack:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    jstack(50, 500);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    CRITICAL_SECTION_VIOLATION_CNT ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
syscall:::entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
/pid == $target && self->in_critical_section > 0/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    printf("\nSystem call %s made in JNI critical region '%s'\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        probefunc, self->critical_section_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    printf("Jstack:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    jstack(50, 500);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    CRITICAL_SECTION_VIOLATION_CNT ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
hotspot_jni$target:::ReleasePrimitiveArrayCritical_entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
hotspot_jni$target:::ReleaseStringCritical_entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
/self->in_critical_section > 0/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    self->in_critical_section --;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
hotspot_jni$target:::GetPrimitiveArrayCritical_return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    self->in_critical_section ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    self->critical_section_name = "GetPrimitiveArrayCritical";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
hotspot_jni$target:::GetStringCritical_return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    self->in_critical_section ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    self->critical_section_name = "GetStringCritical";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
:::END
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    printf("%d critical section violations have been discovered\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        CRITICAL_SECTION_VIOLATION_CNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    printf("\nEND of %s\n", SAMPLE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
}