[master] RFR: Remove a couple LIGHTWEIGHT things from the legacy/monitor version of FastHashCode
Axel Boldt-Christmas
aboldtch at openjdk.org
Wed May 29 06:17:18 UTC 2024
On Tue, 28 May 2024 16:33:32 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:
> So I have to undo this to have a UseObjectMonitorTable option.
That might be the easiest initial approach.
It might be worth to move all the LM_LIGHTWEIGHT code to LightweightSynchronizer regardless. For example the FastHashCode could become:
```C++
intptr_t LightweightSynchronizer::FastHashCode(Thread* current, oop obj) {
assert(LockingMode == LM_LIGHTWEIGHT, "must be");
markWord mark = obj->mark_acquire();
for(;;) {
if (UseOMWorldFlag || !mark.has_monitor()) {
intptr_t hash = mark.hash();
if (hash != 0) {
return hash;
}
hash = ObjectSynchronizer::get_next_hash(current, obj);
const markWord old_mark = mark;
const markWord new_mark = old_mark.copy_set_hash(hash);
mark = obj->cas_set_mark(new_mark, old_mark);
if (old_mark == mark) {
return hash;
}
} else {
ObjectMonitor* monitor = mark.monitor();
markWord displaced_header = monitor->header();
intptr_t hash = displaced_header.hash();
if (hash == 0) {
// Try to install new hash.
hash = ObjectSynchronizer::get_next_hash(current, obj);
displaced_header = mark.copy_set_hash(hash);
displaced_header = markWord(Atomic::cmpxchg(monitor->metadata_addr(), mark.value(), displaced_header.value()));
if (displaced_header != mark) {
// Someone installed another hash before us.
hash = displaced_header.hash();
}
} else {
// Must order the markWord read and the ObjectMonitor contentions read.
OrderAccess::loadload_for_IRIW();
}
if (monitor->is_being_async_deflated()) {
// We do not trust this monitor, assist in deflating the ObjectMonitor and retry.
// This can only happen once per call.
monitor->install_displaced_markword_in_object(obj);
mark = obj->mark_acquire();
continue;
}
return hash;
}
}
}
The whole `else` branch could be shared with the ObjectSynchronizer::FastHashCode. (And added to ObjectMonitor::FastHashCode`.) It makes more sense from an access control point of view as well. Currently the ObjectSynchronizer::FastHashCode uses the friend class property to do things to the ObjectMonitor, which sort of feels like something is poorly designed.
This could then become something in the style of.
```C++
intptr_t LightweightSynchronizer::FastHashCode(Thread* current, oop obj) {
assert(LockingMode == LM_LIGHTWEIGHT, "must be");
markWord mark = obj->mark_acquire();
for(;;) {
if (UseOMWorldFlag || !mark.has_monitor()) {
intptr_t hash = mark.hash();
if (hash != 0) {
return hash;
}
hash = ObjectSynchronizer::get_next_hash(current, obj);
const markWord old_mark = mark;
const markWord new_mark = old_mark.copy_set_hash(hash);
mark = obj->cas_set_mark(new_mark, old_mark);
if (old_mark == mark) {
return hash;
}
} else {
ObjectMonitor* monitor = mark.monitor();
intptr_t hash = 0;
if (monitor->FastHashCode(current, obj, &hash)) {
return hash;
}
}
}
}
-------------
PR Comment: https://git.openjdk.org/lilliput/pull/179#issuecomment-2136599739
More information about the lilliput-dev
mailing list