1 /* 2 * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 import sun.hotspot.WhiteBox; 26 27 public class JvmtiApp { 28 static Class forname() { 29 try { 30 return Class.forName("Hello"); 31 } catch (Throwable t) { 32 return null; 33 } 34 } 35 36 static void failed(String msg) { 37 System.out.println("TEST FAILED: " + msg); 38 System.exit(1); 39 } 40 41 // See ../JvmtiAddPath.java for how the classpaths are configured. 42 public static void main(String args[]) { 43 if (args[0].equals("noadd")) { 44 if (forname() != null) { 45 failed("Hello class was loaded unexpectedly"); 46 } 47 // We use -verbose:class to verify that Extra.class IS loaded by AppCDS if 48 // the boot classpath HAS NOT been appended. 49 ExtraClass.doit(); 50 System.exit(0); 51 } 52 53 WhiteBox wb = WhiteBox.getWhiteBox(); 54 55 if (args[0].equals("bootonly")) { 56 wb.addToBootstrapClassLoaderSearch(args[1]); 57 Class cls = forname(); 58 if (cls == null) { 59 failed("Cannot find Hello class"); 60 } 61 if (cls.getClassLoader() != null) { 62 failed("Hello class not loaded by boot classloader"); 63 } 64 } else if (args[0].equals("apponly")) { 65 wb.addToSystemClassLoaderSearch(args[1]); 66 Class cls = forname(); 67 if (cls == null) { 68 failed("Cannot find Hello class"); 69 } 70 if (cls.getClassLoader() != JvmtiApp.class.getClassLoader()) { 71 failed("Hello class not loaded by app classloader"); 72 } 73 } else if (args[0].equals("noadd-appcds")) { 74 Class cls = forname(); 75 if (cls == null) { 76 failed("Cannot find Hello class"); 77 } 78 if (cls.getClassLoader() != JvmtiApp.class.getClassLoader()) { 79 failed("Hello class not loaded by app classloader"); 80 } 81 } else if (args[0].equals("appandboot")) { 82 wb.addToBootstrapClassLoaderSearch(args[1]); 83 wb.addToSystemClassLoaderSearch(args[2]); 84 Class cls = forname(); 85 if (cls == null) { 86 failed("Cannot find Hello class"); 87 } 88 if (cls.getClassLoader() != null) { 89 failed("Hello class not loaded by boot classloader"); 90 } 91 } else { 92 failed("unknown option " + args[0]); 93 } 94 95 // We use -verbose:class to verify that Extra.class IS NOT loaded by AppCDS if 96 // the boot classpath HAS been appended. 97 ExtraClass.doit(); 98 99 System.out.println("Test passed: " + args[0]); 100 } 101 } 102 103 class ExtraClass { 104 static void doit() {} 105 }