< prev index next >
hotspot/test/compiler/testlibrary/rtm/BusyLock.java
Print this page
rev 7654 : 8054494: Remove sun.misc.Unsafe.monitorEnter, monitorExit and tryMonitorEnter
Reviewed-by: dholmes
Contributed-by: paul.sandoz@oracle.com, filipp.zhinkin@gmail.com
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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.
@@ -22,13 +22,10 @@
*
*/
package rtm;
-import com.oracle.java.testlibrary.Utils;
-import sun.misc.Unsafe;
-
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
/**
* Test case for busy lock scenario.
@@ -40,11 +37,10 @@
private final CyclicBarrier barrier;
// Following field have to be static in order to avoid escape analysis.
@SuppressWarnings("UnsuedDeclaration")
private static int field = 0;
- private static final Unsafe UNSAFE = Utils.getUnsafe();
protected final Object monitor;
protected final int timeout;
public BusyLock() {
this(BusyLock.DEFAULT_TIMEOUT);
@@ -57,31 +53,21 @@
}
@Override
public void run() {
try {
- // wait until forceAbort leave monitor
- barrier.await();
- if (UNSAFE.tryMonitorEnter(monitor)) {
- try {
+ synchronized (monitor) {
barrier.await();
Thread.sleep(timeout);
- } finally {
- UNSAFE.monitorExit(monitor);
- }
- } else {
- throw new RuntimeException("Monitor should be entered by " +
- "::run() first.");
}
} catch (InterruptedException | BrokenBarrierException e) {
throw new RuntimeException("Synchronization error happened.", e);
}
}
public void syncAndTest() {
try {
- barrier.await();
// wait until monitor is locked by a ::run method
barrier.await();
} catch (InterruptedException | BrokenBarrierException e) {
throw new RuntimeException("Synchronization error happened.", e);
}
< prev index next >