test/hotspot/jtreg/runtime/appcds/test-classes/JvmtiApp.java
changeset 49739 00805b129186
parent 48138 78b2ecdd3c4b
equal deleted inserted replaced
49738:a7bc87a63dd8 49739:00805b129186
     1 /*
     1 /*
     2  * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    23  */
    23  */
    24 
    24 
    25 import sun.hotspot.WhiteBox;
    25 import sun.hotspot.WhiteBox;
    26 
    26 
    27 public class JvmtiApp {
    27 public class JvmtiApp {
    28     static Class forname() {
    28     static Class forname(String cn) {
    29         try {
    29         try {
    30             return Class.forName("Hello");
    30             return Class.forName(cn);
    31         } catch (Throwable t) {
    31         } catch (Throwable t) {
    32             return null;
    32             return null;
    33         }
    33         }
    34     }
    34     }
    35 
    35 
    38         System.exit(1);
    38         System.exit(1);
    39     }
    39     }
    40 
    40 
    41     // See ../JvmtiAddPath.java for how the classpaths are configured.
    41     // See ../JvmtiAddPath.java for how the classpaths are configured.
    42     public static void main(String args[]) {
    42     public static void main(String args[]) {
       
    43         String cn = "Hello";
       
    44         if (args.length >= 3) {
       
    45             cn = args[args.length - 1];
       
    46         }
       
    47 
    43         if (args[0].equals("noadd")) {
    48         if (args[0].equals("noadd")) {
    44             if (forname() != null) {
    49             if (forname(cn) != null) {
    45                 failed("Hello class was loaded unexpectedly");
    50                 failed(cn + " class was loaded unexpectedly");
    46             }
    51             }
    47             // We use -verbose:class to verify that Extra.class IS loaded by AppCDS if
    52             // We use -verbose:class to verify that Extra.class IS loaded by AppCDS if
    48             // the boot classpath HAS NOT been appended.
    53             // the boot classpath HAS NOT been appended.
    49             ExtraClass.doit();
    54             ExtraClass.doit();
    50             System.exit(0);
    55             System.exit(0);
    52 
    57 
    53         WhiteBox wb = WhiteBox.getWhiteBox();
    58         WhiteBox wb = WhiteBox.getWhiteBox();
    54 
    59 
    55         if (args[0].equals("bootonly")) {
    60         if (args[0].equals("bootonly")) {
    56             wb.addToBootstrapClassLoaderSearch(args[1]);
    61             wb.addToBootstrapClassLoaderSearch(args[1]);
    57             Class cls = forname();
    62             Class cls = forname(cn);
    58             if (cls == null) {
    63             if (cls == null) {
    59                 failed("Cannot find Hello class");
    64                 failed("Cannot find " + cn + " class");
    60             }
    65             }
    61             if (cls.getClassLoader() != null) {
    66             if (cls.getClassLoader() != null) {
    62                 failed("Hello class not loaded by boot classloader");
    67                 failed("Hello class not loaded by boot classloader");
    63             }
    68             }
    64         } else if (args[0].equals("apponly")) {
    69         } else if (args[0].equals("apponly")) {
    65             wb.addToSystemClassLoaderSearch(args[1]);
    70             wb.addToSystemClassLoaderSearch(args[1]);
    66             Class cls = forname();
    71             Class cls = forname(cn);
    67             if (cls == null) {
    72             if (cls == null) {
    68                 failed("Cannot find Hello class");
    73                 failed("Cannot find " + cn + " class");
    69             }
    74             }
    70             if (cls.getClassLoader() != JvmtiApp.class.getClassLoader()) {
    75             if (cls.getClassLoader() != JvmtiApp.class.getClassLoader()) {
    71                 failed("Hello class not loaded by app classloader");
    76                 failed(cn + " class not loaded by app classloader");
    72             }
    77             }
    73         } else if (args[0].equals("noadd-appcds")) {
    78         } else if (args[0].equals("noadd-appcds")) {
    74             Class cls = forname();
    79             cn = (args.length == 1) ? "Hello" : args[1];
       
    80             Class cls = forname(cn);
    75             if (cls == null) {
    81             if (cls == null) {
    76                 failed("Cannot find Hello class");
    82                 failed("Cannot find " + cn + " class");
    77             }
    83             }
    78             if (cls.getClassLoader() != JvmtiApp.class.getClassLoader()) {
    84             if (cls.getClassLoader() != JvmtiApp.class.getClassLoader()) {
    79                 failed("Hello class not loaded by app classloader");
    85                 failed(cn + " class not loaded by app classloader");
    80             }
    86             }
    81         } else if (args[0].equals("appandboot")) {
    87         } else if (args[0].equals("appandboot")) {
    82             wb.addToBootstrapClassLoaderSearch(args[1]);
    88             wb.addToBootstrapClassLoaderSearch(args[1]);
    83             wb.addToSystemClassLoaderSearch(args[2]);
    89             wb.addToSystemClassLoaderSearch(args[2]);
    84             Class cls = forname();
    90             cn = (args.length == 3) ? "Hello" : args[3];
       
    91             Class cls = forname(cn);
    85             if (cls == null) {
    92             if (cls == null) {
    86                 failed("Cannot find Hello class");
    93                 failed("Cannot find " + cn + " class");
    87             }
    94             }
    88             if (cls.getClassLoader() != null) {
    95             if (cls.getClassLoader() != null) {
    89                 failed("Hello class not loaded by boot classloader");
    96                 failed(cn + " class not loaded by boot classloader");
    90             }
    97             }
    91         } else {
    98         } else {
    92             failed("unknown option " + args[0]);
    99             failed("unknown option " + args[0]);
    93         }
   100         }
    94 
   101