/*
* 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 4272800 4274208 4392010
* @summary Test debugger operations in finalize() methods
* @author Gordon Hirsch (modified for HotSpot by tbell & rfield)
*
* @run build TestScaffold VMConnection TargetListener TargetAdapter
* @run compile -g FinalizerTest.java
*
* @run main FinalizerTest
*/
/*
* Debuggee which exercises a finalize() method. There's no guarantee
* that this will work, but we need some way of attempting to test
* the debugging of finalizers.
* @author Gordon Hirsch (modified for HotSpot by tbell & rfield)
*/
class FinalizerTarg {
static boolean finalizerRun = false;
static class BigObject {
super();
}
/*
* JLS 2nd Ed. section 12.6 "Finalization of Class Instances" "[...]
* invoke the finalize method for its superclass, [...] usually good
* practice [...]"
*/
super.finalize();
//Thread.dumpStack();
finalizerRun = true;
}
}
static void waitForAFinalizer() {
b = null; // Drop the object, creating garbage...
// Now, we have to make sure the finalizer
// gets run. We will keep allocating more
// and more memory with the idea that eventually,
// the memory occupied by the BigObject will get reclaimed
// and the finalizer will be run.
if (finalizerRun) {
return;
}
try {
while(true) {
}
}
}
}
return; // not reached
}
/*
* Spin in waitForAFinalizer() while waiting for
* another thread to run the finalizer on one of the
* BigObjects ...
*/
}
}
///// End of debuggee
throws Exception {
}
super(args);
}
try {
"finalize", "()V");
println("Breakpoint at " +
/*
* Record information about the current location
*/
}
println("Try a stepOverLine()...");
println("Step Complete at " +
/*
* Compare current location with recorded location
*/
throw new Exception("Stack depths do not match: original=" +
methodStack.size() +
", current=" +
}
throw new Exception("Stacks do not match at: original=" +
}
}
testFailed = true;
} finally {
// Allow application to complete and shut down
}
if (!testFailed) {
println("FinalizerTest: passed");
} else {
throw new Exception("FinalizerTest: failed");
}
}
}