ReferrersTest.java revision 2362
479N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. 479N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 479N/A * This code is free software; you can redistribute it and/or modify it 479N/A * under the terms of the GNU General Public License version 2 only, as 479N/A * published by the Free Software Foundation. 479N/A * This code is distributed in the hope that it will be useful, but WITHOUT 479N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 479N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 479N/A * version 2 for more details (a copy is included in the LICENSE file that 479N/A * accompanied this code). 479N/A * You should have received a copy of the GNU General Public License version 479N/A * 2 along with this work; if not, write to the Free Software Foundation, 479N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 479N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 479N/A * or visit www.oracle.com if you need additional information or have any 479N/A * @summary Add support for backtracking reference graph. 479N/A * @run build TestScaffold VMConnection TargetListener TargetAdapter 479N/A * @run main ReferrersTest 479N/A * To run this test do this: 479N/A * runregress -no ReferrersTest <cmd line options> 479N/A * where <cmd line options> are the options to be used to 479N/A * launch the debuggee, with the classname prefixed with @@. 479N/A * For example, this would run java2d demo as the debuggee: 479N/A * runregress -no ReferrersTest -classpath 479N/A * In this mode, the specified debuggee is launched in debug mode, 479N/A * and the debugger waits for a keystroke before connecting to the debuggee. 479N/A * If <cmd line options> is not specified, then the ReferrersTarg class below 479N/A * is run as the debuggee. 479N/A // This many instances of this are created. 479N/A // This many instances + 1 of this class are created. 479N/A // Each instance will point to the theReferrersTarg 479N/A/********** test program **********/ 479N/A * If args contains @@xxxx, then that is the 479N/A * name of the class we are to run. * Used to sort a list of ReferenceTypes by * Get to the top of main() * to determine targetClass and mainThread resumeTo(
"ReferrersTarg",
"bkpt",
"()V");
// Let debuggee run for awhile to get classes loaded " classes from vm.allClasses() took " +
failure(
"failure: NullPointerException not thrown on instanceCounts(null)");
// Test for 0 length array failure(
"failure: instanceCounts with a zero length array fails: " +
// Test various values of maxInstances failure(
"failure: instances(-1) did not get an exception");
// Instance counts for all classes throw new Exception(
"ReferrersTest: failed");
// Create a list of ReferenceTypes sorted by instance count " classes got " +
size +
" instances and took " +
" instances of ReferrersFiller");
" instances of ReferrersTarg");
// Instances, one class at a time, in sorted order, printing each line "at a time (limited) in sorted order");
" instances of ReferrersFiller");
" instances of ReferrersTarg");
" call for each of " +
count +
// Test various values of maxReferrers failure(
"failure: referringObjects(-1) did not get an exception");
" referrers for " +
val);
// Create someInstances to find the referrers of. // Remember one instance per class to get referrers //System.out.println( "Getting referrers for " + objRef); * deal with results of test * if anything has called failure("foo") testFailed will be true throw new Exception(
"ReferrersTest: failed");
//System.out.println(which + "/" + total + ": " + objRef + " took " + time + " ms"); //System.out.println( "Getting referrers for " + objRef); // We have to stop going up a referrer chain in some cases if (
name.
equals(
"sun.misc.SoftCache$ValueCell")) {
// oh oh, should really check for a subclass of ClassLoader :-) // No doubt there are other reasons to stop ...