0N/A/*
2362N/A * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
0N/A *
0N/A * Redistribution and use in source and binary forms, with or without
0N/A * modification, are permitted provided that the following conditions
0N/A * are met:
0N/A *
0N/A * - Redistributions of source code must retain the above copyright
0N/A * notice, this list of conditions and the following disclaimer.
0N/A *
0N/A * - Redistributions in binary form must reproduce the above copyright
0N/A * notice, this list of conditions and the following disclaimer in the
0N/A * documentation and/or other materials provided with the distribution.
0N/A *
2362N/A * - Neither the name of Oracle nor the names of its
0N/A * contributors may be used to endorse or promote products derived
0N/A * from this software without specific prior written permission.
0N/A *
0N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
0N/A * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
0N/A * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
0N/A * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0N/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0N/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0N/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0N/A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0N/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0N/A */
0N/A
0N/AREADME
0N/A------
0N/A
0N/ADesign and Implementation:
0N/A
0N/A * The Tracker Class (Tracker.java & hprof_tracker.c)
0N/A It was added to the sun.tools.hprof.Tracker in JDK 5.0 FCS, then
0N/A moved to a package that didn't cause classload errors due to
0N/A the security manager not liking the sun.* package name.
0N/A 5091195 detected that this class needs to be in com.sun.demo.jvmti.hprof.
0N/A The BCI code will call these static methods, which will in turn
0N/A (if engaged) call matching native methods in the hprof library,
0N/A with the additional current Thread argument (Thread.currentThread()).
0N/A Doing the currentThread call on the Java side was necessary due
0N/A to the difficulty of getting the current thread while inside one
0N/A of these Tracker native methods. This class lives in rt.jar.
0N/A
0N/A * Byte Code Instrumentation (BCI)
0N/A Using the ClassFileLoadHook feature and a C language
0N/A implementation of a byte code injection transformer, the following
0N/A bytecodes get injections:
0N/A - On entry to the java.lang.Object <init> method,
0N/A a invokestatic call to
0N/A Tracker.ObjectInit(this);
0N/A is injected.
0N/A - On any newarray type opcode, immediately following it,
0N/A the array object is duplicated on the stack and an
0N/A invokestatic call to
0N/A Tracker.NewArray(obj);
0N/A is injected.
0N/A - On entry to all methods, a invokestatic call to
0N/A Tracker.CallSite(cnum,mnum);
0N/A is injected. The hprof agent can map the two integers
0N/A (cnum,mnum) to a method in a class. This is the BCI based
0N/A "method entry" event.
0N/A - On return from any method (any return opcode),
0N/A a invokestatic call to
0N/A Tracker.ReturnSite(cnum,mnum);
0N/A is injected.
0N/A All classes found via ClassFileLoadHook are injected with the
0N/A exception of some system class methods "<init>" and "finalize"
0N/A whose length is 1 and system class methods with name "<clinit>",
0N/A and also java.lang.Thread.currentThread() which is used in the
0N/A class Tracker (preventing nasty recursion issue).
0N/A System classes are currently defined as any class seen by the
0N/A ClassFileLoadHook prior to VM_INIT. This does mean that
0N/A objects created in the system classes inside <clinit> might not
0N/A get tracked initially.
0N/A See the java_crw_demo source and documentation for more info.
0N/A The injections are based on what the hprof options
0N/A are requesting, e.g. if heap=sites or heap=all is requested, the
0N/A newarray and Object.<init> method injections happen.
0N/A If cpu=times is requested, all methods get their entries and
0N/A returns tracked. Options like cpu=samples or monitor=y
0N/A do not require BCI.
0N/A
0N/A * BCI Allocation Tags (hprof_tag.c)
0N/A The current jlong tag being used on allocated objects
0N/A is an ObjectIndex, or an index into the object table inside
0N/A the hprof code. Depending on whether heap=sites or heap=dump
0N/A was asked for, these ObjectIndex's might represent unique
0N/A objects, or unique allocation sites for types of objects.
0N/A The heap=dump option requires considerable more space
0N/A due to the one jobject per ObjectIndex mapping.
0N/A
0N/A * BCI Performance
0N/A The cpu=times seems to have the most negative affect on
0N/A performance, this could be improved by not having the
0N/A Tracker class methods call native code directly, but accumulate
0N/A the data in a file or memory somehow and letting it buffer down
0N/A to the agent. The cpu=samples is probably a better way to
0N/A measure cpu usage, varying the interval as needed.
0N/A The heap=dump seems to use memory like crazy, but that's
0N/A partially the way it has always been.
0N/A
0N/A * Sources in the JDK workspace
0N/A The sources and Makefiles live in:
0N/A src/share/classes/com/sun/demo/jvmti/hprof/*
0N/A src/share/demo/jvmti/hprof/*
0N/A src/share/demo/jvmti/java_crw_demo/*
0N/A src/solaris/demo/jvmti/hprof/*
0N/A src/windows/demo/jvmti/hprof/*
0N/A make/java/java_hprof_demo/*
0N/A make/java/java_crw_demo/*
0N/A
0N/A--------