jdk/src/java.instrument/share/classes/java/lang/instrument/ClassFileTransformer.java
author alanb
Wed, 22 Mar 2017 16:26:27 +0000
changeset 44359 c6761862ca0b
parent 43712 5dfd0950317c
child 44545 83b611b88ac8
permissions -rw-r--r--
8174823: Module system implementation refresh (3/2017) Reviewed-by: chegar, mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, sundararajan.athijegannathan@oracle.com, peter.levart@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
     2
 * Copyright (c) 2003, 2016, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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.lang.reflect.Module;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    29
import java.security.AccessController;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    30
import java.security.PrivilegedAction;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    31
import java.security.ProtectionDomain;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Copyright 2003 Wily Technology, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    38
 * A transformer of class files. An agent registers an implementation of this
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    39
 * interface using the {@link Instrumentation#addTransformer addTransformer}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    40
 * method so that the transformer's {@link
39739
5d058d6bd245 8159147: Add ClassLoader parameter to new ClassFileTransformer transform method
sspitsyn
parents: 36511
diff changeset
    41
 * ClassFileTransformer#transform(Module,ClassLoader,String,Class,ProtectionDomain,byte[])
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    42
 * transform} method is invoked when classes are loaded,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    43
 * {@link Instrumentation#redefineClasses redefined}, or
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    44
 * {@link Instrumentation#retransformClasses retransformed}. The implementation
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    45
 * should override one of the {@code transform} methods defined here.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    46
 * Transformers are invoked before the class is defined by the Java virtual
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    47
 * machine.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    48
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    49
 * <P>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    50
 * There are two kinds of transformers, determined by the <code>canRetransform</code>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    51
 * parameter of
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    52
 * {@link java.lang.instrument.Instrumentation#addTransformer(ClassFileTransformer,boolean)}:
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    53
 *  <ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    54
 *    <li><i>retransformation capable</i> transformers that were added with
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    55
 *        <code>canRetransform</code> as true
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    56
 *    </li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    57
 *    <li><i>retransformation incapable</i> transformers that were added with
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    58
 *        <code>canRetransform</code> as false or where added with
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    59
 *        {@link java.lang.instrument.Instrumentation#addTransformer(ClassFileTransformer)}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    60
 *    </li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    61
 *  </ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    62
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    63
 * <P>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    64
 * Once a transformer has been registered with
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    65
 * {@link java.lang.instrument.Instrumentation#addTransformer(ClassFileTransformer,boolean)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    66
 * addTransformer},
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    67
 * the transformer will be called for every new class definition and every class redefinition.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    68
 * Retransformation capable transformers will also be called on every class retransformation.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    69
 * The request for a new class definition is made with
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    70
 * {@link java.lang.ClassLoader#defineClass ClassLoader.defineClass}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    71
 * or its native equivalents.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    72
 * The request for a class redefinition is made with
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    73
 * {@link java.lang.instrument.Instrumentation#redefineClasses Instrumentation.redefineClasses}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    74
 * or its native equivalents.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    75
 * The request for a class retransformation is made with
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    76
 * {@link java.lang.instrument.Instrumentation#retransformClasses Instrumentation.retransformClasses}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    77
 * or its native equivalents.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    78
 * The transformer is called during the processing of the request, before the class file bytes
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    79
 * have been verified or applied.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    80
 * When there are multiple transformers, transformations are composed by chaining the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    81
 * <code>transform</code> calls.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    82
 * That is, the byte array returned by one call to <code>transform</code> becomes the input
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    83
 * (via the <code>classfileBuffer</code> parameter) to the next call.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    84
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    85
 * <P>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    86
 * Transformations are applied in the following order:
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    87
 *  <ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    88
 *    <li>Retransformation incapable transformers
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    89
 *    </li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    90
 *    <li>Retransformation incapable native transformers
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    91
 *    </li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    92
 *    <li>Retransformation capable transformers
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    93
 *    </li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    94
 *    <li>Retransformation capable native transformers
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    95
 *    </li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    96
 *  </ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    97
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    98
 * <P>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    99
 * For retransformations, the retransformation incapable transformers are not
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   100
 * called, instead the result of the previous transformation is reused.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   101
 * In all other cases, this method is called.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   102
 * Within each of these groupings, transformers are called in the order registered.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   103
 * Native transformers are provided by the <code>ClassFileLoadHook</code> event
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   104
 * in the Java Virtual Machine Tool Interface).
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   105
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   106
 * <P>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   107
 * The input (via the <code>classfileBuffer</code> parameter) to the first
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   108
 * transformer is:
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   109
 *  <ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   110
 *    <li>for new class definition,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   111
 *        the bytes passed to <code>ClassLoader.defineClass</code>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   112
 *    </li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   113
 *    <li>for class redefinition,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   114
 *        <code>definitions.getDefinitionClassFile()</code> where
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   115
 *        <code>definitions</code> is the parameter to
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   116
 *        {@link java.lang.instrument.Instrumentation#redefineClasses
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   117
 *         Instrumentation.redefineClasses}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   118
 *    </li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   119
 *    <li>for class retransformation,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   120
 *         the bytes passed to the new class definition or, if redefined,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   121
 *         the last redefinition, with all transformations made by retransformation
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   122
 *         incapable transformers reapplied automatically and unaltered;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   123
 *         for details see
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   124
 *         {@link java.lang.instrument.Instrumentation#retransformClasses
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   125
 *          Instrumentation.retransformClasses}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   126
 *    </li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   127
 *  </ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   128
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   129
 * <P>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   130
 * If the implementing method determines that no transformations are needed,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   131
 * it should return <code>null</code>.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   132
 * Otherwise, it should create a new <code>byte[]</code> array,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   133
 * copy the input <code>classfileBuffer</code> into it,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   134
 * along with all desired transformations, and return the new array.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   135
 * The input <code>classfileBuffer</code> must not be modified.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   136
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   137
 * <P>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   138
 * In the retransform and redefine cases,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   139
 * the transformer must support the redefinition semantics:
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   140
 * if a class that the transformer changed during initial definition is later
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   141
 * retransformed or redefined, the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   142
 * transformer must insure that the second class output class file is a legal
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   143
 * redefinition of the first output class file.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   144
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   145
 * <P>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   146
 * If the transformer throws an exception (which it doesn't catch),
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   147
 * subsequent transformers will still be called and the load, redefine
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   148
 * or retransform will still be attempted.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   149
 * Thus, throwing an exception has the same effect as returning <code>null</code>.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   150
 * To prevent unexpected behavior when unchecked exceptions are generated
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   151
 * in transformer code, a transformer can catch <code>Throwable</code>.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   152
 * If the transformer believes the <code>classFileBuffer</code> does not
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   153
 * represent a validly formatted class file, it should throw
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   154
 * an <code>IllegalClassFormatException</code>;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   155
 * while this has the same effect as returning null. it facilitates the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   156
 * logging or debugging of format corruptions.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   157
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * <P>
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
   159
 * Note the term <i>class file</i> is used as defined in section 3.1 of
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   160
 * <cite>The Java&trade; Virtual Machine Specification</cite>, to mean a
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   161
 * sequence of bytes in class file format, whether or not they reside in a
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   162
 * file.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * @see     java.lang.instrument.Instrumentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
public interface ClassFileTransformer {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   169
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   171
     * Transforms the given class file and returns a new replacement class file.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   172
     * This method is invoked when the {@link Module Module} bearing {@link
39739
5d058d6bd245 8159147: Add ClassLoader parameter to new ClassFileTransformer transform method
sspitsyn
parents: 36511
diff changeset
   173
     * ClassFileTransformer#transform(Module,ClassLoader,String,Class,ProtectionDomain,byte[])
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   174
     * transform} is not overridden.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   176
     * @implSpec The default implementation returns null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param loader                the defining loader of the class to be transformed,
39739
5d058d6bd245 8159147: Add ClassLoader parameter to new ClassFileTransformer transform method
sspitsyn
parents: 36511
diff changeset
   179
     *                              may be {@code null} if the bootstrap loader
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param className             the name of the class in the internal form of fully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *                              qualified class and interface names as defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *                              <i>The Java Virtual Machine Specification</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *                              For example, <code>"java/util/List"</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @param classBeingRedefined   if this is triggered by a redefine or retransform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *                              the class being redefined or retransformed;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   186
     *                              if this is a class load, {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param protectionDomain      the protection domain of the class being defined or redefined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @param classfileBuffer       the input byte buffer in class file format - must not be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   190
     * @throws IllegalClassFormatException
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   191
     *         if the input does not represent a well-formed class file
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   192
     * @return a well-formed class file buffer (the result of the transform),
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   193
     *         or {@code null} if no transform is performed
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   194
     *
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   195
     * @revised 9
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   196
     * @spec JPMS
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   198
    default byte[]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    transform(  ClassLoader         loader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                String              className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                Class<?>            classBeingRedefined,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                ProtectionDomain    protectionDomain,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                byte[]              classfileBuffer)
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   204
        throws IllegalClassFormatException {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   205
        return null;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   206
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   207
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   208
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   209
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   210
     * Transforms the given class file and returns a new replacement class file.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   211
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   212
     * @implSpec The default implementation of this method invokes the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   213
     * {@link #transform(ClassLoader,String,Class,ProtectionDomain,byte[]) transform}
39739
5d058d6bd245 8159147: Add ClassLoader parameter to new ClassFileTransformer transform method
sspitsyn
parents: 36511
diff changeset
   214
     * method.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   215
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   216
     * @param module                the module of the class to be transformed
39739
5d058d6bd245 8159147: Add ClassLoader parameter to new ClassFileTransformer transform method
sspitsyn
parents: 36511
diff changeset
   217
     * @param loader                the defining loader of the class to be transformed,
5d058d6bd245 8159147: Add ClassLoader parameter to new ClassFileTransformer transform method
sspitsyn
parents: 36511
diff changeset
   218
     *                              may be {@code null} if the bootstrap loader
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   219
     * @param className             the name of the class in the internal form of fully
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   220
     *                              qualified class and interface names as defined in
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   221
     *                              <i>The Java Virtual Machine Specification</i>.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   222
     *                              For example, <code>"java/util/List"</code>.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   223
     * @param classBeingRedefined   if this is triggered by a redefine or retransform,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   224
     *                              the class being redefined or retransformed;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   225
     *                              if this is a class load, {@code null}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   226
     * @param protectionDomain      the protection domain of the class being defined or redefined
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   227
     * @param classfileBuffer       the input byte buffer in class file format - must not be modified
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   228
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   229
     * @throws IllegalClassFormatException
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   230
     *         if the input does not represent a well-formed class file
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   231
     * @return a well-formed class file buffer (the result of the transform),
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   232
     *         or {@code null} if no transform is performed
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   233
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   234
     * @since  9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 39739
diff changeset
   235
     * @spec JPMS
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   236
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   237
    default byte[]
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   238
    transform(  Module              module,
39739
5d058d6bd245 8159147: Add ClassLoader parameter to new ClassFileTransformer transform method
sspitsyn
parents: 36511
diff changeset
   239
                ClassLoader         loader,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   240
                String              className,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   241
                Class<?>            classBeingRedefined,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   242
                ProtectionDomain    protectionDomain,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   243
                byte[]              classfileBuffer)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   244
        throws IllegalClassFormatException {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   245
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   246
        // invoke the legacy transform method
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   247
        return transform(loader,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   248
                         className,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   249
                         classBeingRedefined,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   250
                         protectionDomain,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   251
                         classfileBuffer);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   252
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
}