Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/ClassesByName2Test.java
38855 views
/*1* Copyright (c) 2001, 2008, 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 4406439 492574026* @summary ClassesByName2 verifies that all the classes in the loaded class list can be found with classesByName..27*28* @author Tim Bell (based on ClassesByName by Robert Field)29*30* @run build TestScaffold VMConnection TargetListener TargetAdapter31* @run compile -g ClassesByName2Test.java32* @run main ClassesByName2Test33*/34import com.sun.jdi.*;35import com.sun.jdi.event.*;36import com.sun.jdi.request.*;3738import java.util.*;3940/********** target program **********/4142class ClassesByName2Targ {43static void bkpt() {44}4546public static void main(String[] args){47System.out.println("Howdy!");48try {4950Thread zero = new Thread ("ZERO") {51public void run () {52System.setProperty("java.awt.headless", "true");53java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit();5455}56};5758Thread one = new Thread ("ONE") {59public void run () {60try {61java.security.KeyPairGenerator keyGen =62java.security.KeyPairGenerator.getInstance("DSA", "SUN");63} catch (Exception e) {64e.printStackTrace();65}66}67};6869Thread two = new Thread ("TWO") {70public void run () {71javax.rmi.CORBA.Util.getCodebase(this.getClass());72}73};7475two.start();76one.start();77zero.start();7879try {80zero.join();81System.out.println("zero joined");82one.join();83System.out.println("one joined");84two.join();85System.out.println("two joined");86} catch (InterruptedException iex) {87iex.printStackTrace();88}89} catch (Exception e) {90e.printStackTrace();91}92bkpt();93System.out.println("Goodbye from ClassesByName2Targ!");94}95}9697/********** test program **********/9899public class ClassesByName2Test extends TestScaffold {100volatile boolean stop = false;101102ClassesByName2Test (String args[]) {103super(args);104}105106public void breakpointReached(BreakpointEvent event) {107System.out.println("Got BreakpointEvent: " + event);108stop = true;109}110111public void eventSetComplete(EventSet set) {112// Don't resume.113}114115public static void main(String[] args) throws Exception {116new ClassesByName2Test(args).startTests();117}118119void breakpointAtMethod(ReferenceType ref, String methodName)120throws Exception {121List meths = ref.methodsByName(methodName);122if (meths.size() != 1) {123throw new Exception("test error: should be one " +124methodName);125}126Method meth = (Method)meths.get(0);127BreakpointRequest bkptReq = vm().eventRequestManager().128createBreakpointRequest(meth.location());129bkptReq.enable();130try {131addListener (this);132} catch (Exception ex){133ex.printStackTrace();134failure("failure: Could not add listener");135throw new Exception("ClassesByname2Test: failed");136}137}138139protected void runTests() throws Exception {140BreakpointEvent bpe = startToMain("ClassesByName2Targ");141142/*143Bug 6263966 - Don't just resume because the debuggee can144complete and disconnect while the following loop is145accessing it.146*/147breakpointAtMethod(bpe.location().declaringType(), "bkpt");148vm().resume();149150/* The test of 'stop' is so that we stop when the debuggee hits151the bkpt. The 150 is so we stop if the debuggee152is slow (eg, -Xcomp -server) - we don't want to153spend all day waiting for it to get to the bkpt.154*/155for (int i = 0; i < 150 && !stop; i++) {156List all = vm().allClasses();157System.out.println("\n++++ Lookup number: " + i + ". allClasses() returned " +158all.size() + " classes.");159for (Iterator it = all.iterator(); it.hasNext(); ) {160ReferenceType cls = (ReferenceType)it.next();161String name = cls.name();162List found = vm().classesByName(name);163if (found.contains(cls)) {164//System.out.println("Found class: " + name);165} else {166System.out.println("CLASS NOT FOUND: " + name);167throw new Exception("CLASS NOT FOUND (by classesByName): " +168name);169}170}171}172173// In case of a slow debuggee, we don't want to resume the debuggee and wait174// for it to complete.175vm().exit(0);176177/*178* deal with results of test179* if anything has called failure("foo") testFailed will be true180*/181if (!testFailed) {182println("ClassesByName2Test: passed");183} else {184throw new Exception("ClassesByName2Test: failed");185}186}187}188189190