/*
* 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.
*
*/
#include "precompiled.hpp"
#include "prims/jvmtiRawMonitor.hpp"
#include "runtime/interfaceSupport.hpp"
#include "runtime/thread.hpp"
GrowableArray<JvmtiRawMonitor*> *JvmtiPendingMonitors::_monitors = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<JvmtiRawMonitor*>(1,true);
"Java thread has not created yet or more than one java thread \
is running. Raw monitor transition will not work");
{
for(int i=0; i< count(); i++) {
}
}
// pending monitors are converted to real monitor so delete them all.
dispose();
}
//
// class JvmtiRawMonitor
//
#ifdef ASSERT
#else
#endif
}
#ifdef ASSERT
#endif
_magic = 0;
}
bool
int value = 0;
// This object might not be a JvmtiRawMonitor so we can't assume
// the _magic field is properly aligned. Get the value in a safe
// way and then check against JVMTI_RM_MAGIC.
switch (sizeof(_magic)) {
case 2:
break;
case 4:
break;
case 8:
break;
default:
guarantee(false, "_magic field is an unexpected size");
}
return value == JVMTI_RM_MAGIC;
}
// -------------------------------------------------------------------------
// The raw monitor subsystem is entirely distinct from normal
// java-synchronization or jni-synchronization. raw monitors are not
// associated with objects. They can be implemented in any manner
// that makes sense. The original implementors decided to piggy-back
// the raw-monitor implementation on the existing Java objectMonitor mechanism.
// This flaw needs to fixed. We should reimplement raw monitors as sui-generis.
// Specifically, we should not implement raw monitors via java monitors.
// Time permitting, we should disentangle and deconvolve the two implementations
// and move the resulting raw monitor implementation over to the JVMTI directories.
// Ideally, the raw monitor implementation would be built on top of
// park-unpark and nothing else.
//
// raw monitors are used mainly by JVMTI
// The raw monitor implementation borrows the ObjectMonitor structure,
// but the operators are degenerate and extremely simple.
//
// Mixed use of a single objectMonitor instance -- as both a raw monitor
// and a normal java monitor -- is not permissible.
//
// Note that we use the single RawMonitor_lock to protect queue operations for
// _all_ raw monitors. This is a scalability impediment, but since raw monitor usage
// is deprecated and rare, this is not of concern. The RawMonitor_lock can not
// be held indefinitely. The critical sections must be short and bounded.
//
// -------------------------------------------------------------------------
for (;;) {
return OS_OK ;
}
_EntryList = &Node ;
OrderAccess::fence() ;
RawMonitor_lock->unlock() ;
return OS_OK ;
}
RawMonitor_lock->unlock() ;
}
}
}
OrderAccess::fence() ;
ObjectWaiter * w ;
w = _EntryList ;
if (w != NULL) {
_EntryList = w->_next ;
}
RawMonitor_lock->unlock() ;
if (w != NULL) {
OrderAccess::fence() ;
}
return OS_OK ;
}
RawMonitor_lock->unlock() ;
SimpleExit (Self) ;
if (millis <= 0) {
} else {
}
// If thread still resides on the waitset then unlink it.
// Double-checked locking -- the usage is safe in this context
// as we TState is volatile and the lock-unlock operators are
// serializing (barrier-equivalent).
// Simple O(n) unlink, but performance isn't critical here.
ObjectWaiter * p ;
ObjectWaiter * q = NULL ;
q = p ;
}
if (q == NULL) {
} else {
}
}
RawMonitor_lock->unlock() ;
}
SimpleEnter (Self) ;
return ret ;
}
// We have two options:
// A. Transfer the threads from the WaitSet to the EntryList
// B. Remove the thread from the WaitSet and unpark() it.
//
// We use (B), which is crude and results in lots of futile
// context switching. In particular (B) induces lots of contention.
for (;;) {
ObjectWaiter * w = _WaitSet ;
if (w == NULL) break ;
OrderAccess::loadstore() ;
OrderAccess::storeload();
if (!All) break ;
}
RawMonitor_lock->unlock() ;
return OS_OK ;
}
// Any JavaThread will enter here with state _thread_blocked
void * Contended ;
// don't enter raw monitor if thread is being externally suspended, it will
// surprise the suspender if a "suspended" thread can still enter monitor
if (THREAD->is_Java_thread()) {
while (jt->is_external_suspend()) {
jt->java_suspend_self();
}
// guarded by SR_lock to avoid racing with new external suspend requests.
} else {
}
_recursions ++ ;
return OM_OK ;
}
return OM_OK ;
}
THREAD->set_current_pending_monitor(this);
if (!THREAD->is_Java_thread()) {
// No other non-Java threads besides VM thread would acquire
// a raw monitor.
SimpleEnter (THREAD) ;
} else {
for (;;) {
// cleared by handle_special_suspend_equivalent_condition() or
// java_suspend_self()
SimpleEnter (THREAD) ;
// were we externally suspended while we were waiting?
if (!jt->handle_special_suspend_equivalent_condition()) break ;
// This thread was externally suspended
//
// This logic isn't needed for JVMTI raw monitors,
// but doesn't hurt just in case the suspend rules change. This
// logic is needed for the JvmtiRawMonitor.wait() reentry phase.
// We have reentered the contended monitor, but while we were
// waiting another thread suspended us. We don't want to reenter
// the monitor while suspended because that would surprise the
// thread that suspended us.
//
// Drop the lock -
SimpleExit (THREAD) ;
jt->java_suspend_self();
}
}
return OM_OK;
}
// Used mainly for JVMTI raw monitor implementation
// Also used for JvmtiRawMonitor::wait().
return OM_ILLEGAL_MONITOR_STATE;
}
if (_recursions > 0) {
--_recursions ;
return OM_OK ;
}
SimpleExit (THREAD) ;
return OM_OK;
}
// Used for JVMTI raw monitor implementation.
// All JavaThreads will enter here with state _thread_blocked
return OM_ILLEGAL_MONITOR_STATE;
}
// To avoid spurious wakeups we reset the parkevent -- This is strictly optional.
// The caller must be able to tolerate spurious returns from raw_wait().
OrderAccess::fence() ;
// check interrupt event
return OM_INTERRUPTED;
}
_recursions = 0 ;
_waiters ++ ;
if (THREAD->is_Java_thread()) {
}
_recursions = save ;
_waiters -- ;
if (THREAD->is_Java_thread()) {
for (;;) {
if (!jSelf->handle_special_suspend_equivalent_condition()) break ;
SimpleExit (THREAD) ;
SimpleEnter (THREAD) ;
}
}
return OM_INTERRUPTED;
}
return OM_OK ;
}
TEVENT (raw_notify) ;
return OM_ILLEGAL_MONITOR_STATE;
}
SimpleNotify (THREAD, false) ;
return OM_OK;
}
TEVENT (raw_notifyAll) ;
return OM_ILLEGAL_MONITOR_STATE;
}
SimpleNotify (THREAD, true) ;
return OM_OK;
}