src/java.instrument/share/classes/java/lang/instrument/Instrumentation.java
author dholmes
Sat, 23 Jun 2018 01:32:41 -0400
changeset 50735 2f2af62dfac7
parent 47216 71c04702a3d5
child 54954 6ec71a88b68e
permissions -rw-r--r--
8010319: Implementation of JEP 181: Nest-Based Access Control Reviewed-by: alanb, psandoz, mchung, coleenp, acorn, mcimadamore, forax, jlahoda, sspitsyn, abuckley Contributed-by: alex.buckley@oracle.com, maurizio.mimadamore@oracle.com, mandy.chung@oracle.com, tobias.hartmann@oracle.com, david.holmes@oracle.com, vladimir.x.ivanov@oracle.com, karen.kinnear@oracle.com, vladimir.kozlov@oracle.com, john.r.rose@oracle.com, daniel.smith@oracle.com, serguei.spitsyn@oracle.com, kumardotsrinivasan@gmail.com, boris.ulasevich@bell-sw.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3495
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3495
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3495
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3495
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3495
diff changeset
    23
 * questions.
2
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
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    28
import java.security.ProtectionDomain;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
    29
import java.util.List;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
    30
import java.util.Map;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
    31
import java.util.Set;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    32
import java.util.jar.JarFile;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Copyright 2003 Wily Technology, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * This class provides services needed to instrument Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * programming language code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Instrumentation is the addition of byte-codes to methods for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * purpose of gathering data to be utilized by tools.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Since the changes are purely additive, these tools do not modify
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * application state or behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Examples of such benign tools include monitoring agents, profilers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * coverage analyzers, and event loggers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * There are two ways to obtain an instance of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <code>Instrumentation</code> interface:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *   <li><p> When a JVM is launched in a way that indicates an agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *     class. In that case an <code>Instrumentation</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *     is passed to the <code>premain</code> method of the agent class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *     </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *   <li><p> When a JVM provides a mechanism to start agents sometime
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *     after the JVM is launched. In that case an <code>Instrumentation</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *     instance is passed to the <code>agentmain</code> method of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *     agent code. </p> </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * These mechanisms are described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * {@linkplain java.lang.instrument package specification}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Once an agent acquires an <code>Instrumentation</code> instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * the agent may call methods on the instance at any time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
public interface Instrumentation {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Registers the supplied transformer. All future class definitions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * will be seen by the transformer, except definitions of classes upon which any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * registered transformer is dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * The transformer is called when classes are loaded, when they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * {@linkplain #redefineClasses redefined}. and if <code>canRetransform</code> is true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * when they are {@linkplain #retransformClasses retransformed}.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    79
     * {@link ClassFileTransformer} defines the order of transform calls.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    80
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * If a transformer throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * an exception during execution, the JVM will still call the other registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * transformers in order. The same transformer may be added more than once,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * but it is strongly discouraged -- avoid this by creating a new instance of
3495
6b2a376f365c 6870298: 4/4 fix minor typos in java/lang/instrument/Instrumentation.java
dcubed
parents: 715
diff changeset
    85
     * transformer class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * This method is intended for use in instrumentation, as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * {@linkplain Instrumentation class specification}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param transformer          the transformer to register
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param canRetransform       can this transformer's transformations be retransformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @throws java.lang.NullPointerException if passed a <code>null</code> transformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @throws java.lang.UnsupportedOperationException if <code>canRetransform</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * is true and the current configuration of the JVM does not allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * retransformation ({@link #isRetransformClassesSupported} is false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    addTransformer(ClassFileTransformer transformer, boolean canRetransform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Registers the supplied transformer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Same as <code>addTransformer(transformer, false)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param transformer          the transformer to register
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @throws java.lang.NullPointerException if passed a <code>null</code> transformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @see    #addTransformer(ClassFileTransformer,boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    addTransformer(ClassFileTransformer transformer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Unregisters the supplied transformer. Future class definitions will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * not be shown to the transformer. Removes the most-recently-added matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * instance of the transformer. Due to the multi-threaded nature of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * class loading, it is possible for a transformer to receive calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * after it has been removed. Transformers should be written defensively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * to expect this situation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param transformer          the transformer to unregister
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @return  true if the transformer was found and removed, false if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *           transformer was not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @throws java.lang.NullPointerException if passed a <code>null</code> transformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    removeTransformer(ClassFileTransformer transformer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Returns whether or not the current JVM configuration supports retransformation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * of classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * The ability to retransform an already loaded class is an optional capability
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * of a JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Retransformation will only be supported if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * <code>Can-Retransform-Classes</code> manifest attribute is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <code>true</code> in the agent JAR file (as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * {@linkplain java.lang.instrument package specification}) and the JVM supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * this capability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * During a single instantiation of a single JVM, multiple calls to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * method will always return the same answer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @return  true if the current JVM configuration supports retransformation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *          classes, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @see #retransformClasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    isRetransformClassesSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Retransform the supplied set of classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * This function facilitates the instrumentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * of already loaded classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * When classes are initially loaded or when they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * {@linkplain #redefineClasses redefined},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * the initial class file bytes can be transformed with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * {@link java.lang.instrument.ClassFileTransformer ClassFileTransformer}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * This function reruns the transformation process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * (whether or not a transformation has previously occurred).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * This retransformation follows these steps:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *  <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *    <li>starting from the initial class file bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *    </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *    <li>for each transformer that was added with <code>canRetransform</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *      false, the bytes returned by
39739
5d058d6bd245 8159147: Add ClassLoader parameter to new ClassFileTransformer transform method
sspitsyn
parents: 36511
diff changeset
   167
     *      {@link ClassFileTransformer#transform(Module,ClassLoader,String,Class,ProtectionDomain,byte[])
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   168
     *      transform} during the last class load or redefine are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *      reused as the output of the transformation; note that this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *      equivalent to reapplying the previous transformation, unaltered;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   171
     *      except that {@code transform} method is not called.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *    </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *    <li>for each transformer that was added with <code>canRetransform</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *      true, the
39739
5d058d6bd245 8159147: Add ClassLoader parameter to new ClassFileTransformer transform method
sspitsyn
parents: 36511
diff changeset
   175
     *      {@link ClassFileTransformer#transform(Module,ClassLoader,String,Class,ProtectionDomain,byte[])
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   176
     *      transform} method is called in these transformers
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *    </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *    <li>the transformed class file bytes are installed as the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *      definition of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *    </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *  </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   184
     * The order of transformation is described in {@link ClassFileTransformer}.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   185
     * This same order is used in the automatic reapplication of
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   186
     * retransformation incapable transforms.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * The initial class file bytes represent the bytes passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * {@link java.lang.ClassLoader#defineClass ClassLoader.defineClass} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * {@link #redefineClasses redefineClasses}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * (before any transformations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *  were applied), however they might not exactly match them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *  The constant pool might not have the same layout or contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *  The constant pool may have more or fewer entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *  Constant pool entries may be in a different order; however,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *  constant pool indices in the bytecodes of methods will correspond.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *  Some attributes may not be present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *  Where order is not meaningful, for example the order of methods,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *  order might not be preserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * This method operates on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * a set in order to allow interdependent changes to more than one class at the same time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * (a retransformation of class A can require a retransformation of class B).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * If a retransformed method has active stack frames, those active frames continue to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * run the bytecodes of the original method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * The retransformed method will be used on new invokes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * This method does not cause any initialization except that which would occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * under the customary JVM semantics. In other words, redefining a class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * does not cause its initializers to be run. The values of static variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * will remain as they were prior to the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Instances of the retransformed class are not affected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * <P>
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   222
     * The retransformation may change method bodies, the constant pool and
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   223
     * attributes (unless explicitly prohibited).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * The retransformation must not add, remove or rename fields or methods, change the
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   225
     * signatures of methods, or change inheritance.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   226
     * The retransformation must not change the <code>NestHost</code> or
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   227
     * <code>NestMembers</code> attributes.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   228
     * These restrictions may be lifted in future versions.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   229
     * The class file bytes are not checked, verified and installed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * until after the transformations have been applied, if the resultant bytes are in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * error this method will throw an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * If this method throws an exception, no classes have been retransformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * This method is intended for use in instrumentation, as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * {@linkplain Instrumentation class specification}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @param classes array of classes to retransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *                a zero-length array is allowed, in this case, this method does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @throws java.lang.instrument.UnmodifiableClassException if a specified class cannot be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * ({@link #isModifiableClass} would return <code>false</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @throws java.lang.UnsupportedOperationException if the current configuration of the JVM does not allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * retransformation ({@link #isRetransformClassesSupported} is false) or the retransformation attempted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * to make unsupported changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @throws java.lang.ClassFormatError if the data did not contain a valid class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @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
   248
     * @throws java.lang.UnsupportedClassVersionError if the class file version numbers are not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @throws java.lang.ClassCircularityError if the new classes contain a circularity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @throws java.lang.LinkageError if a linkage error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @throws java.lang.NullPointerException if the supplied classes  array or any of its components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *                                        is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @see #isRetransformClassesSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @see #addTransformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @see java.lang.instrument.ClassFileTransformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    retransformClasses(Class<?>... classes) throws UnmodifiableClassException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Returns whether or not the current JVM configuration supports redefinition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * of classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * The ability to redefine an already loaded class is an optional capability
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * of a JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Redefinition will only be supported if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * <code>Can-Redefine-Classes</code> manifest attribute is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * <code>true</code> in the agent JAR file (as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * {@linkplain java.lang.instrument package specification}) and the JVM supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * this capability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * During a single instantiation of a single JVM, multiple calls to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * method will always return the same answer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @return  true if the current JVM configuration supports redefinition of classes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @see #redefineClasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    isRedefineClassesSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * Redefine the supplied set of classes using the supplied class files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * This method is used to replace the definition of a class without reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * to the existing class file bytes, as one might do when recompiling from source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * for fix-and-continue debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Where the existing class file bytes are to be transformed (for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * example in bytecode instrumentation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * {@link #retransformClasses retransformClasses}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * should be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * This method operates on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * a set in order to allow interdependent changes to more than one class at the same time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * (a redefinition of class A can require a redefinition of class B).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * If a redefined method has active stack frames, those active frames continue to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * run the bytecodes of the original method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * The redefined method will be used on new invokes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * This method does not cause any initialization except that which would occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * under the customary JVM semantics. In other words, redefining a class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * does not cause its initializers to be run. The values of static variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * will remain as they were prior to the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Instances of the redefined class are not affected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * <P>
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   313
     * The redefinition may change method bodies, the constant pool and attributes
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   314
     * (unless explicitly prohibited).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * The redefinition must not add, remove or rename fields or methods, change the
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   316
     * signatures of methods, or change inheritance.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   317
     * The redefinition must not change the <code>NestHost</code> or
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   318
     * <code>NestMembers</code> attributes.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   319
     * These restrictions may be lifted in future versions.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 47216
diff changeset
   320
     * The class file bytes are not checked, verified and installed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * until after the transformations have been applied, if the resultant bytes are in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * error this method will throw an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * If this method throws an exception, no classes have been redefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * This method is intended for use in instrumentation, as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * {@linkplain Instrumentation class specification}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @param definitions array of classes to redefine with corresponding definitions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *                    a zero-length array is allowed, in this case, this method does nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @throws java.lang.instrument.UnmodifiableClassException if a specified class cannot be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * ({@link #isModifiableClass} would return <code>false</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @throws java.lang.UnsupportedOperationException if the current configuration of the JVM does not allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * redefinition ({@link #isRedefineClassesSupported} is false) or the redefinition attempted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * to make unsupported changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @throws java.lang.ClassFormatError if the data did not contain a valid class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @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
   339
     * @throws java.lang.UnsupportedClassVersionError if the class file version numbers are not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @throws java.lang.ClassCircularityError if the new classes contain a circularity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @throws java.lang.LinkageError if a linkage error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @throws java.lang.NullPointerException if the supplied definitions array or any of its components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @throws java.lang.ClassNotFoundException Can never be thrown (present for compatibility reasons only)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @see #isRedefineClassesSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @see #addTransformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @see java.lang.instrument.ClassFileTransformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    redefineClasses(ClassDefinition... definitions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        throws  ClassNotFoundException, UnmodifiableClassException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    /**
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   356
     * Tests whether a class is modifiable by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * {@linkplain #retransformClasses retransformation}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * or {@linkplain #redefineClasses redefinition}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * If a class is modifiable then this method returns <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * If a class is not modifiable then this method returns <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * For a class to be retransformed, {@link #isRetransformClassesSupported} must also be true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * But the value of <code>isRetransformClassesSupported()</code> does not influence the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * returned by this function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * For a class to be redefined, {@link #isRedefineClassesSupported} must also be true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * But the value of <code>isRedefineClassesSupported()</code> does not influence the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * returned by this function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Primitive classes (for example, <code>java.lang.Integer.TYPE</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * and array classes are never modifiable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *
18589
8b03e152e2fe 8019527: Fix doclint issues in java.lang.instrument
darcy
parents: 18156
diff changeset
   372
     * @param theClass the class to check for being modifiable
8b03e152e2fe 8019527: Fix doclint issues in java.lang.instrument
darcy
parents: 18156
diff changeset
   373
     * @return whether or not the argument class is modifiable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @throws java.lang.NullPointerException if the specified class is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @see #retransformClasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @see #isRetransformClassesSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @see #redefineClasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @see #isRedefineClassesSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    isModifiableClass(Class<?> theClass);
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 currently loaded by the JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @return an array containing all the classes loaded by the JVM, zero-length if there are none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     */
20754
3d7b2fafc34b 8025967: addition of -Werror broke the old build
valeriep
parents: 18589
diff changeset
   390
    @SuppressWarnings("rawtypes")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    Class[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    getAllLoadedClasses();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * Returns an array of all classes for which <code>loader</code> is an initiating loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * If the supplied loader is <code>null</code>, classes initiated by the bootstrap class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * loader are returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @param loader          the loader whose initiated class list will be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @return an array containing all the classes for which loader is an initiating loader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *          zero-length if there are none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
20754
3d7b2fafc34b 8025967: addition of -Werror broke the old build
valeriep
parents: 18589
diff changeset
   403
    @SuppressWarnings("rawtypes")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    Class[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    getInitiatedClasses(ClassLoader loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Returns an implementation-specific approximation of the amount of storage consumed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * the specified object. The result may include some or all of the object's overhead,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * and thus is useful for comparison within an implementation but not between implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * The estimate may change during a single invocation of the JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @param objectToSize     the object to size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @return an implementation-specific approximation of the amount of storage consumed by the specified object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @throws java.lang.NullPointerException if the supplied Object is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    getObjectSize(Object objectToSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * Specifies a JAR file with instrumentation classes to be defined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * bootstrap class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * <p> When the virtual machine's built-in class loader, known as the "bootstrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * class loader", unsuccessfully searches for a class, the entries in the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * java.util.jar.JarFile JAR file} will be searched as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * <p> This method may be used multiple times to add multiple JAR files to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * searched in the order that this method was invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * <p> The agent should take care to ensure that the JAR does not contain any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * classes or resources other than those to be defined by the bootstrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * class loader for the purpose of instrumentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * Failure to observe this warning could result in unexpected
3495
6b2a376f365c 6870298: 4/4 fix minor typos in java/lang/instrument/Instrumentation.java
dcubed
parents: 715
diff changeset
   437
     * behavior that is difficult to diagnose. For example, suppose there is a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * loader L, and L's parent for delegation is the bootstrap class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * Furthermore, a method in class C, a class defined by L, makes reference to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * a non-public accessor class C$1. If the JAR file contains a class C$1 then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * the delegation to the bootstrap class loader will cause C$1 to be defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * by the bootstrap class loader. In this example an <code>IllegalAccessError</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * will be thrown that may cause the application to fail. One approach to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * avoiding these types of issues, is to use a unique package name for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * instrumentation classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 5506
diff changeset
   447
     * <p>
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 5506
diff changeset
   448
     * <cite>The Java&trade; Virtual Machine Specification</cite>
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 5506
diff changeset
   449
     * specifies that a subsequent attempt to resolve a symbolic
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * reference that the Java virtual machine has previously unsuccessfully attempted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * to resolve always fails with the same error that was thrown as a result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * initial resolution attempt. Consequently, if the JAR file contains an entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * that corresponds to a class for which the Java virtual machine has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * unsuccessfully attempted to resolve a reference, then subsequent attempts to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * resolve that reference will fail with the same error as the initial attempt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @param   jarfile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *          The JAR file to be searched when the bootstrap class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *          unsuccessfully searches for a class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *          If <code>jarfile</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @see     #appendToSystemClassLoaderSearch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @see     java.lang.ClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @see     java.util.jar.JarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    appendToBootstrapClassLoaderSearch(JarFile jarfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * Specifies a JAR file with instrumentation classes to be defined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * system class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * When the system class loader for delegation (see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * {@link java.lang.ClassLoader#getSystemClassLoader getSystemClassLoader()})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * unsuccessfully searches for a class, the entries in the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * java.util.jar.JarFile JarFile} will be searched as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * <p> This method may be used multiple times to add multiple JAR files to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * searched in the order that this method was invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * <p> The agent should take care to ensure that the JAR does not contain any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * classes or resources other than those to be defined by the system class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * loader for the purpose of instrumentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * Failure to observe this warning could result in unexpected
3495
6b2a376f365c 6870298: 4/4 fix minor typos in java/lang/instrument/Instrumentation.java
dcubed
parents: 715
diff changeset
   489
     * behavior that is difficult to diagnose (see
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * {@link #appendToBootstrapClassLoaderSearch
3495
6b2a376f365c 6870298: 4/4 fix minor typos in java/lang/instrument/Instrumentation.java
dcubed
parents: 715
diff changeset
   491
     * appendToBootstrapClassLoaderSearch}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * <p> The system class loader supports adding a JAR file to be searched if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * it implements a method named <code>appendToClassPathForInstrumentation</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * which takes a single parameter of type <code>java.lang.String</code>. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * method is not required to have <code>public</code> access. The name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * the JAR file is obtained by invoking the {@link java.util.zip.ZipFile#getName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * getName()} method on the <code>jarfile</code> and this is provided as the
3495
6b2a376f365c 6870298: 4/4 fix minor typos in java/lang/instrument/Instrumentation.java
dcubed
parents: 715
diff changeset
   499
     * parameter to the <code>appendToClassPathForInstrumentation</code> method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 5506
diff changeset
   501
     * <p>
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 5506
diff changeset
   502
     * <cite>The Java&trade; Virtual Machine Specification</cite>
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 5506
diff changeset
   503
     * specifies that a subsequent attempt to resolve a symbolic
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * reference that the Java virtual machine has previously unsuccessfully attempted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * to resolve always fails with the same error that was thrown as a result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * initial resolution attempt. Consequently, if the JAR file contains an entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * that corresponds to a class for which the Java virtual machine has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * unsuccessfully attempted to resolve a reference, then subsequent attempts to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * resolve that reference will fail with the same error as the initial attempt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * <p> This method does not change the value of <code>java.class.path</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * {@link java.lang.System#getProperties system property}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @param   jarfile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *          The JAR file to be searched when the system class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *          unsuccessfully searches for a class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * @throws  UnsupportedOperationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *          If the system class loader does not support appending a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *          a JAR file to be searched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     *          If <code>jarfile</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * @see     #appendToBootstrapClassLoaderSearch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @see     java.lang.ClassLoader#getSystemClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @see     java.util.jar.JarFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    appendToSystemClassLoaderSearch(JarFile jarfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * Returns whether the current JVM configuration supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * {@linkplain #setNativeMethodPrefix(ClassFileTransformer,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * setting a native method prefix}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * The ability to set a native method prefix is an optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * capability of a JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * Setting a native method prefix will only be supported if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * <code>Can-Set-Native-Method-Prefix</code> manifest attribute is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * <code>true</code> in the agent JAR file (as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * {@linkplain java.lang.instrument package specification}) and the JVM supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * this capability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * During a single instantiation of a single JVM, multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * calls to this method will always return the same answer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @return  true if the current JVM configuration supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * setting a native method prefix, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * @see #setNativeMethodPrefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    isNativeMethodPrefixSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * This method modifies the failure handling of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * native method resolution by allowing retry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * with a prefix applied to the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * When used with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * {@link java.lang.instrument.ClassFileTransformer ClassFileTransformer},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * it enables native methods to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * instrumented.
18589
8b03e152e2fe 8019527: Fix doclint issues in java.lang.instrument
darcy
parents: 18156
diff changeset
   562
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * Since native methods cannot be directly instrumented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * (they have no bytecodes), they must be wrapped with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * a non-native method which can be instrumented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * For example, if we had:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *   native boolean foo(int x);</pre>
18589
8b03e152e2fe 8019527: Fix doclint issues in java.lang.instrument
darcy
parents: 18156
diff changeset
   569
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * We could transform the class file (with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * ClassFileTransformer during the initial definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * of the class) so that this becomes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     *   boolean foo(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     *     <i>... record entry to foo ...</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     *     return wrapped_foo(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *   native boolean wrapped_foo(int x);</pre>
18589
8b03e152e2fe 8019527: Fix doclint issues in java.lang.instrument
darcy
parents: 18156
diff changeset
   580
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * Where <code>foo</code> becomes a wrapper for the actual native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * method with the appended prefix "wrapped_".  Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * "wrapped_" would be a poor choice of prefix since it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * might conceivably form the name of an existing method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * thus something like "$$$MyAgentWrapped$$$_" would be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * better but would make these examples less readable.
18589
8b03e152e2fe 8019527: Fix doclint issues in java.lang.instrument
darcy
parents: 18156
diff changeset
   587
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * The wrapper will allow data to be collected on the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * method call, but now the problem becomes linking up the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * wrapped method with the native implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * That is, the method <code>wrapped_foo</code> needs to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * resolved to the native implementation of <code>foo</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * which might be:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *   Java_somePackage_someClass_foo(JNIEnv* env, jint x)</pre>
18589
8b03e152e2fe 8019527: Fix doclint issues in java.lang.instrument
darcy
parents: 18156
diff changeset
   596
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * This function allows the prefix to be specified and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * proper resolution to occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * Specifically, when the standard resolution fails, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * resolution is retried taking the prefix into consideration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * There are two ways that resolution occurs, explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * resolution with the JNI function <code>RegisterNatives</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * and the normal automatic resolution.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * <code>RegisterNatives</code>, the JVM will attempt this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * association:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14342
diff changeset
   606
     * <pre>{@code
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14342
diff changeset
   607
     *   method(foo) -> nativeImplementation(foo)
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14342
diff changeset
   608
     * }</pre>
18589
8b03e152e2fe 8019527: Fix doclint issues in java.lang.instrument
darcy
parents: 18156
diff changeset
   609
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * When this fails, the resolution will be retried with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * the specified prefix prepended to the method name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * yielding the correct resolution:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14342
diff changeset
   613
     * <pre>{@code
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14342
diff changeset
   614
     *   method(wrapped_foo) -> nativeImplementation(foo)
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14342
diff changeset
   615
     * }</pre>
18589
8b03e152e2fe 8019527: Fix doclint issues in java.lang.instrument
darcy
parents: 18156
diff changeset
   616
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * For automatic resolution, the JVM will attempt:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14342
diff changeset
   618
     * <pre>{@code
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14342
diff changeset
   619
     *   method(wrapped_foo) -> nativeImplementation(wrapped_foo)
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14342
diff changeset
   620
     * }</pre>
18589
8b03e152e2fe 8019527: Fix doclint issues in java.lang.instrument
darcy
parents: 18156
diff changeset
   621
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * When this fails, the resolution will be retried with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * the specified prefix deleted from the implementation name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * yielding the correct resolution:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14342
diff changeset
   625
     * <pre>{@code
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14342
diff changeset
   626
     *   method(wrapped_foo) -> nativeImplementation(foo)
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14342
diff changeset
   627
     * }</pre>
18589
8b03e152e2fe 8019527: Fix doclint issues in java.lang.instrument
darcy
parents: 18156
diff changeset
   628
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * Note that since the prefix is only used when standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * resolution fails, native methods can be wrapped selectively.
18589
8b03e152e2fe 8019527: Fix doclint issues in java.lang.instrument
darcy
parents: 18156
diff changeset
   631
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * Since each <code>ClassFileTransformer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * can do its own transformation of the bytecodes, more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * than one layer of wrappers may be applied. Thus each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * transformer needs its own prefix.  Since transformations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * are applied in order, the prefixes, if applied, will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * be applied in the same order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * (see {@link #addTransformer(ClassFileTransformer,boolean) addTransformer}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * Thus if three transformers applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * wrappers, <code>foo</code> might become
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * <code>$trans3_$trans2_$trans1_foo</code>.  But if, say,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * the second transformer did not apply a wrapper to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * <code>foo</code> it would be just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * <code>$trans3_$trans1_foo</code>.  To be able to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * efficiently determine the sequence of prefixes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * an intermediate prefix is only applied if its non-native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * wrapper exists.  Thus, in the last example, even though
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * <code>$trans1_foo</code> is not a native method, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * <code>$trans1_</code> prefix is applied since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * <code>$trans1_foo</code> exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * @param   transformer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *          The ClassFileTransformer which wraps using this prefix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @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
   655
     *          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
   656
     *          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
   657
     *          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
   658
     *          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
   659
     *          this transformer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * @throws java.lang.NullPointerException if passed a <code>null</code> transformer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @throws java.lang.UnsupportedOperationException if the current configuration of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     *           the JVM does not allow setting a native method prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *           ({@link #isNativeMethodPrefixSupported} is false).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * @throws java.lang.IllegalArgumentException if the transformer is not registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *           (see {@link #addTransformer(ClassFileTransformer,boolean) addTransformer}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    setNativeMethodPrefix(ClassFileTransformer transformer, String prefix);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   671
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   672
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   673
     * Redefine a module to expand the set of modules that it reads, the set of
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   674
     * packages that it exports or opens, or the services that it uses or
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   675
     * provides. This method facilitates the instrumentation of code in named
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   676
     * modules where that instrumentation requires changes to the set of modules
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   677
     * that are read, the packages that are exported or open, or the services
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   678
     * that are used or provided.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   679
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   680
     * <p> This method cannot reduce the set of modules that a module reads, nor
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   681
     * reduce the set of packages that it exports or opens, nor reduce the set
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   682
     * of services that it uses or provides. This method is a no-op when invoked
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   683
     * to redefine an unnamed module. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   684
     *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   685
     * <p> When expanding the services that a module uses or provides then the
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   686
     * onus is on the agent to ensure that the service type will be accessible at
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   687
     * each instrumentation site where the service type is used. This method
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   688
     * does not check if the service type is a member of the module or in a
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   689
     * package exported to the module by another module that it reads. </p>
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   690
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   691
     * <p> The {@code extraExports} parameter is the map of additional packages
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   692
     * to export. The {@code extraOpens} parameter is the map of additional
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   693
     * packages to open. In both cases, the map key is the fully-qualified name
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   694
     * of the package as defined in section 6.5.3 of
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   695
     * <cite>The Java&trade; Language Specification </cite>, for example, {@code
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   696
     * "java.lang"}. The map value is the non-empty set of modules that the
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   697
     * package should be exported or opened to. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   698
     *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   699
     * <p> The {@code extraProvides} parameter is the additional service providers
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   700
     * for the module to provide. The map key is the service type. The map value
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   701
     * is the non-empty list of implementation types, each of which is a member
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   702
     * of the module and an implementation of the service. </p>
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   703
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   704
     * <p> This method is safe for concurrent use and so allows multiple agents
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   705
     * to instrument and update the same module at around the same time. </p>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   706
     *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   707
     * @param module the module to redefine
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   708
     * @param extraReads the possibly-empty set of additional modules to read
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   709
     * @param extraExports the possibly-empty map of additional packages to export
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   710
     * @param extraOpens the possibly-empty map of additional packages to open
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   711
     * @param extraUses the possibly-empty set of additional services to use
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   712
     * @param extraProvides the possibly-empty map of additional services to provide
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   713
     *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   714
     * @throws IllegalArgumentException
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   715
     *         If {@code extraExports} or {@code extraOpens} contains a key
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   716
     *         that is not a package in the module; if {@code extraExports} or
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   717
     *         {@code extraOpens} maps a key to an empty set; if a value in the
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   718
     *         {@code extraProvides} map contains a service provider type that
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   719
     *         is not a member of the module or an implementation of the service;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   720
     *         or {@code extraProvides} maps a key to an empty list
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   721
     * @throws UnmodifiableModuleException if the module cannot be modified
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   722
     * @throws NullPointerException if any of the arguments are {@code null} or
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   723
     *         any of the Sets or Maps contains a {@code null} key or value
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   724
     *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   725
     * @see #isModifiableModule(Module)
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   726
     * @since 9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42338
diff changeset
   727
     * @spec JPMS
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   728
     */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   729
    void redefineModule(Module module,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   730
                        Set<Module> extraReads,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   731
                        Map<String, Set<Module>> extraExports,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   732
                        Map<String, Set<Module>> extraOpens,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   733
                        Set<Class<?>> extraUses,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39739
diff changeset
   734
                        Map<Class<?>, List<Class<?>>> extraProvides);
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   735
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   736
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   737
     * Tests whether a module can be modified with {@link #redefineModule
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   738
     * redefineModule}. If a module is modifiable then this method returns
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   739
     * {@code true}. If a module is not modifiable then this method returns
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   740
     * {@code false}. This method always returns {@code true} when the module
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44545
diff changeset
   741
     * is an unnamed module (as redefining an unnamed module is a no-op).
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   742
     *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   743
     * @param module the module to test if it can be modified
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   744
     * @return {@code true} if the module is modifiable, otherwise {@code false}
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   745
     * @throws NullPointerException if the module is {@code null}
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   746
     *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   747
     * @since 9
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   748
     * @spec JPMS
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   749
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   750
    boolean isModifiableModule(Module module);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
}