8228858: Reimplement JVM_RawMonitors to use PlatformMutex
Reviewed-by: coleenp, dcubed, pchilanomate
--- a/src/hotspot/share/prims/jvm.cpp Wed Aug 14 20:32:44 2019 +0200
+++ b/src/hotspot/share/prims/jvm.cpp Wed Aug 14 18:26:23 2019 -0400
@@ -3384,32 +3384,33 @@
JVM_END
-// Raw monitor support //////////////////////////////////////////////////////////////////////
-
-// The lock routine below calls lock_without_safepoint_check in order to get a raw lock
-// without interfering with the safepoint mechanism. The routines are not JVM_LEAF because
-// they might be called by non-java threads. The JVM_LEAF installs a NoHandleMark check
-// that only works with java threads.
+// VM Raw monitor support //////////////////////////////////////////////////////////////////////
+
+// VM Raw monitors (not to be confused with JvmtiRawMonitors) are a simple mutual exclusion
+// lock (not actually monitors: no wait/notify) that is exported by the VM for use by JDK
+// library code. They may be used by JavaThreads and non-JavaThreads and do not participate
+// in the safepoint protocol, thread suspension, thread interruption, or anything of that
+// nature. JavaThreads will be "in native" when using this API from JDK code.
JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void) {
VM_Exit::block_if_vm_exited();
JVMWrapper("JVM_RawMonitorCreate");
- return new Mutex(Mutex::native, "JVM_RawMonitorCreate");
+ return new os::PlatformMutex();
}
JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon) {
VM_Exit::block_if_vm_exited();
JVMWrapper("JVM_RawMonitorDestroy");
- delete ((Mutex*) mon);
+ delete ((os::PlatformMutex*) mon);
}
JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon) {
VM_Exit::block_if_vm_exited();
JVMWrapper("JVM_RawMonitorEnter");
- ((Mutex*) mon)->jvm_raw_lock();
+ ((os::PlatformMutex*) mon)->lock();
return 0;
}
@@ -3417,7 +3418,7 @@
JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon) {
VM_Exit::block_if_vm_exited();
JVMWrapper("JVM_RawMonitorExit");
- ((Mutex*) mon)->jvm_raw_unlock();
+ ((os::PlatformMutex*) mon)->unlock();
}
--- a/src/hotspot/share/runtime/mutex.cpp Wed Aug 14 20:32:44 2019 +0200
+++ b/src/hotspot/share/runtime/mutex.cpp Wed Aug 14 18:26:23 2019 -0400
@@ -232,24 +232,6 @@
return wait_status != 0; // return true IFF timeout
}
-
-// Temporary JVM_RawMonitor* support.
-// Yet another degenerate version of Monitor::lock() or lock_without_safepoint_check()
-// jvm_raw_lock() and _unlock() can be called by non-Java threads via JVM_RawMonitorEnter.
-// There's no expectation that JVM_RawMonitors will interoperate properly with the native
-// Mutex-Monitor constructs. We happen to implement JVM_RawMonitors in terms of
-// native Mutex-Monitors simply as a matter of convenience.
-
-void Monitor::jvm_raw_lock() {
- _lock.lock();
- assert_owner(NULL);
-}
-
-void Monitor::jvm_raw_unlock() {
- assert_owner(NULL);
- _lock.unlock();
-}
-
Monitor::~Monitor() {
assert_owner(NULL);
}
--- a/src/hotspot/share/runtime/mutex.hpp Wed Aug 14 20:32:44 2019 +0200
+++ b/src/hotspot/share/runtime/mutex.hpp Wed Aug 14 18:26:23 2019 -0400
@@ -52,8 +52,10 @@
// inherently a bit more special than even locks of the 'special' rank.
// NOTE: It is critical that the rank 'special' be the lowest (earliest)
// (except for "event" and "access") for the deadlock detection to work correctly.
- // The rank native is only for use in Mutex's created by JVM_RawMonitorCreate,
- // which being external to the VM are not subject to deadlock detection.
+ // The rank native was only for use in Mutexes created by JVM_RawMonitorCreate,
+ // which being external to the VM are not subject to deadlock detection,
+ // however it has now been used by other locks that don't fit into the
+ // deadlock detection scheme.
// While at a safepoint no mutexes of rank safepoint are held by any thread.
// The rank named "leaf" is probably historical (and should
// be changed) -- mutexes of this rank aren't really leaf mutexes
@@ -174,10 +176,6 @@
Thread* owner() const { return _owner; }
bool owned_by_self() const;
- // Support for JVM_RawMonitorEnter & JVM_RawMonitorExit. These can be called by
- // non-Java thread. (We should really have a RawMonitor abstraction)
- void jvm_raw_lock();
- void jvm_raw_unlock();
const char *name() const { return _name; }
void print_on_error(outputStream* st) const;
--- a/src/hotspot/share/runtime/park.cpp Wed Aug 14 20:32:44 2019 +0200
+++ b/src/hotspot/share/runtime/park.cpp Wed Aug 14 18:26:23 2019 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2019, 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
@@ -53,7 +53,6 @@
ParkEvent * volatile ParkEvent::FreeList = NULL ;
ParkEvent * ParkEvent::Allocate (Thread * t) {
- // In rare cases -- JVM_RawMonitor* operations -- we can find t == null.
ParkEvent * ev ;
// Start by trying to recycle an existing but unassociated
@@ -164,4 +163,3 @@
}
Thread::SpinRelease(&ListLock);
}
-