jdk/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java
author sspitsyn
Sat, 09 Jul 2016 21:41:14 -0700
changeset 39739 5d058d6bd245
parent 37807 78e5cb21ca13
child 42338 a60f280f803c
permissions -rw-r--r--
8159147: Add ClassLoader parameter to new ClassFileTransformer transform method Summary: Add ClassLoader parameter to new ClassFileTransformer transform method Reviewed-by: alanb, dholmes, dcubed, mchung
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: 715
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: 715
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: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package sun.instrument;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.Method;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    30
import java.lang.reflect.Module;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.reflect.AccessibleObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.instrument.ClassFileTransformer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.lang.instrument.ClassDefinition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.lang.instrument.Instrumentation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.security.ProtectionDomain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    41
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.jar.JarFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Copyright 2003 Wily Technology, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * The Java side of the JPLIS implementation. Works in concert with a native JVMTI agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * to implement the JPLIS API set. Provides both the Java API implementation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * the Instrumentation interface and utility Java routines to support the native code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Keeps a pointer to the native data structure in a scalar field to allow native
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * processing behind native methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class InstrumentationImpl implements Instrumentation {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private final     TransformerManager      mTransformerManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private           TransformerManager      mRetransfomableTransformerManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // needs to store a native pointer, so use 64 bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private final     long                    mNativeAgent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private final     boolean                 mEnvironmentSupportsRedefineClasses;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private volatile  boolean                 mEnvironmentSupportsRetransformClassesKnown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private volatile  boolean                 mEnvironmentSupportsRetransformClasses;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private final     boolean                 mEnvironmentSupportsNativeMethodPrefix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    InstrumentationImpl(long    nativeAgent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                        boolean environmentSupportsRedefineClasses,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                        boolean environmentSupportsNativeMethodPrefix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        mTransformerManager                    = new TransformerManager(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        mRetransfomableTransformerManager      = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        mNativeAgent                           = nativeAgent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        mEnvironmentSupportsRedefineClasses    = environmentSupportsRedefineClasses;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        mEnvironmentSupportsRetransformClassesKnown = false; // false = need to ask
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        mEnvironmentSupportsRetransformClasses = false;      // don't know yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        mEnvironmentSupportsNativeMethodPrefix = environmentSupportsNativeMethodPrefix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    addTransformer(ClassFileTransformer transformer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        addTransformer(transformer, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public synchronized void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    addTransformer(ClassFileTransformer transformer, boolean canRetransform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (transformer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            throw new NullPointerException("null passed as 'transformer' in addTransformer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        if (canRetransform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            if (!isRetransformClassesSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                throw new UnsupportedOperationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                  "adding retransformable transformers is not supported in this environment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            if (mRetransfomableTransformerManager == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                mRetransfomableTransformerManager = new TransformerManager(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            mRetransfomableTransformerManager.addTransformer(transformer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            if (mRetransfomableTransformerManager.getTransformerCount() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                setHasRetransformableTransformers(mNativeAgent, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            mTransformerManager.addTransformer(transformer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public synchronized boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    removeTransformer(ClassFileTransformer transformer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (transformer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            throw new NullPointerException("null passed as 'transformer' in removeTransformer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        TransformerManager mgr = findTransformerManager(transformer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (mgr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            mgr.removeTransformer(transformer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            if (mgr.isRetransformable() && mgr.getTransformerCount() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                setHasRetransformableTransformers(mNativeAgent, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    isModifiableClass(Class<?> theClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (theClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            throw new NullPointerException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                         "null passed as 'theClass' in isModifiableClass");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        return isModifiableClass0(mNativeAgent, theClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    isRetransformClassesSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        // ask lazily since there is some overhead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (!mEnvironmentSupportsRetransformClassesKnown) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            mEnvironmentSupportsRetransformClasses = isRetransformClassesSupported0(mNativeAgent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            mEnvironmentSupportsRetransformClassesKnown = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return mEnvironmentSupportsRetransformClasses;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public void
11125
99b115114fa3 7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents: 5506
diff changeset
   141
    retransformClasses(Class<?>... classes) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (!isRetransformClassesSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            throw new UnsupportedOperationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
              "retransformClasses is not supported in this environment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        retransformClasses0(mNativeAgent, classes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    isRedefineClassesSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return mEnvironmentSupportsRedefineClasses;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public void
11125
99b115114fa3 7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents: 5506
diff changeset
   155
    redefineClasses(ClassDefinition...  definitions)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            throws  ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (!isRedefineClassesSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            throw new UnsupportedOperationException("redefineClasses is not supported in this environment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (definitions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            throw new NullPointerException("null passed as 'definitions' in redefineClasses");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        for (int i = 0; i < definitions.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            if (definitions[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                throw new NullPointerException("element of 'definitions' is null in redefineClasses");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (definitions.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            return; // short-circuit if there are no changes requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        redefineClasses0(mNativeAgent, definitions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
20754
3d7b2fafc34b 8025967: addition of -Werror broke the old build
valeriep
parents: 14342
diff changeset
   175
    @SuppressWarnings("rawtypes")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public Class[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    getAllLoadedClasses() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        return getAllLoadedClasses0(mNativeAgent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
20754
3d7b2fafc34b 8025967: addition of -Werror broke the old build
valeriep
parents: 14342
diff changeset
   181
    @SuppressWarnings("rawtypes")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public Class[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    getInitiatedClasses(ClassLoader loader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        return getInitiatedClasses0(mNativeAgent, loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    getObjectSize(Object objectToSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (objectToSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            throw new NullPointerException("null passed as 'objectToSize' in getObjectSize");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return getObjectSize0(mNativeAgent, objectToSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    appendToBootstrapClassLoaderSearch(JarFile jarfile) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        appendToClassLoaderSearch0(mNativeAgent, jarfile.getName(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    appendToSystemClassLoaderSearch(JarFile jarfile) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        appendToClassLoaderSearch0(mNativeAgent, jarfile.getName(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    isNativeMethodPrefixSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return mEnvironmentSupportsNativeMethodPrefix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public synchronized void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    setNativeMethodPrefix(ClassFileTransformer transformer, String prefix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (!isNativeMethodPrefixSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            throw new UnsupportedOperationException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                   "setNativeMethodPrefix is not supported in this environment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (transformer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            throw new NullPointerException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                       "null passed as 'transformer' in setNativeMethodPrefix");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        TransformerManager mgr = findTransformerManager(transformer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (mgr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                       "transformer not registered in setNativeMethodPrefix");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        mgr.setNativeMethodPrefix(transformer, prefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        String[] prefixes = mgr.getNativeMethodPrefixes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        setNativeMethodPrefixes(mNativeAgent, prefixes, mgr.isRetransformable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   230
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   231
    public void addModuleReads(Module module, Module other) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   232
        Objects.requireNonNull(module);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   233
        Objects.requireNonNull(other);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   234
        jdk.internal.module.Modules.addReads(module, other);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   235
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   236
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   237
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private TransformerManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    findTransformerManager(ClassFileTransformer transformer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (mTransformerManager.includesTransformer(transformer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            return mTransformerManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (mRetransfomableTransformerManager != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                mRetransfomableTransformerManager.includesTransformer(transformer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            return mRetransfomableTransformerManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *  Natives
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    private native boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    isModifiableClass0(long nativeAgent, Class<?> theClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    private native boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    isRetransformClassesSupported0(long nativeAgent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    private native void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    setHasRetransformableTransformers(long nativeAgent, boolean has);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    private native void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    retransformClasses0(long nativeAgent, Class<?>[] classes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    private native void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    redefineClasses0(long nativeAgent, ClassDefinition[]  definitions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        throws  ClassNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
20754
3d7b2fafc34b 8025967: addition of -Werror broke the old build
valeriep
parents: 14342
diff changeset
   270
    @SuppressWarnings("rawtypes")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    private native Class[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    getAllLoadedClasses0(long nativeAgent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
20754
3d7b2fafc34b 8025967: addition of -Werror broke the old build
valeriep
parents: 14342
diff changeset
   274
    @SuppressWarnings("rawtypes")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private native Class[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    getInitiatedClasses0(long nativeAgent, ClassLoader loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    private native long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    getObjectSize0(long nativeAgent, Object objectToSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    private native void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    appendToClassLoaderSearch0(long nativeAgent, String jarfile, boolean bootLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    private native void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    setNativeMethodPrefixes(long nativeAgent, String[] prefixes, boolean isRetransformable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        System.loadLibrary("instrument");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *  Internals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    // Enable or disable Java programming language access checks on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    // reflected object (for example, a method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    private static void setAccessible(final AccessibleObject ao, final boolean accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                    ao.setAccessible(accessible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    // Attempt to load and start an agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    private void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    loadClassAndStartAgent( String  classname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                            String  methodname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                            String  optionsString)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        ClassLoader mainAppLoader   = ClassLoader.getSystemClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        Class<?>    javaAgentClass  = mainAppLoader.loadClass(classname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        Method m = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        NoSuchMethodException firstExc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        boolean twoArgAgent = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
274
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   320
        // The agent class must have a premain or agentmain method that
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   321
        // has 1 or 2 arguments. We check in the following order:
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   322
        //
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   323
        // 1) declared with a signature of (String, Instrumentation)
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   324
        // 2) declared with a signature of (String)
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   325
        // 3) inherited with a signature of (String, Instrumentation)
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   326
        // 4) inherited with a signature of (String)
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   327
        //
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   328
        // So the declared version of either 1-arg or 2-arg always takes
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   329
        // primary precedence over an inherited version. After that, the
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   330
        // 2-arg version takes precedence over the 1-arg version.
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   331
        //
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   332
        // If no method is found then we throw the NoSuchMethodException
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   333
        // from the first attempt so that the exception text indicates
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   334
        // the lookup failed for the 2-arg method (same as JDK5.0).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        try {
274
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   337
            m = javaAgentClass.getDeclaredMethod( methodname,
11125
99b115114fa3 7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents: 5506
diff changeset
   338
                                 new Class<?>[] {
274
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   339
                                     String.class,
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   340
                                     java.lang.instrument.Instrumentation.class
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   341
                                 }
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   342
                               );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            twoArgAgent = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        } catch (NoSuchMethodException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            // remember the NoSuchMethodException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            firstExc = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (m == null) {
274
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   350
            // now try the declared 1-arg method
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   351
            try {
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   352
                m = javaAgentClass.getDeclaredMethod(methodname,
11125
99b115114fa3 7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents: 5506
diff changeset
   353
                                                 new Class<?>[] { String.class });
274
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   354
            } catch (NoSuchMethodException x) {
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   355
                // ignore this exception because we'll try
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   356
                // two arg inheritance next
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   357
            }
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   358
        }
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   359
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   360
        if (m == null) {
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   361
            // now try the inherited 2-arg method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            try {
274
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   363
                m = javaAgentClass.getMethod( methodname,
11125
99b115114fa3 7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents: 5506
diff changeset
   364
                                 new Class<?>[] {
274
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   365
                                     String.class,
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   366
                                     java.lang.instrument.Instrumentation.class
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   367
                                 }
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   368
                               );
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   369
                twoArgAgent = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            } catch (NoSuchMethodException x) {
274
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   371
                // ignore this exception because we'll try
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   372
                // one arg inheritance next
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   373
            }
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   374
        }
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   375
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   376
        if (m == null) {
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   377
            // finally try the inherited 1-arg method
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   378
            try {
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   379
                m = javaAgentClass.getMethod(methodname,
11125
99b115114fa3 7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents: 5506
diff changeset
   380
                                             new Class<?>[] { String.class });
274
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   381
            } catch (NoSuchMethodException x) {
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   382
                // none of the methods exists so we throw the
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   383
                // first NoSuchMethodException as per 5.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                throw firstExc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        // the premain method should not be required to be public,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        // make it accessible so we can call it
274
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   390
        // Note: The spec says the following:
d0ca9ee56273 6289149: 4/4 Java Agent will pick wrong execution path while attaching
dcubed
parents: 2
diff changeset
   391
        //     The agent class must implement a public static premain method...
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        setAccessible(m, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        // invoke the 1 or 2-arg method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (twoArgAgent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            m.invoke(null, new Object[] { optionsString, this });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            m.invoke(null, new Object[] { optionsString });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    // WARNING: the native code knows the name & signature of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    private void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    loadClassAndCallPremain(    String  classname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                                String  optionsString)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        loadClassAndStartAgent( classname, "premain", optionsString );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    // WARNING: the native code knows the name & signature of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    private void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    loadClassAndCallAgentmain(  String  classname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                                String  optionsString)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        loadClassAndStartAgent( classname, "agentmain", optionsString );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    // WARNING: the native code knows the name & signature of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    private byte[]
39739
5d058d6bd245 8159147: Add ClassLoader parameter to new ClassFileTransformer transform method
sspitsyn
parents: 37807
diff changeset
   423
    transform(  Module              module,
5d058d6bd245 8159147: Add ClassLoader parameter to new ClassFileTransformer transform method
sspitsyn
parents: 37807
diff changeset
   424
                ClassLoader         loader,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                String              classname,
11125
99b115114fa3 7117357: Warnings in sun.instrument, tools and other sun.* classes
alanb
parents: 5506
diff changeset
   426
                Class<?>            classBeingRedefined,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                ProtectionDomain    protectionDomain,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                byte[]              classfileBuffer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                boolean             isRetransformer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        TransformerManager mgr = isRetransformer?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                                        mRetransfomableTransformerManager :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                        mTransformerManager;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   433
        // module is null when not a class load or when loading a class in an
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   434
        // unnamed module and this is the first type to be loaded in the package.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   435
        if (module == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   436
            if (classBeingRedefined != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   437
                module = classBeingRedefined.getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   438
            } else {
37807
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents: 36511
diff changeset
   439
                module = (loader == null) ? jdk.internal.loader.BootLoader.getUnnamedModule()
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents: 36511
diff changeset
   440
                                          : loader.getUnnamedModule();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   441
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   442
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        if (mgr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            return null; // no manager, no transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        } else {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   446
            return mgr.transform(   module,
39739
5d058d6bd245 8159147: Add ClassLoader parameter to new ClassFileTransformer transform method
sspitsyn
parents: 37807
diff changeset
   447
                                    loader,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                                    classname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                                    classBeingRedefined,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                                    protectionDomain,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                                    classfileBuffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
}