0N/A#
2362N/A# Copyright (c) 2004, 2007, 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/Ajava_crw_demo Library
0N/A
0N/AThe library java_crw_demo is a small C library that is used by HPROF
0N/Aand other agent libraries to do some very basic bytecode
0N/Ainsertion (BCI) of class files. This is not an agent
0N/Alibrary but a general purpose library that can be used to do some
0N/Avery limited bytecode insertion.
0N/A
0N/AIn the demo sources, look for the use of java_crw_demo.h and
0N/Athe C function java_crw_demo(). The java_crw_demo library is provided
0N/Aas part of the JRE.
0N/A
0N/AThe basic BCI that this library does includes:
0N/A
0N/A * On entry to the java.lang.Object init method (signature "()V"),
0N/A a invokestatic call to tclass.obj_init_method(object); is inserted.
0N/A
0N/A * On any newarray type opcode, immediately following it, the array
0N/A object is duplicated on the stack and an invokestatic call to
0N/A tclass.newarray_method(object); is inserted.
0N/A
0N/A * On entry to all methods, a invokestatic call to
0N/A tclass.call_method(cnum,mnum); is inserted. The agent can map the
0N/A two integers (cnum,mnum) to a method in a class, the cnum is the
0N/A number provided to the java_crw_demo library when the classfile was
0N/A modified.
0N/A
0N/A * On return from any method (any return opcode), a invokestatic call to
0N/A tclass.return_method(cnum,mnum); is inserted.
0N/A
0N/ASome methods are not modified at all, init methods and finalize methods
0N/Awhose length is 1 will not be modified. Classes that are designated
0N/A"system" will not have their clinit methods modified. In addition, the
0N/Amethod java.lang.Thread.currentThread() is not modified.
0N/A
0N/ANo methods or fields will be added to any class, however new constant
0N/Apool entries will be added at the end of the original constant pool table.
0N/AThe exception, line, and local variable tables for each method is adjusted
0N/Afor the modification. The bytecodes are compressed to use smaller offsets
0N/Aand the fewest 'wide' opcodes.
0N/A
0N/AAll attempts are made to minimize the number of bytecodes at each insertion
0N/Asite, however, classes with N return opcodes or N newarray opcodes will get
0N/AN insertions. And only the necessary modification dictated by the input
0N/Aarguments to java_crw_demo are actually made.
0N/A