test/hotspot/jtreg/runtime/appcds/jvmti/dumpingWithAgent/DumpingWithJvmtiAgent.java
author ccheung
Fri, 16 Nov 2018 16:10:25 -0800
changeset 52596 dfa02b3f728c
permissions -rw-r--r--
8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping Summary: Allow Java agent during CDS dumping if the AllowArchivingWithJavaAgent dignostic option is specified. Reviewed-by: iklam, jiangli, sspitsyn, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52596
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     1
/*
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     4
 *
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     8
 *
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    13
 * accompanied this code).
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    14
 *
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    18
 *
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    21
 * questions.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    22
 */
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    23
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    24
/**
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    25
 * @test
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    26
 * @summary CDS dumping with JVMTI agent.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    27
 * @requires vm.cds
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    28
 * @requires vm.flavor != "minimal"
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    29
 * @library /test/lib /test/hotspot/jtreg/runtime/appcds
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    30
 * @modules jdk.jartool/sun.tools.jar
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    31
 * @compile ../../test-classes/Hello.java
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    32
 * @run main/othervm/native DumpingWithJvmtiAgent
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    33
 */
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    34
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    35
import java.io.File;
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    36
import java.nio.file.Path;
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    37
import java.nio.file.Paths;
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    38
import jdk.test.lib.process.OutputAnalyzer;
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    39
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    40
public class DumpingWithJvmtiAgent {
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    41
    private static final String AGENT_LIB_ONLOAD = "AddToSystemCLSearchOnLoad";
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    42
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    43
    public static void main(String[] args) throws Exception {
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    44
        String appJar = JarBuilder.getOrCreateHelloJar();
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    45
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    46
        // CDS dump with a JVMTI agent with the AllowArchivingWithJavaAgent option.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    47
        // vm should exit with an error message.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    48
        OutputAnalyzer out = TestCommon.dump(
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    49
           appJar,
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    50
           TestCommon.list("Hello"),
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    51
           "-XX:+UnlockDiagnosticVMOptions", "-XX:+AllowArchivingWithJavaAgent",
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    52
           "-agentlib:" + AGENT_LIB_ONLOAD + "=" + appJar,
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    53
           "-Djava.library.path=" + System.getProperty("java.library.path"));
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    54
        out.shouldContain("CDS dumping does not support native JVMTI agent, name: " + AGENT_LIB_ONLOAD)
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    55
           .shouldHaveExitValue(1);
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    56
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    57
        // CDS dump with a JVMTI agent without the AllowArchivingWithJavaAgent option.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    58
        // vm should exit with an error message.
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    59
        out = TestCommon.dump(
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    60
           appJar,
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    61
           TestCommon.list("Hello"),
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    62
           "-agentlib:" + AGENT_LIB_ONLOAD + "=" + appJar,
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    63
           "-Djava.library.path=" + System.getProperty("java.library.path"));
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    64
        out.shouldContain("CDS dumping does not support native JVMTI agent, name: " + AGENT_LIB_ONLOAD)
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    65
           .shouldHaveExitValue(1);
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    66
    }
dfa02b3f728c 8201375: Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
ccheung
parents:
diff changeset
    67
}