/*
* 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 4026895
@summary Ensure that System.runFinalization does not run finalizers in the
thread that invokes it
*/
public class FinThreads {
static class Foo {
boolean catchFinalizer = false;
/* Instances are only created in an auxiliary thread, in order to
guard against stray references from the current thread's stack
*/
throws InterruptedException
{
public void run() {
new Foo(catchFinalizer);
}});
t.start();
t.join();
}
this.catchFinalizer = catchFinalizer;
}
if (catchFinalizer) {
boolean gotFinalizer = false;
synchronized (lock) {
if (finalizerThread == null) {
gotFinalizer = true;
}
}
if (gotFinalizer) {
}
} else {
synchronized (lock) {
}
}
}
}
throws InterruptedException
{
public void run() {
try {
} catch (InterruptedException x) { }
}});
t.setDaemon(true);
t.start();
}
/* Find the finalizer thread and put it to sleep */
for (;;) {
synchronized (lock) {
if (finalizerThread != null) break;
}
}
/* Now create a finalizable object and run finalization */
for (;;) {
synchronized (lock) {
if (finalizedBy != null) break;
}
}
if (finalizedBy == mainThread)
throw new Exception("Finalizer run in main thread");
}
}