Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/demo/jvmti/hprof/README.txt
38829 views
/*1* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6*7* - Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9*10* - Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* - Neither the name of Oracle nor the names of its15* contributors may be used to endorse or promote products derived16* from this software without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS19* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,20* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR21* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR22* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,23* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,24* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR25* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF26* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING27* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS28* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.29*/3031README32------3334Design and Implementation:3536* The Tracker Class (Tracker.java & hprof_tracker.c)37It was added to the sun.tools.hprof.Tracker in JDK 5.0 FCS, then38moved to a package that didn't cause classload errors due to39the security manager not liking the sun.* package name.405091195 detected that this class needs to be in com.sun.demo.jvmti.hprof.41The BCI code will call these static methods, which will in turn42(if engaged) call matching native methods in the hprof library,43with the additional current Thread argument (Thread.currentThread()).44Doing the currentThread call on the Java side was necessary due45to the difficulty of getting the current thread while inside one46of these Tracker native methods. This class lives in rt.jar.4748* Byte Code Instrumentation (BCI)49Using the ClassFileLoadHook feature and a C language50implementation of a byte code injection transformer, the following51bytecodes get injections:52- On entry to the java.lang.Object <init> method,53a invokestatic call to54Tracker.ObjectInit(this);55is injected.56- On any newarray type opcode, immediately following it,57the array object is duplicated on the stack and an58invokestatic call to59Tracker.NewArray(obj);60is injected.61- On entry to all methods, a invokestatic call to62Tracker.CallSite(cnum,mnum);63is injected. The hprof agent can map the two integers64(cnum,mnum) to a method in a class. This is the BCI based65"method entry" event.66- On return from any method (any return opcode),67a invokestatic call to68Tracker.ReturnSite(cnum,mnum);69is injected.70All classes found via ClassFileLoadHook are injected with the71exception of some system class methods "<init>" and "finalize"72whose length is 1 and system class methods with name "<clinit>",73and also java.lang.Thread.currentThread() which is used in the74class Tracker (preventing nasty recursion issue).75System classes are currently defined as any class seen by the76ClassFileLoadHook prior to VM_INIT. This does mean that77objects created in the system classes inside <clinit> might not78get tracked initially.79See the java_crw_demo source and documentation for more info.80The injections are based on what the hprof options81are requesting, e.g. if heap=sites or heap=all is requested, the82newarray and Object.<init> method injections happen.83If cpu=times is requested, all methods get their entries and84returns tracked. Options like cpu=samples or monitor=y85do not require BCI.8687* BCI Allocation Tags (hprof_tag.c)88The current jlong tag being used on allocated objects89is an ObjectIndex, or an index into the object table inside90the hprof code. Depending on whether heap=sites or heap=dump91was asked for, these ObjectIndex's might represent unique92objects, or unique allocation sites for types of objects.93The heap=dump option requires considerable more space94due to the one jobject per ObjectIndex mapping.9596* BCI Performance97The cpu=times seems to have the most negative affect on98performance, this could be improved by not having the99Tracker class methods call native code directly, but accumulate100the data in a file or memory somehow and letting it buffer down101to the agent. The cpu=samples is probably a better way to102measure cpu usage, varying the interval as needed.103The heap=dump seems to use memory like crazy, but that's104partially the way it has always been.105106* Sources in the JDK workspace107The sources and Makefiles live in:108src/share/classes/com/sun/demo/jvmti/hprof/*109src/share/demo/jvmti/hprof/*110src/share/demo/jvmti/java_crw_demo/*111src/solaris/demo/jvmti/hprof/*112src/windows/demo/jvmti/hprof/*113make/java/java_hprof_demo/*114make/java/java_crw_demo/*115116--------117118119