Path: blob/master/test/jdk/com/sun/jdi/AnyDebuggeeTest.java
41149 views
/*1* Copyright (c) 2005, 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*25* @bug 622470026* @summary ReferenceType.nestedTypes() is too slow27* @author jjh28*29* @run build TestScaffold VMConnection TargetListener TargetAdapter30* @run compile -g AnyDebuggeeTest.java31* @run driver AnyDebuggeeeTest32*33* This test is intended to be run manually to investigate behaviors;34* it is not an actual test of any specific functionality, it just35* allows you to run the debugger part of this test on any debuggee.36* As set up, it prints the time to find all nested types and all37* subclasses in the debuggee, and so can be used to verify the38* fix for 6224700.39*40* For other investigations, edit this test to do whatever you want.41* To run this test do this:42* runregress -no AnyDebuggeeTest <cmd line options>43* where <cmd line options> are the options to be used to44* launch the debuggee, with the classname prefixed with @@.45* For example, this would run java2d demo as the debuggee:46* runregress -no AnyDebuggeeTest -classpath $jdkDir/demo/jfc/Java2D/Java2Demo.jar \47* -client @@java2d.Java2Demo'48* If <cmd line options> is not specified, then the AnyDebuggeeTarg class below49* is run as the debuggee.50*/51import com.sun.jdi.*;52import com.sun.jdi.event.*;53import com.sun.jdi.request.*;54import javax.swing.*;5556import java.util.*;5758class AnyDebuggeeTarg {59public static void main(String[] args){60System.out.println("Howdy!");61try {62javax.swing.UIManager.setLookAndFeel( javax.swing.UIManager.getSystemLookAndFeelClassName());63} catch( Throwable exc) {64}65JFrame f = new JFrame("JFrame");66try {67Thread.sleep(60000);68} catch (InterruptedException ee) {69}7071System.out.println("Goodbye from NestedClassesTarg!");72}73}7475/********** test program **********/7677public class AnyDebuggeeTest extends TestScaffold {78static String targetName = "AnyDebuggeeTarg";79ReferenceType targetClass;80ThreadReference mainThread;8182AnyDebuggeeTest(String args[]) {83super(args);84}8586public static void main(String[] args) throws Exception {87/*88* If args contains @@xxxx, then that is the89* name of the class we are to run.90*/91for (int ii = 0; ii < args.length; ii ++) {92if (args[ii].startsWith("@@")) {93targetName = args[ii] = args[ii].substring(2);94}95}96new AnyDebuggeeTest(args).startTests();97}9899100protected void runTests() throws Exception {101/*102* Get to the top of main()103* to determine targetClass and mainThread104*/105BreakpointEvent bpe;106bpe = startToMain(targetName);107108targetClass = bpe.location().declaringType();109mainThread = bpe.thread();110111// Let debuggee run for awhile to get classes loaded112resumeForMsecs(20000);113114List<ReferenceType> allClasses = vm().allClasses();115System.out.println( allClasses.size() + " classes");116117118int size = 0;119long start = System.currentTimeMillis();120for(ReferenceType rt: allClasses) {121if (rt instanceof ClassType) {122List<ReferenceType> nested = rt.nestedTypes();123int sz = nested.size();124size += sz;125}126}127long end = System.currentTimeMillis();128System.out.println(size + " nested types took " + (end - start) + " ms");129130size = 0;131start = System.currentTimeMillis();132for(ReferenceType rt: allClasses) {133if (rt instanceof ClassType) {134List<ClassType> subs = ((ClassType)rt).subclasses();135int sz = subs.size();136size += sz;137}138}139end = System.currentTimeMillis();140System.out.println(size + " subclasses took " + (end - start) + " ms");141142/*143* deal with results of test144* if anything has called failure("foo") testFailed will be true145*/146if (!testFailed) {147println("AnyDebuggeeTest: passed");148} else {149throw new Exception("AnyDebuggeeTest: failed");150}151}152}153154155