RFR 8054494: Remove sun.misc.Unsafe.monitorEnter, monitorExit and tryMonitorEnter
Paul Sandoz
paul.sandoz at oracle.com
Mon Jan 12 17:00:42 UTC 2015
On Jan 12, 2015, at 11:33 AM, Filipp Zhinkin <filipp.zhinkin at gmail.com> wrote:
> So that leaves just hotspot/test/compiler/testlibrary/rtm/BusyLock.java using tryMonitorEnter and monitorExit:
>
> 66 if (WB.tryMonitorEnter(monitor)) {
> 67 try {
> 68 barrier.await();
> 69 Thread.sleep(timeout);
> 70 } finally {
> 71 WB.monitorExit(monitor);
> 72 }
> 73 } else {
> 74 throw new RuntimeException("Monitor should be entered by " +
> 75 "::run() first.");
> 76 }
>
> Could we replace that with:
>
> if (!WB.isMonitorHeld(monitor)) {
> synchronized(monitor) {
> ...
> }
> } else {
> ...
> }
>
> ?
>
> If so we would no longer require any updates to white box and i could also remove ObjectSynchronizer::jni_try_enter method. Plus jdk/test/java/lang/ProcessBuilder/Basic.java could be updated to use WB.isMonitorHeld method.
>
> Filipp, I noticed you provided the fix for JDK-8050486 so perhaps you may know if BusyLock can be updated as suggested.
>
> It could be updated to use synchronized-block instead of Unsafe/WB, see attached diff.
>
Thanks! I was unsure if the use of UNSAFE.tryMonitorEnter was a key part of the test or just some extra defence. I will update as you suggest (plus add you as a contributor), and remove the additional methods i added to WB.
Paul.
More information about the hotspot-runtime-dev
mailing list