jdk/src/share/classes/java/lang/instrument/Instrumentation.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 283 f141a78d9f2b
child 3495 6b2a376f365c
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 283
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang.instrument;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import  java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import  java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import  java.util.jar.JarFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Copyright 2003 Wily Technology, Inc.
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
 * This class provides services needed to instrument Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * programming language code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Instrumentation is the addition of byte-codes to methods for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * purpose of gathering data to be utilized by tools.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Since the changes are purely additive, these tools do not modify
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * application state or behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Examples of such benign tools include monitoring agents, profilers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * coverage analyzers, and event loggers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * There are two ways to obtain an instance of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <code>Instrumentation</code> interface:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *   <li><p> When a JVM is launched in a way that indicates an agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *     class. In that case an <code>Instrumentation</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *     is passed to the <code>premain</code> method of the agent class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *     </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *   <li><p> When a JVM provides a mechanism to start agents sometime
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *     after the JVM is launched. In that case an <code>Instrumentation</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *     instance is passed to the <code>agentmain</code> method of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *     agent code. </p> </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * These mechanisms are described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * {@linkplain java.lang.instrument package specification}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Once an agent acquires an <code>Instrumentation</code> instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * the agent may call methods on the instance at any time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
public interface Instrumentation {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Registers the supplied transformer. All future class definitions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * will be seen by the transformer, except definitions of classes upon which any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * registered transformer is dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * The transformer is called when classes are loaded, when they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * {@linkplain #redefineClasses redefined}. and if <code>canRetransform</code> is true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * when they are {@linkplain #retransformClasses retransformed}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * See {@link java.lang.instrument.ClassFileTransformer#transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * ClassFileTransformer.transform} for the order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * of transform calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * If a transformer throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * an exception during execution, the JVM will still call the other registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * transformers in order. The same transformer may be added more than once,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * but it is strongly discouraged -- avoid this by creating a new instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * tranformer class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * This method is intended for use in instrumentation, as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * {@linkplain Instrumentation class specification}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @param transformer          the transformer to register
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param canRetransform       can this transformer's transformations be retransformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @throws java.lang.NullPointerException if passed a <code>null</code> transformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @throws java.lang.UnsupportedOperationException if <code>canRetransform</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * is true and the current configuration of the JVM does not allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * retransformation ({@link #isRetransformClassesSupported} is false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    addTransformer(ClassFileTransformer transformer, boolean canRetransform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Registers the supplied transformer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Same as <code>addTransformer(transformer, false)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param transformer          the transformer to register
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @throws java.lang.NullPointerException if passed a <code>null</code> transformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @see    #addTransformer(ClassFileTransformer,boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    addTransformer(ClassFileTransformer transformer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Unregisters the supplied transformer. Future class definitions will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * not be shown to the transformer. Removes the most-recently-added matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * instance of the transformer. Due to the multi-threaded nature of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * class loading, it is possible for a transformer to receive calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * after it has been removed. Transformers should be written defensively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * to expect this situation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param transformer          the transformer to unregister
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @return  true if the transformer was found and removed, false if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *           transformer was not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @throws java.lang.NullPointerException if passed a <code>null</code> transformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    removeTransformer(ClassFileTransformer transformer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Returns whether or not the current JVM configuration supports retransformation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * of classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * The ability to retransform an already loaded class is an optional capability
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * of a JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Retransformation will only be supported if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * <code>Can-Retransform-Classes</code> manifest attribute is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * <code>true</code> in the agent JAR file (as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * {@linkplain java.lang.instrument package specification}) and the JVM supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * this capability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * During a single instantiation of a single JVM, multiple calls to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * method will always return the same answer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @return  true if the current JVM configuration supports retransformation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *          classes, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @see #retransformClasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    isRetransformClassesSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Retransform the supplied set of classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * This function facilitates the instrumentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * of already loaded classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * When classes are initially loaded or when they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * {@linkplain #redefineClasses redefined},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * the initial class file bytes can be transformed with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * {@link java.lang.instrument.ClassFileTransformer ClassFileTransformer}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * This function reruns the transformation process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * (whether or not a transformation has previously occurred).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * This retransformation follows these steps:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *  <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *    <li>starting from the initial class file bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *    </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *    <li>for each transformer that was added with <code>canRetransform</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *      false, the bytes returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *      {@link java.lang.instrument.ClassFileTransformer#transform transform}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *      during the last class load or redefine are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *      reused as the output of the transformation; note that this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *      equivalent to reapplying the previous transformation, unaltered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *      except that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *      {@link java.lang.instrument.ClassFileTransformer#transform transform}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *      is not called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *    </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *    <li>for each transformer that was added with <code>canRetransform</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *      true, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *      {@link java.lang.instrument.ClassFileTransformer#transform transform}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *      method is called in these transformers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *    </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *    <li>the transformed class file bytes are installed as the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *      definition of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *    </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *  </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * The order of transformation is described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * ({@link java.lang.instrument.ClassFileTransformer#transform transform} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * This same order is used in the automatic reapplication of retransformation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * incapable transforms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * The initial class file bytes represent the bytes passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * {@link java.lang.ClassLoader#defineClass ClassLoader.defineClass} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * {@link #redefineClasses redefineClasses}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * (before any transformations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *  were applied), however they might not exactly match them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *  The constant pool might not have the same layout or contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *  The constant pool may have more or fewer entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *  Constant pool entries may be in a different order; however,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *  constant pool indices in the bytecodes of methods will correspond.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *  Some attributes may not be present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *  Where order is not meaningful, for example the order of methods,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *  order might not be preserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * This method operates on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * a set in order to allow interdependent changes to more than one class at the same time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * (a retransformation of class A can require a retransformation of class B).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * If a retransformed method has active stack frames, those active frames continue to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * run the bytecodes of the original method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * The retransformed method will be used on new invokes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * This method does not cause any initialization except that which would occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * under the customary JVM semantics. In other words, redefining a class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * does not cause its initializers to be run. The values of static variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * will remain as they were prior to the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Instances of the retransformed class are not affected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * The retransformation may change method bodies, the constant pool and attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * The retransformation must not add, remove or rename fields or methods, change the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * signatures of methods, or change inheritance.  These restrictions maybe be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * lifted in future versions.  The class file bytes are not checked, verified and installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * until after the transformations have been applied, if the resultant bytes are in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * error this method will throw an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * If this method throws an exception, no classes have been retransformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * This method is intended for use in instrumentation, as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * {@linkplain Instrumentation class specification}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @param classes array of classes to retransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *                a zero-length array is allowed, in this case, this method does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @throws java.lang.instrument.UnmodifiableClassException if a specified class cannot be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * ({@link #isModifiableClass} would return <code>false</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @throws java.lang.UnsupportedOperationException if the current configuration of the JVM does not allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * retransformation ({@link #isRetransformClassesSupported} is false) or the retransformation attempted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * to make unsupported changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @throws java.lang.ClassFormatError if the data did not contain a valid class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @throws java.lang.NoClassDefFoundError if the name in the class file is not equal to the name of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @throws java.lang.UnsupportedClassVersionError if the class file version numbers are not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @throws java.lang.ClassCircularityError if the new classes contain a circularity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @throws java.lang.LinkageError if a linkage error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @throws java.lang.NullPointerException if the supplied classes  array or any of its components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *                                        is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @see #isRetransformClassesSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @see #addTransformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @see java.lang.instrument.ClassFileTransformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    retransformClasses(Class<?>... classes) throws UnmodifiableClassException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Returns whether or not the current JVM configuration supports redefinition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * of classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * The ability to redefine an already loaded class is an optional capability
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * of a JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Redefinition will only be supported if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * <code>Can-Redefine-Classes</code> manifest attribute is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * <code>true</code> in the agent JAR file (as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * {@linkplain java.lang.instrument package specification}) and the JVM supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * this capability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * During a single instantiation of a single JVM, multiple calls to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * method will always return the same answer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @return  true if the current JVM configuration supports redefinition of classes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @see #redefineClasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    isRedefineClassesSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Redefine the supplied set of classes using the supplied class files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * This method is used to replace the definition of a class without reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * to the existing class file bytes, as one might do when recompiling from source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * for fix-and-continue debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Where the existing class file bytes are to be transformed (for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * example in bytecode instrumentation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * {@link #retransformClasses retransformClasses}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * should be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * This method operates on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * a set in order to allow interdependent changes to more than one class at the same time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * (a redefinition of class A can require a redefinition of class B).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * If a redefined method has active stack frames, those active frames continue to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * run the bytecodes of the original method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * The redefined method will be used on new invokes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * This method does not cause any initialization except that which would occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * under the customary JVM semantics. In other words, redefining a class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * does not cause its initializers to be run. The values of static variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * will remain as they were prior to the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Instances of the redefined class are not affected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * The redefinition may change method bodies, the constant pool and attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * The redefinition must not add, remove or rename fields or methods, change the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * signatures of methods, or change inheritance.  These restrictions maybe be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * lifted in future versions.  The class file bytes are not checked, verified and installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * until after the transformations have been applied, if the resultant bytes are in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * error this method will throw an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * If this method throws an exception, no classes have been redefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * This method is intended for use in instrumentation, as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * {@linkplain Instrumentation class specification}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @param definitions array of classes to redefine with corresponding definitions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *                    a zero-length array is allowed, in this case, this method does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @throws java.lang.instrument.UnmodifiableClassException if a specified class cannot be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * ({@link #isModifiableClass} would return <code>false</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @throws java.lang.UnsupportedOperationException if the current configuration of the JVM does not allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * redefinition ({@link #isRedefineClassesSupported} is false) or the redefinition attempted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * to make unsupported changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @throws java.lang.ClassFormatError if the data did not contain a valid class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @throws java.lang.NoClassDefFoundError if the name in the class file is not equal to the name of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @throws java.lang.UnsupportedClassVersionError if the class file version numbers are not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @throws java.lang.ClassCircularityError if the new classes contain a circularity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @throws java.lang.LinkageError if a linkage error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @throws java.lang.NullPointerException if the supplied definitions array or any of its components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @throws java.lang.ClassNotFoundException Can never be thrown (present for compatibility reasons only)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @see #isRedefineClassesSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @see #addTransformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @see java.lang.instrument.ClassFileTransformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    redefineClasses(ClassDefinition... definitions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        throws  ClassNotFoundException, UnmodifiableClassException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Determines whether a class is modifiable by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * {@linkplain #retransformClasses retransformation}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * or {@linkplain #redefineClasses redefinition}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * If a class is modifiable then this method returns <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * If a class is not modifiable then this method returns <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * For a class to be retransformed, {@link #isRetransformClassesSupported} must also be true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * But the value of <code>isRetransformClassesSupported()</code> does not influence the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * returned by this function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * For a class to be redefined, {@link #isRedefineClassesSupported} must also be true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * But the value of <code>isRedefineClassesSupported()</code> does not influence the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * returned by this function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * Primitive classes (for example, <code>java.lang.Integer.TYPE</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * and array classes are never modifiable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @throws java.lang.NullPointerException if the specified class is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @see #retransformClasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @see #isRetransformClassesSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @see #redefineClasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @see #isRedefineClassesSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    isModifiableClass(Class<?> theClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Returns an array of all classes currently loaded by the JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @return an array containing all the classes loaded by the JVM, zero-length if there are none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    Class[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    getAllLoadedClasses();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Returns an array of all classes for which <code>loader</code> is an initiating loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * If the supplied loader is <code>null</code>, classes initiated by the bootstrap class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * loader are returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @param loader          the loader whose initiated class list will be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @return an array containing all the classes for which loader is an initiating loader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *          zero-length if there are none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    Class[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    getInitiatedClasses(ClassLoader loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Returns an implementation-specific approximation of the amount of storage consumed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * the specified object. The result may include some or all of the object's overhead,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * and thus is useful for comparison within an implementation but not between implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * The estimate may change during a single invocation of the JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @param objectToSize     the object to size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @return an implementation-specific approximation of the amount of storage consumed by the specified object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @throws java.lang.NullPointerException if the supplied Object is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    getObjectSize(Object objectToSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Specifies a JAR file with instrumentation classes to be defined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * bootstrap class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * <p> When the virtual machine's built-in class loader, known as the "bootstrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * class loader", unsuccessfully searches for a class, the entries in the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * java.util.jar.JarFile JAR file} will be searched as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * <p> This method may be used multiple times to add multiple JAR files to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * searched in the order that this method was invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * <p> The agent should take care to ensure that the JAR does not contain any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * classes or resources other than those to be defined by the bootstrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * class loader for the purpose of instrumentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * Failure to observe this warning could result in unexpected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * behaviour that is difficult to diagnose. For example, suppose there is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * loader L, and L's parent for delegation is the bootstrap class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Furthermore, a method in class C, a class defined by L, makes reference to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * a non-public accessor class C$1. If the JAR file contains a class C$1 then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * the delegation to the bootstrap class loader will cause C$1 to be defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * by the bootstrap class loader. In this example an <code>IllegalAccessError</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * will be thrown that may cause the application to fail. One approach to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * avoiding these types of issues, is to use a unique package name for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * instrumentation classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * <p> The <a href="http://java.sun.com/docs/books/vmspec/">Java Virtual Machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * Specification</a> specifies that a subsequent attempt to resolve a symbolic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * reference that the Java virtual machine has previously unsuccessfully attempted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * to resolve always fails with the same error that was thrown as a result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * initial resolution attempt. Consequently, if the JAR file contains an entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * that corresponds to a class for which the Java virtual machine has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * unsuccessfully attempted to resolve a reference, then subsequent attempts to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * resolve that reference will fail with the same error as the initial attempt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @param   jarfile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *          The JAR file to be searched when the bootstrap class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *          unsuccessfully searches for a class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *          If <code>jarfile</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @see     #appendToSystemClassLoaderSearch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @see     java.lang.ClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @see     java.util.jar.JarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    appendToBootstrapClassLoaderSearch(JarFile jarfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * Specifies a JAR file with instrumentation classes to be defined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * system class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * When the system class loader for delegation (see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * {@link java.lang.ClassLoader#getSystemClassLoader getSystemClassLoader()})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * unsuccessfully searches for a class, the entries in the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * java.util.jar.JarFile JarFile} will be searched as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * <p> This method may be used multiple times to add multiple JAR files to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * searched in the order that this method was invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * <p> The agent should take care to ensure that the JAR does not contain any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * classes or resources other than those to be defined by the system class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * loader for the purpose of instrumentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * Failure to observe this warning could result in unexpected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * behaviour that is difficult to diagnose (see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * {@link #appendToBootstrapClassLoaderSearch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * appendToBootstrapClassLoaderSearch}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * <p> The system class loader supports adding a JAR file to be searched if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * it implements a method named <code>appendToClassPathForInstrumentation</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * which takes a single parameter of type <code>java.lang.String</code>. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * method is not required to have <code>public</code> access. The name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * the JAR file is obtained by invoking the {@link java.util.zip.ZipFile#getName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * getName()} method on the <code>jarfile</code> and this is provided as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * parameter to the <code>appendtoClassPathForInstrumentation</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * <p> The <a href="http://java.sun.com/docs/books/vmspec/">Java Virtual Machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * Specification</a> specifies that a subsequent attempt to resolve a symbolic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * reference that the Java virtual machine has previously unsuccessfully attempted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * to resolve always fails with the same error that was thrown as a result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * initial resolution attempt. Consequently, if the JAR file contains an entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * that corresponds to a class for which the Java virtual machine has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * unsuccessfully attempted to resolve a reference, then subsequent attempts to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * resolve that reference will fail with the same error as the initial attempt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * <p> This method does not change the value of <code>java.class.path</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * {@link java.lang.System#getProperties system property}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @param   jarfile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *          The JAR file to be searched when the system class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *          unsuccessfully searches for a class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @throws  UnsupportedOperationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *          If the system class loader does not support appending a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     *          a JAR file to be searched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *          If <code>jarfile</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @see     #appendToBootstrapClassLoaderSearch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @see     java.lang.ClassLoader#getSystemClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @see     java.util.jar.JarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    appendToSystemClassLoaderSearch(JarFile jarfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * Returns whether the current JVM configuration supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * {@linkplain #setNativeMethodPrefix(ClassFileTransformer,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * setting a native method prefix}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * The ability to set a native method prefix is an optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * capability of a JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * Setting a native method prefix will only be supported if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * <code>Can-Set-Native-Method-Prefix</code> manifest attribute is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * <code>true</code> in the agent JAR file (as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * {@linkplain java.lang.instrument package specification}) and the JVM supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * this capability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * During a single instantiation of a single JVM, multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * calls to this method will always return the same answer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @return  true if the current JVM configuration supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * setting a native method prefix, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @see #setNativeMethodPrefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    isNativeMethodPrefixSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * This method modifies the failure handling of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * native method resolution by allowing retry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * with a prefix applied to the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * When used with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * {@link java.lang.instrument.ClassFileTransformer ClassFileTransformer},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * it enables native methods to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * instrumented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * <p/>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * Since native methods cannot be directly instrumented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * (they have no bytecodes), they must be wrapped with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * a non-native method which can be instrumented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * For example, if we had:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     *   native boolean foo(int x);</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * <p/>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * We could transform the class file (with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * ClassFileTransformer during the initial definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * of the class) so that this becomes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *   boolean foo(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     *     <i>... record entry to foo ...</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *     return wrapped_foo(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     *   native boolean wrapped_foo(int x);</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * <p/>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * Where <code>foo</code> becomes a wrapper for the actual native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * method with the appended prefix "wrapped_".  Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * "wrapped_" would be a poor choice of prefix since it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * might conceivably form the name of an existing method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * thus something like "$$$MyAgentWrapped$$$_" would be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * better but would make these examples less readable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * <p/>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * The wrapper will allow data to be collected on the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * method call, but now the problem becomes linking up the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * wrapped method with the native implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * That is, the method <code>wrapped_foo</code> needs to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * resolved to the native implementation of <code>foo</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * which might be:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *   Java_somePackage_someClass_foo(JNIEnv* env, jint x)</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * <p/>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * This function allows the prefix to be specified and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * proper resolution to occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * Specifically, when the standard resolution fails, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * resolution is retried taking the prefix into consideration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * There are two ways that resolution occurs, explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * resolution with the JNI function <code>RegisterNatives</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * and the normal automatic resolution.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * <code>RegisterNatives</code>, the JVM will attempt this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * association:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *   method(foo) -> nativeImplementation(foo)</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * <p/>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * When this fails, the resolution will be retried with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * the specified prefix prepended to the method name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * yielding the correct resolution:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     *   method(wrapped_foo) -> nativeImplementation(foo)</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * <p/>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * For automatic resolution, the JVM will attempt:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     *   method(wrapped_foo) -> nativeImplementation(wrapped_foo)</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * <p/>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * When this fails, the resolution will be retried with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * the specified prefix deleted from the implementation name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * yielding the correct resolution:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     *   method(wrapped_foo) -> nativeImplementation(foo)</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * <p/>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * Note that since the prefix is only used when standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * resolution fails, native methods can be wrapped selectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * <p/>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * Since each <code>ClassFileTransformer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * can do its own transformation of the bytecodes, more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * than one layer of wrappers may be applied. Thus each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * transformer needs its own prefix.  Since transformations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * are applied in order, the prefixes, if applied, will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * be applied in the same order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * (see {@link #addTransformer(ClassFileTransformer,boolean) addTransformer}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * Thus if three transformers applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * wrappers, <code>foo</code> might become
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * <code>$trans3_$trans2_$trans1_foo</code>.  But if, say,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * the second transformer did not apply a wrapper to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * <code>foo</code> it would be just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * <code>$trans3_$trans1_foo</code>.  To be able to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * efficiently determine the sequence of prefixes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * an intermediate prefix is only applied if its non-native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * wrapper exists.  Thus, in the last example, even though
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * <code>$trans1_foo</code> is not a native method, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * <code>$trans1_</code> prefix is applied since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * <code>$trans1_foo</code> exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * @param   transformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     *          The ClassFileTransformer which wraps using this prefix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * @param   prefix
283
f141a78d9f2b 6655234: 4/4 j.l.i.: setNativeMethodPrefix does not document that prefix string can be null
dcubed
parents: 2
diff changeset
   639
     *          The prefix to apply to wrapped native methods when
f141a78d9f2b 6655234: 4/4 j.l.i.: setNativeMethodPrefix does not document that prefix string can be null
dcubed
parents: 2
diff changeset
   640
     *          retrying a failed native method resolution. If prefix
f141a78d9f2b 6655234: 4/4 j.l.i.: setNativeMethodPrefix does not document that prefix string can be null
dcubed
parents: 2
diff changeset
   641
     *          is either <code>null</code> or the empty string, then
f141a78d9f2b 6655234: 4/4 j.l.i.: setNativeMethodPrefix does not document that prefix string can be null
dcubed
parents: 2
diff changeset
   642
     *          failed native method resolutions are not retried for
f141a78d9f2b 6655234: 4/4 j.l.i.: setNativeMethodPrefix does not document that prefix string can be null
dcubed
parents: 2
diff changeset
   643
     *          this transformer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * @throws java.lang.NullPointerException if passed a <code>null</code> transformer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @throws java.lang.UnsupportedOperationException if the current configuration of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *           the JVM does not allow setting a native method prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     *           ({@link #isNativeMethodPrefixSupported} is false).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @throws java.lang.IllegalArgumentException if the transformer is not registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     *           (see {@link #addTransformer(ClassFileTransformer,boolean) addTransformer}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    setNativeMethodPrefix(ClassFileTransformer transformer, String prefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
}