Skip to content

Commit e2e1598

Browse files
committed
8353584: [BACKOUT] DaCapo xalan performance with -XX:+UseObjectMonitorTable
Reviewed-by: rkennke
1 parent 814730e commit e2e1598

File tree

8 files changed

+26
-57
lines changed

8 files changed

+26
-57
lines changed

src/hotspot/share/runtime/basicLock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "runtime/objectMonitor.hpp"
2828
#include "runtime/synchronizer.hpp"
2929

30-
void BasicLock::print_on(outputStream* st, oop owner) {
30+
void BasicLock::print_on(outputStream* st, oop owner) const {
3131
st->print("monitor");
3232
if (UseObjectMonitorTable) {
3333
ObjectMonitor* mon = object_monitor_cache();

src/hotspot/share/runtime/basicLock.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ class BasicLock {
5050
static int metadata_offset_in_bytes() { return (int)offset_of(BasicLock, _metadata); }
5151

5252
public:
53-
BasicLock() : _metadata(0) {}
54-
5553
// LM_MONITOR
5654
void set_bad_metadata_deopt() { set_metadata(badDispHeaderDeopt); }
5755

@@ -61,12 +59,12 @@ class BasicLock {
6159
static int displaced_header_offset_in_bytes() { return metadata_offset_in_bytes(); }
6260

6361
// LM_LIGHTWEIGHT
64-
inline ObjectMonitor* object_monitor_cache();
62+
inline ObjectMonitor* object_monitor_cache() const;
6563
inline void clear_object_monitor_cache();
6664
inline void set_object_monitor_cache(ObjectMonitor* mon);
6765
static int object_monitor_cache_offset_in_bytes() { return metadata_offset_in_bytes(); }
6866

69-
void print_on(outputStream* st, oop owner);
67+
void print_on(outputStream* st, oop owner) const;
7068

7169
// move a basic lock (used during deoptimization)
7270
void move_to(oop obj, BasicLock* dest);

src/hotspot/share/runtime/basicLock.inline.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#define SHARE_RUNTIME_BASICLOCK_INLINE_HPP
2727

2828
#include "runtime/basicLock.hpp"
29-
#include "runtime/objectMonitor.inline.hpp"
3029

3130
inline markWord BasicLock::displaced_header() const {
3231
assert(LockingMode == LM_LEGACY, "must be");
@@ -38,15 +37,10 @@ inline void BasicLock::set_displaced_header(markWord header) {
3837
Atomic::store(&_metadata, header.value());
3938
}
4039

41-
inline ObjectMonitor* BasicLock::object_monitor_cache() {
40+
inline ObjectMonitor* BasicLock::object_monitor_cache() const {
4241
assert(UseObjectMonitorTable, "must be");
4342
#if !defined(ZERO) && (defined(X86) || defined(AARCH64) || defined(RISCV64) || defined(PPC64) || defined(S390))
44-
ObjectMonitor* monitor = reinterpret_cast<ObjectMonitor*>(get_metadata());
45-
if (monitor != nullptr && monitor->is_being_async_deflated()) {
46-
clear_object_monitor_cache();
47-
return nullptr;
48-
}
49-
return monitor;
43+
return reinterpret_cast<ObjectMonitor*>(get_metadata());
5044
#else
5145
// Other platforms do not make use of the cache yet,
5246
// and are not as careful with maintaining the invariant

src/hotspot/share/runtime/lightweightSynchronizer.cpp

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ void LightweightSynchronizer::enter_for(Handle obj, BasicLock* lock, JavaThread*
633633
} else {
634634
do {
635635
// It is assumed that enter_for must enter on an object without contention.
636-
monitor = inflate_and_enter(obj(), lock, ObjectSynchronizer::inflate_cause_monitor_enter, locking_thread, current);
636+
monitor = inflate_and_enter(obj(), ObjectSynchronizer::inflate_cause_monitor_enter, locking_thread, current);
637637
// But there may still be a race with deflation.
638638
} while (monitor == nullptr);
639639
}
@@ -689,7 +689,7 @@ void LightweightSynchronizer::enter(Handle obj, BasicLock* lock, JavaThread* cur
689689
spin_yield.wait();
690690
}
691691

692-
ObjectMonitor* monitor = inflate_and_enter(obj(), lock, ObjectSynchronizer::inflate_cause_monitor_enter, current, current);
692+
ObjectMonitor* monitor = inflate_and_enter(obj(), ObjectSynchronizer::inflate_cause_monitor_enter, current, current);
693693
if (monitor != nullptr) {
694694
cache_setter.set_monitor(monitor);
695695
return;
@@ -703,7 +703,7 @@ void LightweightSynchronizer::enter(Handle obj, BasicLock* lock, JavaThread* cur
703703
}
704704
}
705705

706-
void LightweightSynchronizer::exit(oop object, BasicLock* lock, JavaThread* current) {
706+
void LightweightSynchronizer::exit(oop object, JavaThread* current) {
707707
assert(LockingMode == LM_LIGHTWEIGHT, "must be");
708708
assert(current == Thread::current(), "must be");
709709

@@ -738,18 +738,7 @@ void LightweightSynchronizer::exit(oop object, BasicLock* lock, JavaThread* curr
738738

739739
assert(mark.has_monitor(), "must be");
740740
// The monitor exists
741-
ObjectMonitor* monitor;
742-
if (UseObjectMonitorTable) {
743-
monitor = lock->object_monitor_cache();
744-
if (monitor == nullptr) {
745-
monitor = current->om_get_from_monitor_cache(object);
746-
if (monitor == nullptr) {
747-
monitor = get_monitor_from_table(current, object);
748-
}
749-
}
750-
} else {
751-
monitor = ObjectSynchronizer::read_monitor(mark);
752-
}
741+
ObjectMonitor* monitor = ObjectSynchronizer::read_monitor(current, object, mark);
753742
if (monitor->has_anonymous_owner()) {
754743
assert(current->lock_stack().contains(object), "current must have object on its lock stack");
755744
monitor->set_owner_from_anonymous(current);
@@ -988,7 +977,7 @@ ObjectMonitor* LightweightSynchronizer::inflate_fast_locked_object(oop object, O
988977
return monitor;
989978
}
990979

991-
ObjectMonitor* LightweightSynchronizer::inflate_and_enter(oop object, BasicLock* lock, ObjectSynchronizer::InflateCause cause, JavaThread* locking_thread, JavaThread* current) {
980+
ObjectMonitor* LightweightSynchronizer::inflate_and_enter(oop object, ObjectSynchronizer::InflateCause cause, JavaThread* locking_thread, JavaThread* current) {
992981
assert(LockingMode == LM_LIGHTWEIGHT, "only used for lightweight");
993982
VerifyThreadState vts(locking_thread, current);
994983

@@ -1014,20 +1003,18 @@ ObjectMonitor* LightweightSynchronizer::inflate_and_enter(oop object, BasicLock*
10141003

10151004
NoSafepointVerifier nsv;
10161005

1006+
// Lightweight monitors require that hash codes are installed first
1007+
ObjectSynchronizer::FastHashCode(locking_thread, object);
1008+
10171009
// Try to get the monitor from the thread-local cache.
10181010
// There's no need to use the cache if we are locking
10191011
// on behalf of another thread.
10201012
if (current == locking_thread) {
1021-
monitor = lock->object_monitor_cache();
1022-
if (monitor == nullptr) {
1023-
monitor = current->om_get_from_monitor_cache(object);
1024-
}
1013+
monitor = current->om_get_from_monitor_cache(object);
10251014
}
10261015

10271016
// Get or create the monitor
10281017
if (monitor == nullptr) {
1029-
// Lightweight monitors require that hash codes are installed first
1030-
ObjectSynchronizer::FastHashCode(locking_thread, object);
10311018
monitor = get_or_insert_monitor(object, current, cause);
10321019
}
10331020

@@ -1175,6 +1162,9 @@ bool LightweightSynchronizer::quick_enter(oop obj, BasicLock* lock, JavaThread*
11751162
assert(obj != nullptr, "must be");
11761163
NoSafepointVerifier nsv;
11771164

1165+
// If quick_enter succeeds with entering, the cache should be in a valid initialized state.
1166+
CacheSetter cache_setter(current, lock);
1167+
11781168
LockStack& lock_stack = current->lock_stack();
11791169
if (lock_stack.is_full()) {
11801170
// Always go into runtime if the lock stack is full.
@@ -1201,28 +1191,17 @@ bool LightweightSynchronizer::quick_enter(oop obj, BasicLock* lock, JavaThread*
12011191
#endif
12021192

12031193
if (mark.has_monitor()) {
1204-
ObjectMonitor* monitor;
1205-
if (UseObjectMonitorTable) {
1206-
// C2 fast-path may have put the monitor in the cache in the BasicLock.
1207-
monitor = lock->object_monitor_cache();
1208-
if (monitor == nullptr) {
1209-
// Otherwise look up the monitor in the thread's OMCache.
1210-
monitor = current->om_get_from_monitor_cache(obj);
1211-
}
1212-
} else {
1213-
monitor = ObjectSynchronizer::read_monitor(mark);
1214-
}
1194+
ObjectMonitor* const monitor = UseObjectMonitorTable ? current->om_get_from_monitor_cache(obj) :
1195+
ObjectSynchronizer::read_monitor(mark);
12151196

12161197
if (monitor == nullptr) {
12171198
// Take the slow-path on a cache miss.
12181199
return false;
12191200
}
12201201

1221-
if (UseObjectMonitorTable) {
1222-
lock->set_object_monitor_cache(monitor);
1223-
}
1224-
1225-
if (monitor->spin_enter(current)) {
1202+
if (monitor->try_enter(current)) {
1203+
// ObjectMonitor enter successful.
1204+
cache_setter.set_monitor(monitor);
12261205
return true;
12271206
}
12281207
}

src/hotspot/share/runtime/lightweightSynchronizer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ class LightweightSynchronizer : AllStatic {
6161
public:
6262
static void enter_for(Handle obj, BasicLock* lock, JavaThread* locking_thread);
6363
static void enter(Handle obj, BasicLock* lock, JavaThread* current);
64-
static void exit(oop object, BasicLock* lock, JavaThread* current);
64+
static void exit(oop object, JavaThread* current);
6565

6666
static ObjectMonitor* inflate_into_object_header(oop object, ObjectSynchronizer::InflateCause cause, JavaThread* locking_thread, Thread* current);
6767
static ObjectMonitor* inflate_locked_or_imse(oop object, ObjectSynchronizer::InflateCause cause, TRAPS);
6868
static ObjectMonitor* inflate_fast_locked_object(oop object, ObjectSynchronizer::InflateCause cause, JavaThread* locking_thread, JavaThread* current);
69-
static ObjectMonitor* inflate_and_enter(oop object, BasicLock* lock, ObjectSynchronizer::InflateCause cause, JavaThread* locking_thread, JavaThread* current);
69+
static ObjectMonitor* inflate_and_enter(oop object, ObjectSynchronizer::InflateCause cause, JavaThread* locking_thread, JavaThread* current);
7070

7171
static void deflate_monitor(Thread* current, oop obj, ObjectMonitor* monitor);
7272

src/hotspot/share/runtime/objectMonitor.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ class ObjectWaiter : public CHeapObj<mtThread> {
148148
#define OM_CACHE_LINE_SIZE DEFAULT_CACHE_LINE_SIZE
149149

150150
class ObjectMonitor : public CHeapObj<mtObjectMonitor> {
151-
friend class LightweightSynchronizer;
152151
friend class ObjectSynchronizer;
153152
friend class ObjectWaiter;
154153
friend class VMStructs;

src/hotspot/share/runtime/synchronizer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,7 @@ void ObjectSynchronizer::jni_enter(Handle obj, JavaThread* current) {
678678
ObjectMonitor* monitor;
679679
bool entered;
680680
if (LockingMode == LM_LIGHTWEIGHT) {
681-
BasicLock lock;
682-
entered = LightweightSynchronizer::inflate_and_enter(obj(), &lock, inflate_cause_jni_enter, current, current) != nullptr;
681+
entered = LightweightSynchronizer::inflate_and_enter(obj(), inflate_cause_jni_enter, current, current) != nullptr;
683682
} else {
684683
monitor = inflate(current, obj(), inflate_cause_jni_enter);
685684
entered = monitor->enter(current);

src/hotspot/share/runtime/synchronizer.inline.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ inline void ObjectSynchronizer::exit(oop object, BasicLock* lock, JavaThread* cu
7272
current->dec_held_monitor_count();
7373

7474
if (LockingMode == LM_LIGHTWEIGHT) {
75-
LightweightSynchronizer::exit(object, lock, current);
75+
LightweightSynchronizer::exit(object, current);
7676
} else {
7777
exit_legacy(object, lock, current);
7878
}

0 commit comments

Comments
 (0)