test/hotspot/jtreg/runtime/cds/appcds/javaldr/AnonVmClassesDuringDumpTransformer.java
author jiefu
Wed, 06 Nov 2019 13:43:25 +0800
changeset 58944 bb2a436e616c
parent 57567 b000362a89a0
permissions -rw-r--r--
8233659: [TESTBUG] runtime/cds/appcds/CommandLineFlagCombo.java fails when jfr is disabled Reviewed-by: iklam
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49352
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     1
/*
57567
b000362a89a0 8202339: [TESTBUG] Consolidate the tests in runtime/SharedArchiveFile and runtime/appcds
coleenp
parents: 49352
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
49352
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     4
 *
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     8
 *
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    13
 * accompanied this code).
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    14
 *
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    18
 *
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    21
 * questions.
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    22
 *
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    23
 */
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    24
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    25
import java.lang.instrument.ClassFileTransformer;
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    26
import java.lang.instrument.Instrumentation;
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    27
import java.lang.instrument.IllegalClassFormatException;
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    28
import java.security.ProtectionDomain;
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    29
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    30
public class AnonVmClassesDuringDumpTransformer implements ClassFileTransformer {
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    31
    public byte[] transform(ClassLoader loader, String name, Class<?> classBeingRedefined,
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    32
                            ProtectionDomain pd, byte[] buffer) throws IllegalClassFormatException {
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    33
        return null;
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    34
    }
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    35
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    36
    private static Instrumentation savedInstrumentation;
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    37
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    38
    public static void premain(String agentArguments, Instrumentation instrumentation) {
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    39
        System.out.println("ClassFileTransformer.premain() is called");
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    40
        instrumentation.addTransformer(new AnonVmClassesDuringDumpTransformer(), /*canRetransform=*/true);
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    41
        savedInstrumentation = instrumentation;
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    42
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    43
        // This will create a Lambda, which will result in some Anonymous VM Classes
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    44
        // being generated.
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    45
        //
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    46
        // Look for something like these in the STDOUT:
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    47
        // ----------------
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    48
        // ClassFileTransformer.premain() is called
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    49
        // Dumping class files to DUMP_CLASS_FILES/...
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    50
        // dump: DUMP_CLASS_FILES/java/lang/invoke/LambdaForm$MH000.class
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    51
        // dump: DUMP_CLASS_FILES/java/lang/invoke/LambdaForm$MH001.class
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    52
        // Invoked inside a Lambda
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    53
        // ----------------
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    54
        Runnable r = () -> {
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    55
            System.out.println("Invoked inside a Lambda");
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    56
        };
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    57
        r.run();
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    58
    }
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    59
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    60
    public static Instrumentation getInstrumentation() {
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    61
        return savedInstrumentation;
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    62
    }
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    63
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    64
    public static void agentmain(String args, Instrumentation inst) throws Exception {
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    65
        premain(args, inst);
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    66
    }
0b48f0aa79ec 8191585: VM anonymous classes created during CDS dump time cause crash
iklam
parents:
diff changeset
    67
}