< prev index next >
src/hotspot/share/runtime/synchronizer.cpp
Print this page
*** 126,135 ****
--- 126,148 ----
static void post_monitor_inflate_event(EventJavaMonitorInflate&,
const oop,
const ObjectSynchronizer::InflateCause);
+ #define CHECK_THROW_VALUE_TYPE_IMSE(obj) \
+ if ((obj)->klass_is_value_type()) { \
+ ResourceMark rm(THREAD); \
+ THROW_MSG(vmSymbols::java_lang_IllegalMonitorStateException(), obj->klass()->external_name()); \
+ }
+
+ #define CHECK_THROW_VALUE_TYPE_IMSE_0(obj) \
+ if ((obj)->klass_is_value_type()) { \
+ ResourceMark rm(THREAD); \
+ THROW_MSG_0(vmSymbols::java_lang_IllegalMonitorStateException(), obj->klass()->external_name()); \
+ }
+
+
#define CHAINMARKER (cast_to_oop<intptr_t>(-1))
// =====================> Quick functions
*** 157,166 ****
--- 170,180 ----
assert(!SafepointSynchronize::is_at_safepoint(), "invariant");
assert(self->is_Java_thread(), "invariant");
assert(((JavaThread *) self)->thread_state() == _thread_in_Java, "invariant");
NoSafepointVerifier nsv;
if (obj == NULL) return false; // slow-path for invalid obj
+ assert(!obj->klass_is_value_type(), "monitor op on value type");
const markOop mark = obj->mark();
if (mark->has_locker() && self->is_lock_owned((address)mark->locker())) {
// Degenerate notify
// stack-locked by caller so by definition the implied waitset is empty.
*** 207,216 ****
--- 221,231 ----
assert(!SafepointSynchronize::is_at_safepoint(), "invariant");
assert(Self->is_Java_thread(), "invariant");
assert(((JavaThread *) Self)->thread_state() == _thread_in_Java, "invariant");
NoSafepointVerifier nsv;
if (obj == NULL) return false; // Need to throw NPE
+ assert(!obj->klass_is_value_type(), "monitor op on value type");
const markOop mark = obj->mark();
if (mark->has_monitor()) {
ObjectMonitor * const m = mark->monitor();
assert(m->object() == obj, "invariant");
*** 262,271 ****
--- 277,287 ----
// if the following function is changed. The implementation is
// extremely sensitive to race condition. Be careful.
void ObjectSynchronizer::fast_enter(Handle obj, BasicLock* lock,
bool attempt_rebias, TRAPS) {
+ assert(!obj->klass_is_value_type(), "monitor op on value type");
if (UseBiasedLocking) {
if (!SafepointSynchronize::is_at_safepoint()) {
BiasedLocking::Condition cond = BiasedLocking::revoke_and_rebias(obj, attempt_rebias, THREAD);
if (cond == BiasedLocking::BIAS_REVOKED_AND_REBIASED) {
return;
*** 280,289 ****
--- 296,306 ----
slow_enter(obj, lock, THREAD);
}
void ObjectSynchronizer::fast_exit(oop object, BasicLock* lock, TRAPS) {
markOop mark = object->mark();
+ assert(!object->klass_is_value_type(), "monitor op on value type");
// We cannot check for Biased Locking if we are racing an inflation.
assert(mark == markOopDesc::INFLATING() ||
!mark->has_bias_pattern(), "should not see bias pattern here");
markOop dhw = lock->displaced_header();
*** 336,345 ****
--- 353,363 ----
// Interpreter/Compiler Slow Case
// This routine is used to handle interpreter/compiler slow case
// We don't need to use fast path here, because it must have been
// failed in the interpreter/compiler code.
void ObjectSynchronizer::slow_enter(Handle obj, BasicLock* lock, TRAPS) {
+ CHECK_THROW_VALUE_TYPE_IMSE(obj);
markOop mark = obj->mark();
assert(!mark->has_bias_pattern(), "should not see bias pattern here");
if (mark->is_neutral()) {
// Anticipate successful CAS -- the ST of the displaced mark must
*** 388,397 ****
--- 406,416 ----
// 4) reenter lock1 with original recursion count
// 5) lock lock2
// NOTE: must use heavy weight monitor to handle complete_exit/reenter()
intptr_t ObjectSynchronizer::complete_exit(Handle obj, TRAPS) {
TEVENT(complete_exit);
+ assert(!obj->klass_is_value_type(), "monitor op on value type");
if (UseBiasedLocking) {
BiasedLocking::revoke_and_rebias(obj, false, THREAD);
assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
}
*** 403,412 ****
--- 422,432 ----
}
// NOTE: must use heavy weight monitor to handle complete_exit/reenter()
void ObjectSynchronizer::reenter(Handle obj, intptr_t recursion, TRAPS) {
TEVENT(reenter);
+ assert(!obj->klass_is_value_type(), "monitor op on value type");
if (UseBiasedLocking) {
BiasedLocking::revoke_and_rebias(obj, false, THREAD);
assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
}
*** 420,429 ****
--- 440,450 ----
// JNI locks on java objects
// NOTE: must use heavy weight monitor to handle jni monitor enter
void ObjectSynchronizer::jni_enter(Handle obj, TRAPS) {
// the current locking is from JNI instead of Java code
TEVENT(jni_enter);
+ CHECK_THROW_VALUE_TYPE_IMSE(obj);
if (UseBiasedLocking) {
BiasedLocking::revoke_and_rebias(obj, false, THREAD);
assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
}
THREAD->set_current_pending_monitor_is_from_java(false);
*** 432,441 ****
--- 453,463 ----
}
// NOTE: must use heavy weight monitor to handle jni monitor exit
void ObjectSynchronizer::jni_exit(oop obj, Thread* THREAD) {
TEVENT(jni_exit);
+ CHECK_THROW_VALUE_TYPE_IMSE(obj);
if (UseBiasedLocking) {
Handle h_obj(THREAD, obj);
BiasedLocking::revoke_and_rebias(h_obj, false, THREAD);
obj = h_obj();
}
*** 476,485 ****
--- 498,508 ----
// -----------------------------------------------------------------------------
// Wait/Notify/NotifyAll
// NOTE: must use heavy weight monitor to handle wait()
int ObjectSynchronizer::wait(Handle obj, jlong millis, TRAPS) {
+ CHECK_THROW_VALUE_TYPE_IMSE_0(obj);
if (UseBiasedLocking) {
BiasedLocking::revoke_and_rebias(obj, false, THREAD);
assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
}
if (millis < 0) {
*** 499,508 ****
--- 522,532 ----
// DTRACE_MONITOR_PROBE(waited, monitor, obj(), THREAD);
return dtrace_waited_probe(monitor, obj, THREAD);
}
void ObjectSynchronizer::waitUninterruptibly(Handle obj, jlong millis, TRAPS) {
+ CHECK_THROW_VALUE_TYPE_IMSE(obj);
if (UseBiasedLocking) {
BiasedLocking::revoke_and_rebias(obj, false, THREAD);
assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
}
if (millis < 0) {
*** 513,522 ****
--- 537,547 ----
obj(),
inflate_cause_wait)->wait(millis, false, THREAD);
}
void ObjectSynchronizer::notify(Handle obj, TRAPS) {
+ CHECK_THROW_VALUE_TYPE_IMSE(obj);
if (UseBiasedLocking) {
BiasedLocking::revoke_and_rebias(obj, false, THREAD);
assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
}
*** 529,538 ****
--- 554,564 ----
inflate_cause_notify)->notify(THREAD);
}
// NOTE: see comment of notify()
void ObjectSynchronizer::notifyall(Handle obj, TRAPS) {
+ CHECK_THROW_VALUE_TYPE_IMSE(obj);
if (UseBiasedLocking) {
BiasedLocking::revoke_and_rebias(obj, false, THREAD);
assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
}
*** 707,716 ****
--- 733,750 ----
TEVENT(hashCode: GENERATE);
return value;
}
intptr_t ObjectSynchronizer::FastHashCode(Thread * Self, oop obj) {
+ if (EnableValhalla && obj->klass_is_value_type()) {
+ // Expected tooling to override hashCode for value type, just don't crash
+ if (log_is_enabled(Debug, monitorinflation)) {
+ ResourceMark rm;
+ log_debug(monitorinflation)("FastHashCode for value type: %s", obj->klass()->external_name());
+ }
+ return 0;
+ }
if (UseBiasedLocking) {
// NOTE: many places throughout the JVM do not expect a safepoint
// to be taken here, in particular most operations on perm gen
// objects. However, we only ever bias Java instances and all of
// the call sites of identity_hash that might revoke biases have
*** 811,826 ****
}
// We finally get the hash
return hash;
}
- // Deprecated -- use FastHashCode() instead.
-
- intptr_t ObjectSynchronizer::identity_hash_value_for(Handle obj) {
- return FastHashCode(Thread::current(), obj());
- }
-
bool ObjectSynchronizer::current_thread_holds_lock(JavaThread* thread,
Handle h_obj) {
if (UseBiasedLocking) {
BiasedLocking::revoke_and_rebias(h_obj, false, thread);
--- 845,854 ----
*** 1381,1390 ****
--- 1409,1422 ----
// Inflate mutates the heap ...
// Relaxing assertion for bug 6320749.
assert(Universe::verify_in_progress() ||
!SafepointSynchronize::is_at_safepoint(), "invariant");
+ if (EnableValhalla) {
+ guarantee(!object->klass_is_value_type(), "Attempt to inflate value type");
+ }
+
EventJavaMonitorInflate event;
for (;;) {
const markOop mark = object->mark();
assert(!mark->has_bias_pattern(), "invariant");
< prev index next >