jdk/src/jdk.hprof.agent/share/classes/com/sun/demo/jvmti/hprof/Tracker.java
author stefank
Mon, 25 Aug 2014 09:10:13 +0200
changeset 26314 f8bc1966fb30
parent 25859 3317bb8137f4
permissions -rw-r--r--
8055416: Several vm/gc/heap/summary "After GC" events emitted for the same GC ID Reviewed-by: brutisso, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 20823
diff changeset
     2
 * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    15
 *   - Neither the name of Oracle nor the names of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
package com.sun.demo.jvmti.hprof;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/* This class and it's methods are used by hprof when injecting bytecodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *   into class file images.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *   See the directory src/share/demo/jvmti/hprof and the file README.txt
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *   for more details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class Tracker {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /* Master switch that activates calls to native functions. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static int engaged = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /* To track memory allocated, we need to catch object init's and arrays. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /* At the beginning of java.jang.Object.<init>(), a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *   Tracker.ObjectInit() is injected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static native void nativeObjectInit(Object thr, Object obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static void ObjectInit(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    {
20823
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    56
        if ( engaged != 0) {
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    57
            if (obj == null) {
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    58
                throw new IllegalArgumentException("Null object.");
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    59
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            nativeObjectInit(Thread.currentThread(), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /* Immediately following any of the newarray bytecodes, a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *   Tracker.NewArray() is injected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private static native void nativeNewArray(Object thr, Object obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public static void NewArray(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    {
20823
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    72
        if ( engaged != 0) {
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    73
            if (obj == null) {
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    74
                throw new IllegalArgumentException("Null object.");
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    75
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            nativeNewArray(Thread.currentThread(), obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /* For cpu time spent in methods, we need to inject for every method. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /* At the very beginning of every method, a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *   Tracker.CallSite() is injected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private static native void nativeCallSite(Object thr, int cnum, int mnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static void CallSite(int cnum, int mnum)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if ( engaged != 0 ) {
20823
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    91
            if (cnum < 0) {
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    92
                throw new IllegalArgumentException("Negative class index");
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    93
            }
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    94
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    95
            if (mnum < 0) {
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    96
                throw new IllegalArgumentException("Negative method index");
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    97
            }
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
    98
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            nativeCallSite(Thread.currentThread(), cnum, mnum);
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
    /* Before any of the return bytecodes, a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *   Tracker.ReturnSite() is injected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private static native void nativeReturnSite(Object thr, int cnum, int mnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public static void ReturnSite(int cnum, int mnum)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if ( engaged != 0 ) {
20823
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
   112
            if (cnum < 0) {
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
   113
                throw new IllegalArgumentException("Negative class index");
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
   114
            }
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
   115
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
   116
            if (mnum < 0) {
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
   117
                throw new IllegalArgumentException("Negative method index");
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
   118
            }
ddd111318407 8014534: Better profiling support
sjiang
parents: 5506
diff changeset
   119
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            nativeReturnSite(Thread.currentThread(), cnum, mnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
}