1/* 2 * Copyright (c) 2005, 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 * 26 * @bug 6224700 27 * @summary ReferenceType.nestedTypes() is too slow 28 * @author jjh 29 * 30 * @run build TestScaffold VMConnection TargetListener TargetAdapter 31 * @run compile -g AnyDebuggeeTest.java 32 * @run driver AnyDebuggeeeTest 33 * 34 * This test is intended to be run manually to investigate behaviors; 35 * it is not an actual test of any specific functionality, it just 36 * allows you to run the debugger part of this test on any debuggee. 37 * As set up, it prints the time to find all nested types and all 38 * subclasses in the debuggee, and so can be used to verify the 39 * fix for 6224700. 40 * 41 * For other investigations, edit this test to do whatever you want. 42 * To run this test do this: 43 * runregress -no AnyDebuggeeTest <cmd line options> 44 * where <cmd line options> are the options to be used to 45 * launch the debuggee, with the classname prefixed with @@. 46 * For example, this would run java2d demo as the debuggee: 47 * runregress -no AnyDebuggeeTest -classpath $jdkDir/demo/jfc/Java2D/Java2Demo.jar \ 48 * -client @@java2d.Java2Demo' 49 * If <cmd line options> is not specified, then the AnyDebuggeeTarg class below 50 * is run as the debuggee. 51 */ 52import com.sun.jdi.*; 53import com.sun.jdi.event.*; 54import com.sun.jdi.request.*; 55import javax.swing.*; 56 57import java.util.*; 58 59class AnyDebuggeeTarg { 60 public static void main(String[] args){ 61 System.out.println("Howdy!"); 62 try { 63 javax.swing.UIManager.setLookAndFeel( javax.swing.UIManager.getSystemLookAndFeelClassName()); 64 } catch( Throwable exc) { 65 } 66 JFrame f = new JFrame("JFrame"); 67 try { 68 Thread.sleep(60000); 69 } catch (InterruptedException ee) { 70 } 71 72 System.out.println("Goodbye from NestedClassesTarg!"); 73 } 74} 75 76 /********** test program **********/ 77 78public class AnyDebuggeeTest extends TestScaffold { 79 static String targetName = "AnyDebuggeeTarg"; 80 ReferenceType targetClass; 81 ThreadReference mainThread; 82 83 AnyDebuggeeTest(String args[]) { 84 super(args); 85 } 86 87 public static void main(String[] args) throws Exception { 88 /* 89 * If args contains @@xxxx, then that is the 90 * name of the class we are to run. 91 */ 92 for (int ii = 0; ii < args.length; ii ++) { 93 if (args[ii].startsWith("@@")) { 94 targetName = args[ii] = args[ii].substring(2); 95 } 96 } 97 new AnyDebuggeeTest(args).startTests(); 98 } 99 100 101 protected void runTests() throws Exception { 102 /* 103 * Get to the top of main() 104 * to determine targetClass and mainThread 105 */ 106 BreakpointEvent bpe; 107 bpe = startToMain(targetName); 108 109 targetClass = bpe.location().declaringType(); 110 mainThread = bpe.thread(); 111 112 // Let debuggee run for awhile to get classes loaded 113 resumeForMsecs(20000); 114 115 List<ReferenceType> allClasses = vm().allClasses(); 116 System.out.println( allClasses.size() + " classes"); 117 118 119 int size = 0; 120 long start = System.currentTimeMillis(); 121 for(ReferenceType rt: allClasses) { 122 if (rt instanceof ClassType) { 123 List<ReferenceType> nested = rt.nestedTypes(); 124 int sz = nested.size(); 125 size += sz; 126 } 127 } 128 long end = System.currentTimeMillis(); 129 System.out.println(size + " nested types took " + (end - start) + " ms"); 130 131 size = 0; 132 start = System.currentTimeMillis(); 133 for(ReferenceType rt: allClasses) { 134 if (rt instanceof ClassType) { 135 List<ClassType> subs = ((ClassType)rt).subclasses(); 136 int sz = subs.size(); 137 size += sz; 138 } 139 } 140 end = System.currentTimeMillis(); 141 System.out.println(size + " subclasses took " + (end - start) + " ms"); 142 143 /* 144 * deal with results of test 145 * if anything has called failure("foo") testFailed will be true 146 */ 147 if (!testFailed) { 148 println("AnyDebuggeeTest: passed"); 149 } else { 150 throw new Exception("AnyDebuggeeTest: failed"); 151 } 152 } 153} 154