/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 5089849
* @summary Add support for backtracking reference graph.
* @author jjh
*
* @run build TestScaffold VMConnection TargetListener TargetAdapter
* @run compile -g ReferrersTest.java
* @run main ReferrersTest
*/
/*
* To run this test do this:
* runregress -no ReferrersTest <cmd line options>
*
* where <cmd line options> are the options to be used to
* launch the debuggee, with the classname prefixed with @@.
* For example, this would run java2d demo as the debuggee:
* runregress -no ReferrersTest -classpath
* $jdkDir/demo/jfc/Java2D/Java2Demo.jar \
* -client @@java2d.Java2Demo
*
* In this mode, the specified debuggee is launched in debug mode,
* and the debugger waits for a keystroke before connecting to the debuggee.
*
* If <cmd line options> is not specified, then the ReferrersTarg class below
* is run as the debuggee.
*/
class ReferrersFiller {
// This many instances of this are created.
int xx;
}
}
class ReferrersTarg {
// This many instances + 1 of this class are created.
// Each instance will point to the theReferrersTarg
public static void bkpt() {
}
}
theReferrersTarg = new ReferrersTarg();
}
bkpt();
}
}
/********** test program **********/
super(args);
}
/*
* If args contains @@xxxx, then that is the
* name of the class we are to run.
*/
break;
}
}
}
/*
* Used to sort a list of ReferenceTypes by
* instance count.
*/
long count;
}
return 1;
}
}
/*
* Get to the top of main()
* to determine targetClass and mainThread
*/
int CUT_OFF = 1000;
} else {
// Let debuggee run for awhile to get classes loaded
try {
} catch(Exception e) {
}
}
// Get all classes.
" classes from vm.allClasses() took " +
long[] counts;
// Test for NPE
{
boolean pass = false;
try {
} catch (NullPointerException ee) {
pass = true;
}
if (!pass) {
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
}
}
boolean pass = false;
try {
} catch (IllegalArgumentException ee) {
pass = true;
}
if (!pass) {
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
int size = 0;
}
boolean gotReferrersFiller = false;
boolean gotReferrersTarg = false;
gotReferrersFiller = true;
}
gotReferrersTarg = true;
}
}
if (!gotReferrersFiller) {
" instances of ReferrersFiller");
}
if (!gotReferrersTarg) {
" instances of ReferrersTarg");
}
// Instances, one class at a time, in sorted order, printing each line
if (true) {
"at a time (limited) in sorted order");
size = 0;
long count = 0;
break;
}
count++;
oneInstances.size() +
" instances of ReferrersFiller");
}
" instances of ReferrersTarg");
}
}
" call for each of " + count +
}
// referrers
// Test various values of maxReferrers
", for " + anInstance);
}
", for " + anInstance);
}
boolean pass = false;
try {
} catch (IllegalArgumentException ee) {
pass = true;
}
if (!pass) {
failure("failure: referringObjects(-1) did not get an exception");
}
}
" referrers for " + val);
}
} else {
// referrers
// Create someInstances to find the referrers of.
if (objRefList != null) {
if (false) {
}
// Remember one instance per class to get referrers
if (asize > 0) {
}
}
}
}
//System.out.println( "Getting referrers for " + objRef);
if ( true) {
} else {
System.out.println( allReferrers.size() + " referrers for " + objRef + " took " + (end - start) + " ms");
}
}
}
/*
* deal with results of test
* if anything has called failure("foo") testFailed will be true
*/
if (!testFailed) {
println("ReferrersTest: passed");
} else {
throw new Exception("ReferrersTest: failed");
}
}
}
}
if (level == 0) {
} else {
return;
}
//System.out.println(which + "/" + total + ": " + objRef + " took " + time + " ms");
}
//System.out.println( "Getting referrers for " + objRef);
if (which == 0) {
System.out.println(allReferrers.size() + " referrers for " + objRef + " took " + (end - start) + " ms");
} else {
System.out.println(" " + allReferrers.size() + " referrers for " + objRef + " took " + (end - start) + " ms");
}
// We have to stop going up a referrer chain in some cases
return;
}
return;
}
return;
}
// oh oh, should really check for a subclass of ClassLoader :-)
return;
}
// No doubt there are other reasons to stop ...
}
int itemNumber = 1;
}
}
}