jdk/src/sample/solaris/dtrace/hotspot/class_loading_stat.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. class_loading_stat.d -c "java ..." INTERVAL_SECS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *    2. class_loading_stat.d -p JAVA_PID INTERVAL_SECS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This script collects statistics about loaded and unloaded Java classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * and dump current state to stdout every INTERVAL_SECS seconds.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * INTERVAL_SECS is not set then 10 seconds interval is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#pragma D option quiet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#pragma D option destructive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#pragma D option defaultargs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#pragma D option aggrate=100ms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
self char *str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
self string class_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
self string package_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
int INTERVAL_SECS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
:::BEGIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    SAMPLE_NAME = "hotspot class loadin tracing";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    INTERVAL_SECS = $1 ? $1 : 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    SAMPLING_TIME = timestamp + INTERVAL_SECS * 1000000000ull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    LOADED_CLASSES_CNT = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    UNLOADED_CLASSES_CNT = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    LINE_SEP =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    "------------------------------------------------------------------------";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    printf("BEGIN %s\n\n", SAMPLE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * hotspot:::class-loaded, hotspot:::class-unloaded probe arguments:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *  arg0: char*,        class name passed as mUTF8 string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *  arg1: uintptr_t,    class name length
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *  arg2: void*,        class loader ID, which is unique identifier for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *                      a class loader in the VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *  arg3: uintptr_t,    class is shared or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
hotspot$target:::class-loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    LOADED_CLASSES_CNT ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    self->str_ptr = (char*) copyin(arg0, arg1+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    self->str_ptr[arg1] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    self->class_name = (string) self->str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    self->package_name = dirname(self->class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    @classes_loaded[self->package_name] = count();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
hotspot$target:::class-unloaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    UNLOADED_CLASSES_CNT ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    self->str_ptr = (char*) copyin(arg0, arg1+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    self->str_ptr[arg1] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    self->class_name = (string) self->str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    self->package_name = dirname(self->class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    @classes_unloaded[self->package_name] = count();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
tick-1sec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
/timestamp > SAMPLING_TIME/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    printf("%s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    printf("%Y\n", walltimestamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    printf("%s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    printf("Loaded classes by package:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    printa("%10@d %s\n", @classes_loaded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    printf("Unloaded classes by package:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    printa("%10@d %s\n", @classes_unloaded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    printf("Number of loaded classes: %10d\n", LOADED_CLASSES_CNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    printf("Number of unloaded classes: %10d\n", UNLOADED_CLASSES_CNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    SAMPLING_TIME = timestamp + INTERVAL_SECS * 1000000000ull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
:::END
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    printf("%s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    printf("%Y\n", walltimestamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    printf("%s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    printf("Loaded classes by package:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    printa("%10@d %s\n", @classes_loaded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    printf("Unloaded classes by package:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    printa("%10@d %s\n", @classes_unloaded);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    printf("Number of loaded classes: %10d\n", LOADED_CLASSES_CNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    printf("Number of unloaded classes: %10d\n", UNLOADED_CLASSES_CNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    printf("\nEND of %s\n", SAMPLE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
syscall::rexit:entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
syscall::exit:entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
/pid == $target/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
   exit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
}