< prev index next > src/hotspot/share/runtime/lightweightSynchronizer.cpp
Print this page
#include "runtime/trimNativeHeap.hpp"
#include "utilities/concurrentHashTable.inline.hpp"
#include "utilities/concurrentHashTableTasks.inline.hpp"
#include "utilities/globalDefinitions.hpp"
+ static uintx objhash(oop obj) {
+ if (UseCompactObjectHeaders) {
+ uintx hash = LightweightSynchronizer::get_hash(obj->mark(), obj);
+ assert(hash != 0, "should have a hash");
+ return hash;
+ } else {
+ uintx hash = obj->mark().hash();
+ assert(hash != 0, "should have a hash");
+ return hash;
+ }
+ }
+
// ConcurrentHashTable storing links from objects to ObjectMonitors
class ObjectMonitorTable : AllStatic {
struct Config {
using Value = ObjectMonitor*;
static uintx get_hash(Value const& value, bool* is_dead) {
public:
explicit Lookup(oop obj) : _obj(obj) {}
uintx get_hash() const {
! uintx hash = _obj->mark().hash();
- assert(hash != 0, "should have a hash");
- return hash;
}
bool equals(ObjectMonitor** value) {
assert(*value != nullptr, "must be");
return (*value)->object_refers_to(_obj);
public:
explicit Lookup(oop obj) : _obj(obj) {}
uintx get_hash() const {
! return objhash(_obj);
}
bool equals(ObjectMonitor** value) {
assert(*value != nullptr, "must be");
return (*value)->object_refers_to(_obj);
// Enter the monitor into the concurrent hashtable.
ObjectMonitor* result = monitor;
Lookup lookup_f(obj);
auto found_f = [&](ObjectMonitor** found) {
assert((*found)->object_peek() == obj, "must be");
+ assert(objhash(obj) == (uintx)(*found)->hash(), "hash must match");
result = *found;
};
bool grow;
_table->insert_get(current, lookup_f, monitor, found_f, &grow);
verify_monitor_get_result(obj, result);
auto printer = [&] (ObjectMonitor** entry) {
ObjectMonitor* om = *entry;
oop obj = om->object_peek();
st->print("monitor=" PTR_FORMAT ", ", p2i(om));
st->print("object=" PTR_FORMAT, p2i(obj));
! assert(obj->mark().hash() == om->hash(), "hash must match");
st->cr();
return true;
};
if (SafepointSynchronize::is_at_safepoint()) {
_table->do_safepoint_scan(printer);
auto printer = [&] (ObjectMonitor** entry) {
ObjectMonitor* om = *entry;
oop obj = om->object_peek();
st->print("monitor=" PTR_FORMAT ", ", p2i(om));
st->print("object=" PTR_FORMAT, p2i(obj));
! assert(objhash(obj) == (uintx)om->hash(), "hash must match");
st->cr();
return true;
};
if (SafepointSynchronize::is_at_safepoint()) {
_table->do_safepoint_scan(printer);
// Add the hashcode to the monitor to match the object and put it in the hashtable.
ObjectMonitor* LightweightSynchronizer::add_monitor(JavaThread* current, ObjectMonitor* monitor, oop obj) {
assert(UseObjectMonitorTable, "must be");
assert(obj == monitor->object(), "must be");
! intptr_t hash = obj->mark().hash();
assert(hash != 0, "must be set when claiming the object monitor");
monitor->set_hash(hash);
return ObjectMonitorTable::monitor_put_get(current, monitor, obj);
}
// Add the hashcode to the monitor to match the object and put it in the hashtable.
ObjectMonitor* LightweightSynchronizer::add_monitor(JavaThread* current, ObjectMonitor* monitor, oop obj) {
assert(UseObjectMonitorTable, "must be");
assert(obj == monitor->object(), "must be");
! intptr_t hash = objhash(obj);
assert(hash != 0, "must be set when claiming the object monitor");
monitor->set_hash(hash);
return ObjectMonitorTable::monitor_put_get(current, monitor, obj);
}
}
// Slow-path.
return false;
}
+
+ uint32_t LightweightSynchronizer::get_hash(markWord mark, oop obj, Klass* klass) {
+ assert(UseCompactObjectHeaders, "Only with compact i-hash");
+ //assert(mark.is_neutral() | mark.is_fast_locked(), "only from neutral or fast-locked mark: " INTPTR_FORMAT, mark.value());
+ assert(mark.is_hashed(), "only from hashed or copied object");
+ if (mark.is_hashed_expanded()) {
+ return obj->int_field(klass->hash_offset_in_bytes(obj));
+ } else {
+ assert(mark.is_hashed_not_expanded(), "must be hashed");
+ assert(hashCode == 6 || hashCode == 2, "must have idempotent hashCode");
+ // Already marked as hashed, but not yet copied. Recompute hash and return it.
+ return ObjectSynchronizer::get_next_hash(nullptr, obj); // recompute hash
+ }
+ }
+
+ uint32_t LightweightSynchronizer::get_hash(markWord mark, oop obj) {
+ return get_hash(mark, obj, mark.klass());
+ }
< prev index next >