Skip to content

Commit 3aadead

Browse files
committed
8326753: Lilliput: OMCache: Use AoS
Reviewed-by: rkennke
1 parent 9c09cda commit 3aadead

File tree

4 files changed

+38
-37
lines changed

4 files changed

+38
-37
lines changed

Diff for: src/hotspot/share/runtime/javaThread.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ class JavaThread: public Thread {
11861186

11871187

11881188
static ByteSize om_cache_offset() { return byte_offset_of(JavaThread, _om_cache); }
1189-
static ByteSize om_cache_oops_offset() { return om_cache_offset() + OMCache::oops_offset(); }
1189+
static ByteSize om_cache_oops_offset() { return om_cache_offset() + OMCache::entries(); }
11901190

11911191
void om_set_monitor_cache(ObjectMonitor* monitor);
11921192
void om_clear_monitor_cache();

Diff for: src/hotspot/share/runtime/lockStack.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "utilities/debug.hpp"
3737
#include "utilities/globalDefinitions.hpp"
3838
#include "utilities/ostream.hpp"
39+
#include "utilities/sizes.hpp"
3940

4041
#include <type_traits>
4142

@@ -110,3 +111,11 @@ void LockStack::print_on(outputStream* st) {
110111
}
111112
}
112113
}
114+
115+
OMCache::OMCache(JavaThread* jt) : _entries() {
116+
STATIC_ASSERT(std::is_standard_layout<OMCache>::value);
117+
STATIC_ASSERT(std::is_standard_layout<OMCache::OMCacheEntry>::value);
118+
STATIC_ASSERT(offsetof(OMCache, _null_sentinel) == offsetof(OMCache, _entries) +
119+
offsetof(OMCache::OMCacheEntry, _oop) +
120+
OMCache::CAPACITY * in_bytes(oop_to_oop_difference()));
121+
}

Diff for: src/hotspot/share/runtime/lockStack.hpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,18 @@ class OMCache {
140140
static constexpr int CAPACITY = 8;
141141

142142
private:
143-
oop _oops[CAPACITY];
144-
const oop _null_sentinel;
145-
ObjectMonitor* _monitors[CAPACITY];
143+
struct OMCacheEntry {
144+
oop _oop = nullptr;
145+
ObjectMonitor* _monitor = nullptr;
146+
} _entries[CAPACITY];
147+
const oop _null_sentinel = nullptr;
146148

147149
public:
148-
static ByteSize oops_offset() { return byte_offset_of(OMCache, _oops); }
149-
static ByteSize monitors_offset() { return byte_offset_of(OMCache, _monitors); }
150-
static ByteSize oop_to_oop_difference() { return in_ByteSize(sizeof(oop)); }
151-
static ByteSize oop_to_monitor_difference() { return monitors_offset() - oops_offset(); }
150+
static ByteSize entries() { return byte_offset_of(OMCache, _entries); }
151+
static constexpr ByteSize oop_to_oop_difference() { return in_ByteSize(sizeof(OMCacheEntry)); }
152+
static constexpr ByteSize oop_to_monitor_difference() { return in_ByteSize(sizeof(oop)); }
152153

153-
explicit OMCache(JavaThread* jt) : _oops(), _null_sentinel(nullptr), _monitors() {};
154+
explicit OMCache(JavaThread* jt);
154155

155156
inline ObjectMonitor* get_monitor(oop o);
156157
inline void set_monitor(ObjectMonitor* monitor);

Diff for: src/hotspot/share/runtime/lockStack.inline.hpp

+19-28
Original file line numberDiff line numberDiff line change
@@ -247,55 +247,46 @@ inline void OMCache::set_monitor(ObjectMonitor *monitor) {
247247
assert(obj != nullptr, "must be alive");
248248
assert(monitor == PlaceholderSynchronizer::read_monitor(JavaThread::current(), obj), "must be exist in table");
249249

250-
oop cmp_obj = obj;
250+
OMCacheEntry to_insert = {obj, monitor};
251+
251252
for (int i = 0; i < end; ++i) {
252-
if (_oops[i] == cmp_obj ||
253-
_monitors[i] == nullptr ||
254-
_monitors[i]->is_being_async_deflated()) {
255-
_oops[i] = obj;
256-
_monitors[i] = monitor;
253+
if (_entries[i]._oop == obj ||
254+
_entries[i]._monitor == nullptr ||
255+
_entries[i]._monitor->is_being_async_deflated()) {
256+
// Use stale slot.
257+
_entries[i] = to_insert;
257258
return;
258259
}
259-
// Remember Most Recent Values
260-
oop tmp_oop = obj;
261-
ObjectMonitor* tmp_mon = monitor;
262-
// Set next pair to the next most recent
263-
obj = _oops[i];
264-
monitor = _monitors[i];
265-
// Store most recent values
266-
_oops[i] = tmp_oop;
267-
_monitors[i] = tmp_mon;
260+
// Swap with the most recent value.
261+
::swap(to_insert, _entries[i]);
268262
}
269-
_oops[end] = obj;
270-
_monitors[end] = monitor;
263+
_entries[end] = to_insert;
271264
}
272265

273266
inline ObjectMonitor* OMCache::get_monitor(oop o) {
274267
for (int i = 0; i < OMCacheSize; ++i) {
275-
if (_oops[i] == o) {
276-
assert(_monitors[i] != nullptr, "monitor must exist");
277-
if (_monitors[i]->is_being_async_deflated()) {
268+
if (_entries[i]._oop == o) {
269+
assert(_entries[i]._monitor != nullptr, "monitor must exist");
270+
if (_entries[i]._monitor->is_being_async_deflated()) {
278271
// Bad monitor
279272
// Shift down rest
280273
for (; i < OMCacheSize - 1; ++i) {
281-
_oops[i] = _oops[i + 1];
282-
_monitors[i] = _monitors[i + 1];
274+
_entries[i] = _entries[i + 1];
283275
}
284-
// i == CAPACITY - 1
285-
_oops[i] = nullptr;
286-
_monitors[i] = nullptr;
276+
// Clear end
277+
_entries[i] = {};
287278
return nullptr;
288279
}
289-
return _monitors[i];
280+
return _entries[i]._monitor;
290281
}
291282
}
292283
return nullptr;
293284
}
294285

295286
inline void OMCache::clear() {
296287
for (size_t i = 0 , r = 0; i < CAPACITY; ++i) {
297-
_oops[i] = nullptr;
298-
_monitors[i] = nullptr;
288+
// Clear
289+
_entries[i] = {};
299290
}
300291
}
301292

0 commit comments

Comments
 (0)