Path: blob/master/test/jdk/com/sun/jdi/ClassLoaderClassesTest.java
41149 views
/*1* Copyright (c) 2001, 2015, 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* @author Robert Field30*31* @run build TestScaffold VMConnection TargetListener TargetAdapter32* @run compile -g ClassLoaderClassesTest.java33* @run driver ClassLoaderClassesTest34*/35import com.sun.jdi.*;36import com.sun.jdi.event.*;37import com.sun.jdi.request.*;3839import java.util.*;4041/********** target program **********/4243class ClassLoaderClassesTarg {44static int[] intArray = new int[10];4546static {47// make sure our class loader "creates" int[] before tested48intArray[1] = 99;49}5051public static void main(String[] args){52System.out.println("Goodbye from ClassLoaderClassesTarg!");53}54}5556/********** test program **********/5758public class ClassLoaderClassesTest extends TestScaffold {59ReferenceType targetClass;6061ClassLoaderClassesTest (String args[]) {62super(args);63}6465public static void main(String[] args) throws Exception {66new ClassLoaderClassesTest(args).startTests();67}6869/********** test assist **********/7071boolean findClass(String className) throws Exception {72ClassLoaderReference cl = targetClass.classLoader();73Iterator vci = cl.visibleClasses().iterator();74while (vci.hasNext()) {75ReferenceType rt = (ReferenceType)vci.next();76println(rt.name() + " - " + rt.classLoader());77if (rt.name().equals(className)) {78return true;79}80}81return false;82}8384/********** test core **********/8586protected void runTests() throws Exception {87/*88* Get to the top of main() to determine targetClass89*/90BreakpointEvent bpe = startToMain("ClassLoaderClassesTarg");91targetClass = bpe.location().declaringType();9293if (findClass("int[]")) {94println("int[] found");95} else {96failure("failed - int[] not found");97}9899// use it indirectly - throws ClassNotLoadedException on error100Field arrayField = targetClass.fieldByName("intArray");101ArrayType arrayType = (ArrayType)arrayField.type();102println("Type for intArray is " + arrayType);103104/*105* resume the target until end106*/107listenUntilVMDisconnect();108109/*110* deal with results of test111* if anything has called failure("foo") testFailed will be true112*/113if (!testFailed) {114println("ClassLoaderClassesTest: passed");115} else {116throw new Exception("ClassLoaderClassesTest: failed");117}118}119}120121122