@@ -633,7 +633,7 @@ void LightweightSynchronizer::enter_for(Handle obj, BasicLock* lock, JavaThread*
633
633
} else {
634
634
do {
635
635
// 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);
637
637
// But there may still be a race with deflation.
638
638
} while (monitor == nullptr );
639
639
}
@@ -689,7 +689,7 @@ void LightweightSynchronizer::enter(Handle obj, BasicLock* lock, JavaThread* cur
689
689
spin_yield.wait ();
690
690
}
691
691
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);
693
693
if (monitor != nullptr ) {
694
694
cache_setter.set_monitor (monitor);
695
695
return ;
@@ -703,7 +703,7 @@ void LightweightSynchronizer::enter(Handle obj, BasicLock* lock, JavaThread* cur
703
703
}
704
704
}
705
705
706
- void LightweightSynchronizer::exit (oop object, BasicLock* lock, JavaThread* current) {
706
+ void LightweightSynchronizer::exit (oop object, JavaThread* current) {
707
707
assert (LockingMode == LM_LIGHTWEIGHT, " must be" );
708
708
assert (current == Thread::current (), " must be" );
709
709
@@ -738,18 +738,7 @@ void LightweightSynchronizer::exit(oop object, BasicLock* lock, JavaThread* curr
738
738
739
739
assert (mark.has_monitor (), " must be" );
740
740
// 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);
753
742
if (monitor->has_anonymous_owner ()) {
754
743
assert (current->lock_stack ().contains (object), " current must have object on its lock stack" );
755
744
monitor->set_owner_from_anonymous (current);
@@ -988,7 +977,7 @@ ObjectMonitor* LightweightSynchronizer::inflate_fast_locked_object(oop object, O
988
977
return monitor;
989
978
}
990
979
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) {
992
981
assert (LockingMode == LM_LIGHTWEIGHT, " only used for lightweight" );
993
982
VerifyThreadState vts (locking_thread, current);
994
983
@@ -1014,20 +1003,18 @@ ObjectMonitor* LightweightSynchronizer::inflate_and_enter(oop object, BasicLock*
1014
1003
1015
1004
NoSafepointVerifier nsv;
1016
1005
1006
+ // Lightweight monitors require that hash codes are installed first
1007
+ ObjectSynchronizer::FastHashCode (locking_thread, object);
1008
+
1017
1009
// Try to get the monitor from the thread-local cache.
1018
1010
// There's no need to use the cache if we are locking
1019
1011
// on behalf of another thread.
1020
1012
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);
1025
1014
}
1026
1015
1027
1016
// Get or create the monitor
1028
1017
if (monitor == nullptr ) {
1029
- // Lightweight monitors require that hash codes are installed first
1030
- ObjectSynchronizer::FastHashCode (locking_thread, object);
1031
1018
monitor = get_or_insert_monitor (object, current, cause);
1032
1019
}
1033
1020
@@ -1175,6 +1162,9 @@ bool LightweightSynchronizer::quick_enter(oop obj, BasicLock* lock, JavaThread*
1175
1162
assert (obj != nullptr , " must be" );
1176
1163
NoSafepointVerifier nsv;
1177
1164
1165
+ // If quick_enter succeeds with entering, the cache should be in a valid initialized state.
1166
+ CacheSetter cache_setter (current, lock);
1167
+
1178
1168
LockStack& lock_stack = current->lock_stack ();
1179
1169
if (lock_stack.is_full ()) {
1180
1170
// Always go into runtime if the lock stack is full.
@@ -1201,28 +1191,17 @@ bool LightweightSynchronizer::quick_enter(oop obj, BasicLock* lock, JavaThread*
1201
1191
#endif
1202
1192
1203
1193
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);
1215
1196
1216
1197
if (monitor == nullptr ) {
1217
1198
// Take the slow-path on a cache miss.
1218
1199
return false ;
1219
1200
}
1220
1201
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);
1226
1205
return true ;
1227
1206
}
1228
1207
}
0 commit comments