--- a/jdk/src/java.base/share/classes/java/lang/ref/Finalizer.java Thu Aug 06 12:35:59 2015 -0700
+++ b/jdk/src/java.base/share/classes/java/lang/ref/Finalizer.java Thu Aug 06 13:00:45 2015 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -83,6 +83,10 @@
add();
}
+ static ReferenceQueue<Object> getQueue() {
+ return queue;
+ }
+
/* Invoked by VM */
static void register(Object finalizee) {
new Finalizer(finalizee);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/ref/FinalizerHistogram.java Thu Aug 06 13:00:45 2015 -0700
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+
+package java.lang.ref;
+
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Arrays;
+import java.util.Comparator;
+
+/**
+ * This FinalizerHistogram class is for GC.finalizer_info diagnostic command support.
+ * It is invoked by the VM.
+ */
+
+final class FinalizerHistogram {
+
+ private static final class Entry {
+ private int instanceCount;
+ private final String className;
+
+ int getInstanceCount() {
+ return instanceCount;
+ }
+
+ void increment() {
+ instanceCount += 1;
+ }
+
+ Entry(String className) {
+ this.className = className;
+ }
+ }
+
+ // Method below is called by VM and VM expect certain
+ // entry class layout.
+
+ static Entry[] getFinalizerHistogram() {
+ Map<String, Entry> countMap = new HashMap<>();
+ ReferenceQueue<Object> queue = Finalizer.getQueue();
+ queue.forEach(r -> {
+ Object referent = r.get();
+ if (referent != null) {
+ countMap.computeIfAbsent(
+ referent.getClass().getName(), Entry::new).increment();
+ /* Clear stack slot containing this variable, to decrease
+ the chances of false retention with a conservative GC */
+ referent = null;
+ }
+ });
+
+ Entry fhe[] = countMap.values().toArray(new Entry[countMap.size()]);
+ Arrays.sort(fhe,
+ Comparator.comparingInt(Entry::getInstanceCount).reversed());
+ return fhe;
+ }
+}
--- a/jdk/src/java.base/share/classes/java/lang/ref/Reference.java Thu Aug 06 12:35:59 2015 -0700
+++ b/jdk/src/java.base/share/classes/java/lang/ref/Reference.java Thu Aug 06 13:00:45 2015 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -101,7 +101,7 @@
* Inactive: this
*/
@SuppressWarnings("rawtypes")
- Reference next;
+ volatile Reference next;
/* When active: next element in a discovered reference list maintained by GC (or this if last)
* pending: next element in the pending list (or null if last)
--- a/jdk/src/java.base/share/classes/java/lang/ref/ReferenceQueue.java Thu Aug 06 12:35:59 2015 -0700
+++ b/jdk/src/java.base/share/classes/java/lang/ref/ReferenceQueue.java Thu Aug 06 13:00:45 2015 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
package java.lang.ref;
+import java.util.function.Consumer;
+
/**
* Reference queues, to which registered reference objects are appended by the
* garbage collector after the appropriate reachability changes are detected.
@@ -75,13 +77,12 @@
}
}
- @SuppressWarnings("unchecked")
private Reference<? extends T> reallyPoll() { /* Must hold lock */
Reference<? extends T> r = head;
if (r != null) {
- head = (r.next == r) ?
- null :
- r.next; // Unchecked due to the next field having a raw type in Reference
+ @SuppressWarnings("unchecked")
+ Reference<? extends T> rn = r.next;
+ head = (rn == r) ? null : rn;
r.queue = NULL;
r.next = r;
queueLength--;
@@ -164,4 +165,32 @@
return remove(0);
}
+ /**
+ * Iterate queue and invoke given action with each Reference.
+ * Suitable for diagnostic purposes.
+ * WARNING: any use of this method should make sure to not
+ * retain the referents of iterated references (in case of
+ * FinalReference(s)) so that their life is not prolonged more
+ * than necessary.
+ */
+ void forEach(Consumer<? super Reference<? extends T>> action) {
+ for (Reference<? extends T> r = head; r != null;) {
+ action.accept(r);
+ @SuppressWarnings("unchecked")
+ Reference<? extends T> rn = r.next;
+ if (rn == r) {
+ if (r.queue == ENQUEUED) {
+ // still enqueued -> we reached end of chain
+ r = null;
+ } else {
+ // already dequeued: r.queue == NULL; ->
+ // restart from head when overtaken by queue poller(s)
+ r = head;
+ }
+ } else {
+ // next in chain
+ r = rn;
+ }
+ }
+ }
}
--- a/jdk/src/java.management/share/classes/com/sun/jmx/mbeanserver/Introspector.java Thu Aug 06 12:35:59 2015 -0700
+++ b/jdk/src/java.management/share/classes/com/sun/jmx/mbeanserver/Introspector.java Thu Aug 06 13:00:45 2015 -0700
@@ -552,8 +552,10 @@
// Java Beans introspection
//
Class<?> clazz = complex.getClass();
- Method readMethod = JavaBeansAccessor.getReadMethod(clazz, element);
- if (readMethod == null) {
+ Method readMethod;
+ if (JavaBeansAccessor.isAvailable()) {
+ readMethod = JavaBeansAccessor.getReadMethod(clazz, element);
+ } else {
// Java Beans not available so use simple introspection
// to locate method
readMethod = SimpleIntrospector.getReadMethod(clazz, element);
@@ -676,7 +678,12 @@
* {@code null} if no method is found.
*/
static Method getReadMethod(Class<?> clazz, String property) {
- // first character in uppercase (compatibility with JavaBeans)
+ if (Character.isUpperCase(property.charAt(0))) {
+ // the property name must start with a lower-case letter
+ return null;
+ }
+ // first character after 'get/is' prefix must be in uppercase
+ // (compatibility with JavaBeans)
property = property.substring(0, 1).toUpperCase(Locale.ENGLISH) +
property.substring(1);
String getMethod = GET_METHOD_PREFIX + property;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/com/sun/jmx/mbeanserver/introspector/BeanClass.java Thu Aug 06 13:00:45 2015 -0700
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+public class BeanClass {
+ public int getNumber() {return 1;}
+ public boolean isAvailable() {return false;}
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/com/sun/jmx/mbeanserver/introspector/SimpleIntrospectorTest.java Thu Aug 06 13:00:45 2015 -0700
@@ -0,0 +1,104 @@
+
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+import java.lang.reflect.Method;
+
+/*
+ * @test
+ * @bug 8129215
+ * @summary The test checks whether the SimpleIntrospector is honoring the
+ * the JavaBeans property naming convention of always starting
+ * with a lower-case letter
+ *
+ * @author Jaroslav Bachorik
+ * @modules java.management
+ * @run clean SimpleIntrospectorTest
+ * @run build SimpleIntrospectorTest BeanClass
+ * @run main SimpleIntrospectorTest
+ */
+public class SimpleIntrospectorTest {
+ private static Method INTROSPECT_GETTER;
+
+ public static void main(String ... args) throws Exception {
+ Class clz = Class.forName(
+ "com.sun.jmx.mbeanserver.Introspector$SimpleIntrospector"
+ );
+ INTROSPECT_GETTER = clz.getDeclaredMethod(
+ "getReadMethod",
+ Class.class,
+ String.class
+ );
+ INTROSPECT_GETTER.setAccessible(true);
+ boolean result = true;
+ result &= checkNumberValid();
+ result &= checkNumberInvalid();
+ result &= checkAvailableValid();
+ result &= checkAvailableInvalid();
+
+ if (!result) {
+ throw new Error();
+ }
+ }
+
+ private static boolean checkNumberValid() throws Exception {
+ return checkGetter(false, "number");
+ }
+
+ private static boolean checkNumberInvalid() throws Exception {
+ return checkGetter(true, "Number");
+ }
+
+ private static boolean checkAvailableValid() throws Exception {
+ return checkGetter(false, "available");
+ }
+
+ private static boolean checkAvailableInvalid() throws Exception {
+ return checkGetter(true, "Available");
+ }
+
+ private static boolean checkGetter(boolean nullExpected, String name)
+ throws Exception {
+ Method m = getReadMethod(BeanClass.class, name);
+ boolean result = (m != null);
+ if (nullExpected) result = !result;
+
+ if (result) {
+ return true;
+ }
+ if (nullExpected) {
+ System.err.println("SimpleIntrospector resolved an unknown getter " +
+ "for attribute '"+ name +"'");
+ } else {
+ System.err.println("SimpleIntrospector fails to resolve getter " +
+ "for attribute '"+ name +"'");
+ }
+ return false;
+ }
+
+ private static Method getReadMethod(Class clz, String attr)
+ throws Exception {
+ return (Method)INTROSPECT_GETTER.invoke(null, clz, attr);
+ }
+}
--- a/jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java Thu Aug 06 12:35:59 2015 -0700
+++ b/jdk/test/java/lang/management/MemoryMXBean/LowMemoryTest.java Thu Aug 06 13:00:45 2015 -0700
@@ -33,7 +33,7 @@
* @library /lib/testlibrary/
* @modules java.management
* @build jdk.testlibrary.* LowMemoryTest MemoryUtil RunUtil
- * @run main/timeout=600 LowMemoryTest
+ * @run main/timeout=600 LowMemoryTest
* @requires vm.opt.ExplicitGCInvokesConcurrent != "true"
* @requires vm.opt.ExplicitGCInvokesConcurrentAndUnloadsClasses != "true"
* @requires vm.opt.DisableExplicitGC != "true"
@@ -44,6 +44,9 @@
import java.util.concurrent.Phaser;
import javax.management.*;
import javax.management.openmbean.CompositeData;
+import jdk.testlibrary.ProcessTools;
+import jdk.testlibrary.JDKToolFinder;
+import jdk.testlibrary.Utils;
public class LowMemoryTest {
private static final MemoryMXBean mm = ManagementFactory.getMemoryMXBean();
@@ -56,6 +59,7 @@
private static final int NUM_CHUNKS = 2;
private static final int YOUNG_GEN_SIZE = 8 * 1024 * 1024;
private static long chunkSize;
+ private static final String classMain = "LowMemoryTest$TestMain";
/**
* Run the test multiple times with different GC versions.
@@ -63,7 +67,6 @@
* Then with GC versions specified by the test.
*/
public static void main(String a[]) throws Throwable {
- final String main = "LowMemoryTest$TestMain";
// Use a low young gen size to ensure that the
// allocated objects are put in the old gen.
final String nmFlag = "-Xmn" + YOUNG_GEN_SIZE;
@@ -73,12 +76,75 @@
// Prevent G1 from selecting a large heap region size,
// since that would change the young gen size.
final String g1Flag = "-XX:G1HeapRegionSize=1m";
- RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseSerialGC");
- RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseParallelGC");
- RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseG1GC", g1Flag);
- RunUtil.runTestClearGcOpts(main, nmFlag, lpFlag, "-XX:+UseConcMarkSweepGC");
+
+ // Runs the test collecting subprocess I/O while it's running.
+ traceTest(classMain + ", -XX:+UseSerialGC", nmFlag, lpFlag, "-XX:+UseSerialGC");
+ traceTest(classMain + ", -XX:+UseParallelGC", nmFlag, lpFlag, "-XX:+UseParallelGC");
+ traceTest(classMain + ", -XX:+UseG1GC", nmFlag, lpFlag, "-XX:+UseG1GC", g1Flag);
+ traceTest(classMain + ", -XX:+UseConcMarkSweepGC", nmFlag, lpFlag, "-XX:+UseConcMarkSweepGC");
+ }
+
+ /*
+ * Creating command-line for running subprocess JVM:
+ *
+ * JVM command line is like:
+ * {test_jdk}/bin/java {defaultopts} -cp {test.class.path} {testopts} main
+ *
+ * {defaultopts} are the default java options set by the framework.
+ *
+ * @param testOpts java options specified by the test.
+ */
+ private static List<String> buildCommandLine(String... testOpts) {
+ List<String> opts = new ArrayList<>();
+ opts.add(JDKToolFinder.getJDKTool("java"));
+ opts.addAll(Arrays.asList(Utils.getTestJavaOpts()));
+ opts.add("-cp");
+ opts.add(System.getProperty("test.class.path", "test.class.path"));
+ opts.add("-XX:+PrintGCDetails");
+ opts.addAll(Arrays.asList(testOpts));
+ opts.add(classMain);
+
+ return opts;
}
+ /**
+ * Runs LowMemoryTest$TestMain with the passed options and redirects subprocess
+ * standard I/O to the current (parent) process. This provides a trace of what
+ * happens in the subprocess while it is runnning (and before it terminates).
+ *
+ * @param prefixName the prefix string for redirected outputs
+ * @param testOpts java options specified by the test.
+ */
+ private static void traceTest(String prefixName,
+ String... testOpts)
+ throws Throwable {
+
+ // Building command-line
+ List<String> opts = buildCommandLine(testOpts);
+
+ // We activate all tracing in subprocess
+ opts.add("trace");
+
+ // Launch separate JVM subprocess
+ String[] optsArray = opts.toArray(new String[0]);
+ ProcessBuilder pb = new ProcessBuilder(optsArray);
+ System.out.println("\n========= Tracing of subprocess " + prefixName + " =========");
+ Process p = ProcessTools.startProcess(prefixName, pb);
+
+ // Handling end of subprocess
+ try {
+ int exitCode = p.waitFor();
+ if (exitCode != 0) {
+ throw new RuntimeException(
+ "Subprocess unexpected exit value of [" + exitCode + "]. Expected 0.\n");
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Parent process interrupted with exception : \n " + e + " :" );
+ }
+
+
+ }
+
private static volatile boolean listenerInvoked = false;
static class SensorListener implements NotificationListener {
@Override
@@ -204,6 +270,7 @@
System.out.println("Setting threshold for " + mpool.getName() +
" from " + mpool.getUsageThreshold() + " to " + newThreshold +
". Current used = " + mu.getUsed());
+
mpool.setUsageThreshold(newThreshold);
if (mpool.getUsageThreshold() != newThreshold) {
@@ -236,7 +303,6 @@
throw new RuntimeException("TEST FAILED.");
System.out.println(RunUtil.successMessage);
-
}
}
@@ -298,28 +364,42 @@
static class SweeperThread extends Thread {
private void doTask() {
+ int iterations = 0;
+ if (trace) {
+ System.out.println("SweeperThread clearing allocated objects.");
+ }
+
for (; mpool.getUsage().getUsed() >=
mpool.getUsageThreshold();) {
// clear all allocated objects and invoke GC
objectPool.clear();
mm.gc();
+
+ if (trace) {
+ iterations++;
+ System.out.println("SweeperThread called " + iterations +
+ " time(s) MemoryMXBean.gc().");
+ }
+
goSleep(100);
}
}
+
@Override
public void run() {
for (int i = 1; i <= NUM_TRIGGERS; i++) {
// Sync with AllocatorThread's first phase.
phaser.arriveAndAwaitAdvance();
- System.out.println("SweepThread is doing task " + i +
+ System.out.println("SweeperThread is doing task " + i +
" phase " + phaser.getPhase());
+
doTask();
listenerInvoked = false;
// Sync with AllocatorThread's second phase.
phaser.arriveAndAwaitAdvance();
- System.out.println("SweepThread done task " + i +
+ System.out.println("SweeperThread done task " + i +
" phase " + phaser.getPhase());
if (testFailed) return;
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/ref/FinalizerHistogramTest.java Thu Aug 06 13:00:45 2015 -0700
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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.
+ */
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.ReentrantLock;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Field;
+
+/*
+ * @test
+ * @summary Unit test for FinalizerHistogram
+ * @run main FinalizerHistogramTest
+ */
+
+public class FinalizerHistogramTest {
+ static ReentrantLock lock = new ReentrantLock();
+ static volatile int wasInitialized = 0;
+ static volatile int wasTrapped = 0;
+ static final int objectsCount = 1000;
+
+ static class MyObject {
+ public MyObject() {
+ // Make sure object allocation/deallocation is not optimized out
+ wasInitialized += 1;
+ }
+
+ protected void finalize() {
+ // Trap the object in a finalization queue
+ wasTrapped += 1;
+ lock.lock();
+ }
+ }
+
+ public static void main(String[] argvs) {
+ try {
+ lock.lock();
+ for(int i = 0; i < objectsCount; ++i) {
+ new MyObject();
+ }
+ System.out.println("Objects intialized: " + objectsCount);
+ System.gc();
+ while(wasTrapped < 1);
+
+ Class<?> klass = Class.forName("java.lang.ref.FinalizerHistogram");
+
+ Method m = klass.getDeclaredMethod("getFinalizerHistogram");
+ m.setAccessible(true);
+ Object entries[] = (Object[]) m.invoke(null);
+
+ Class<?> entryKlass = Class.forName("java.lang.ref.FinalizerHistogram$Entry");
+ Field name = entryKlass.getDeclaredField("className");
+ name.setAccessible(true);
+ Field count = entryKlass.getDeclaredField("instanceCount");
+ count.setAccessible(true);
+
+ System.out.println("Unreachable instances waiting for finalization");
+ System.out.println("#instances class name");
+ System.out.println("-----------------------");
+
+ boolean found = false;
+ for (Object entry : entries) {
+ Object e = entryKlass.cast(entry);
+ System.out.printf("%10d %s\n", count.get(e), name.get(e));
+ if (((String) name.get(e)).indexOf("MyObject") != -1 ) {
+ found = true;
+ }
+ }
+
+ if (!found) {
+ throw new RuntimeException("MyObject is not found in test output");
+ }
+
+ System.out.println("Test PASSED");
+ } catch(Exception e) {
+ System.err.println("Test failed with " + e);
+ e.printStackTrace(System.err);
+ throw new RuntimeException("Test failed");
+ } finally {
+ lock.unlock();
+ }
+ }
+}