jdk/test/java/lang/instrument/BootstrapClassPathAgent.java
author alanb
Fri, 07 Apr 2017 08:05:54 +0000
changeset 44545 83b611b88ac8
parent 37807 78e5cb21ca13
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37807
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
     1
/*
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
     4
 *
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
     8
 *
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    13
 * accompanied this code).
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    14
 *
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    18
 *
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    21
 * questions.
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    22
 */
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    23
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    24
package p;
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    25
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    26
import java.io.*;
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    27
import java.lang.instrument.ClassFileTransformer;
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    28
import java.lang.instrument.Instrumentation;
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    29
import java.security.ProtectionDomain;
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    30
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    31
public class BootstrapClassPathAgent {
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    32
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    33
    public static void premain(String args, Instrumentation inst) {
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    34
        System.out.println("agent loader=" + BootstrapClassPathAgent.class.getClassLoader());
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    35
        inst.addTransformer(new MyTransformer());
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    36
    }
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    37
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    38
    static class MyTransformer implements ClassFileTransformer {
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    39
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    40
        public byte[] transform(Module module,
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    41
                                String className,
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    42
                                Class<?> classBeingRedefined,
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    43
                                ProtectionDomain    protectionDomain,
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    44
                                byte[] classfileBuffer) {
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    45
            System.out.println(className + ", module=" + module);
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    46
            return null;
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    47
        }
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    48
    }
78e5cb21ca13 8156147: NPE in InstrumentationImpl.transform when loading classes from -Xbootclasspath/a
sspitsyn
parents:
diff changeset
    49
}