Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/ClassLoaderClassesTest.java
38854 views
/*1* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 445009126* @summary Test ClassLoaderReference.visibleClasses() which is27* a direct pass-through of the JVMDI function GetClassLoaderClasses28* for inclusion of primitive arrays.29*30* @author Robert Field31*32* @run build TestScaffold VMConnection TargetListener TargetAdapter33* @run compile -g ClassLoaderClassesTest.java34* @run main ClassLoaderClassesTest35*/36import com.sun.jdi.*;37import com.sun.jdi.event.*;38import com.sun.jdi.request.*;3940import java.util.*;4142/********** target program **********/4344class ClassLoaderClassesTarg {45static int[] intArray = new int[10];4647static {48// make sure our class loader "creates" int[] before tested49intArray[1] = 99;50}5152public static void main(String[] args){53System.out.println("Goodbye from ClassLoaderClassesTarg!");54}55}5657/********** test program **********/5859public class ClassLoaderClassesTest extends TestScaffold {60ReferenceType targetClass;6162ClassLoaderClassesTest (String args[]) {63super(args);64}6566public static void main(String[] args) throws Exception {67new ClassLoaderClassesTest(args).startTests();68}6970/********** test assist **********/7172boolean findClass(String className) throws Exception {73ClassLoaderReference cl = targetClass.classLoader();74Iterator vci = cl.visibleClasses().iterator();75while (vci.hasNext()) {76ReferenceType rt = (ReferenceType)vci.next();77println(rt.name() + " - " + rt.classLoader());78if (rt.name().equals(className)) {79return true;80}81}82return false;83}8485/********** test core **********/8687protected void runTests() throws Exception {88/*89* Get to the top of main() to determine targetClass90*/91BreakpointEvent bpe = startToMain("ClassLoaderClassesTarg");92targetClass = bpe.location().declaringType();9394if (findClass("int[]")) {95println("int[] found");96} else {97failure("failed - int[] not found");98}99100// use it indirectly - throws ClassNotLoadedException on error101Field arrayField = targetClass.fieldByName("intArray");102ArrayType arrayType = (ArrayType)arrayField.type();103println("Type for intArray is " + arrayType);104105/*106* resume the target until end107*/108listenUntilVMDisconnect();109110/*111* deal with results of test112* if anything has called failure("foo") testFailed will be true113*/114if (!testFailed) {115println("ClassLoaderClassesTest: passed");116} else {117throw new Exception("ClassLoaderClassesTest: failed");118}119}120}121122123