Skip to content

Commit 77a0f39

Browse files
committed
8253540: InterpreterRuntime::monitorexit should be a JRT_LEAF function
Reviewed-by: rehn, mdoerr, dcubed, pchilanomate
1 parent 0054c15 commit 77a0f39

File tree

10 files changed

+45
-64
lines changed

10 files changed

+45
-64
lines changed

src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,7 @@ void InterpreterMacroAssembler::unlock_object(Register lock_reg)
812812
assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1");
813813

814814
if (UseHeavyMonitors) {
815-
call_VM(noreg,
816-
CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
817-
lock_reg);
815+
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
818816
} else {
819817
Label done;
820818

@@ -850,9 +848,7 @@ void InterpreterMacroAssembler::unlock_object(Register lock_reg)
850848

851849
// Call the runtime routine for slow case.
852850
str(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes())); // restore obj
853-
call_VM(noreg,
854-
CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
855-
lock_reg);
851+
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
856852

857853
bind(done);
858854

src/hotspot/cpu/arm/interp_masm_arm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ void InterpreterMacroAssembler::unlock_object(Register Rlock) {
990990
assert(Rlock == R1, "the second argument");
991991

992992
if (UseHeavyMonitors) {
993-
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), Rlock);
993+
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), Rlock);
994994
} else {
995995
Label done, slow_case;
996996

@@ -1031,7 +1031,7 @@ void InterpreterMacroAssembler::unlock_object(Register Rlock) {
10311031

10321032
// Call the runtime routine for slow case.
10331033
str(Robj, Address(Rlock, obj_offset)); // restore obj
1034-
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), Rlock);
1034+
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), Rlock);
10351035

10361036
bind(done);
10371037
}

src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -997,8 +997,7 @@ void InterpreterMacroAssembler::lock_object(Register monitor, Register object) {
997997
// Throw IllegalMonitorException if object is not locked by current thread.
998998
void InterpreterMacroAssembler::unlock_object(Register monitor, bool check_for_exceptions) {
999999
if (UseHeavyMonitors) {
1000-
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
1001-
monitor, check_for_exceptions);
1000+
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);
10021001
} else {
10031002

10041003
// template code:
@@ -1011,7 +1010,7 @@ void InterpreterMacroAssembler::unlock_object(Register monitor, bool check_for_e
10111010
// monitor->set_obj(NULL);
10121011
// } else {
10131012
// // Slow path.
1014-
// InterpreterRuntime::monitorexit(THREAD, monitor);
1013+
// InterpreterRuntime::monitorexit(monitor);
10151014
// }
10161015

10171016
const Register object = R7_ARG5;
@@ -1065,13 +1064,12 @@ void InterpreterMacroAssembler::unlock_object(Register monitor, bool check_for_e
10651064

10661065
// } else {
10671066
// // Slow path.
1068-
// InterpreterRuntime::monitorexit(THREAD, monitor);
1067+
// InterpreterRuntime::monitorexit(monitor);
10691068

10701069
// The lock has been converted into a heavy lock and hence
10711070
// we need to get into the slow case.
10721071
bind(slow_case);
1073-
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
1074-
monitor, check_for_exceptions);
1072+
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);
10751073
// }
10761074

10771075
Label done;

src/hotspot/cpu/s390/interp_masm_s390.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ void InterpreterMacroAssembler::lock_object(Register monitor, Register object) {
10801080
void InterpreterMacroAssembler::unlock_object(Register monitor, Register object) {
10811081

10821082
if (UseHeavyMonitors) {
1083-
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);
1083+
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);
10841084
return;
10851085
}
10861086

@@ -1095,7 +1095,7 @@ void InterpreterMacroAssembler::unlock_object(Register monitor, Register object)
10951095
// monitor->set_obj(NULL);
10961096
// } else {
10971097
// // Slow path.
1098-
// InterpreterRuntime::monitorexit(THREAD, monitor);
1098+
// InterpreterRuntime::monitorexit(monitor);
10991099
// }
11001100

11011101
const Register displaced_header = Z_ARG4;
@@ -1149,12 +1149,12 @@ void InterpreterMacroAssembler::unlock_object(Register monitor, Register object)
11491149

11501150
// } else {
11511151
// // Slow path.
1152-
// InterpreterRuntime::monitorexit(THREAD, monitor);
1152+
// InterpreterRuntime::monitorexit(monitor);
11531153

11541154
// The lock has been converted into a heavy lock and hence
11551155
// we need to get into the slow case.
11561156
z_stg(object, obj_entry); // Restore object entry, has been cleared above.
1157-
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);
1157+
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);
11581158

11591159
// }
11601160

src/hotspot/cpu/x86/interp_masm_x86.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,9 +1281,7 @@ void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
12811281
"The argument is only for looks. It must be c_rarg1");
12821282

12831283
if (UseHeavyMonitors) {
1284-
call_VM(noreg,
1285-
CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
1286-
lock_reg);
1284+
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
12871285
} else {
12881286
Label done;
12891287

@@ -1324,12 +1322,10 @@ void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
13241322
// zero for simple unlock of a stack-lock case
13251323
jcc(Assembler::zero, done);
13261324

1325+
13271326
// Call the runtime routine for slow case.
1328-
movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()),
1329-
obj_reg); // restore obj
1330-
call_VM(noreg,
1331-
CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
1332-
lock_reg);
1327+
movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), obj_reg); // restore obj
1328+
call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
13331329

13341330
bind(done);
13351331

src/hotspot/cpu/zero/zeroInterpreter_zero.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,8 @@ int ZeroInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) {
459459
if (header.to_pointer() != NULL) {
460460
markWord old_header = markWord::encode(lock);
461461
if (rcvr->cas_set_mark(header, old_header) != old_header) {
462-
monitor->set_obj(rcvr); {
463-
HandleMark hm(thread);
464-
CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor));
465-
}
462+
monitor->set_obj(rcvr);
463+
InterpreterRuntime::monitorexit(monitor);
466464
}
467465
}
468466
}

src/hotspot/share/interpreter/interpreterRuntime.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -733,24 +733,21 @@ JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, Ba
733733
JRT_END
734734

735735

736-
//%note monitor_1
737-
JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorexit(JavaThread* thread, BasicObjectLock* elem))
738-
#ifdef ASSERT
739-
thread->last_frame().interpreter_frame_verify_monitor(elem);
740-
#endif
741-
Handle h_obj(thread, elem->obj());
742-
assert(Universe::heap()->is_in_or_null(h_obj()),
743-
"must be NULL or an object");
744-
if (elem == NULL || h_obj()->is_unlocked()) {
745-
THROW(vmSymbols::java_lang_IllegalMonitorStateException());
736+
JRT_LEAF(void, InterpreterRuntime::monitorexit(BasicObjectLock* elem))
737+
oop obj = elem->obj();
738+
assert(Universe::heap()->is_in(obj), "must be an object");
739+
// The object could become unlocked through a JNI call, which we have no other checks for.
740+
// Give a fatal message if CheckJNICalls. Otherwise we ignore it.
741+
if (obj->is_unlocked()) {
742+
if (CheckJNICalls) {
743+
fatal("Object has been unlocked by JNI");
744+
}
745+
return;
746746
}
747-
ObjectSynchronizer::exit(h_obj(), elem->lock(), thread);
748-
// Free entry. This must be done here, since a pending exception might be installed on
749-
// exit. If it is not cleared, the exception handling code will try to unlock the monitor again.
747+
ObjectSynchronizer::exit(obj, elem->lock(), Thread::current());
748+
// Free entry. If it is not cleared, the exception handling code will try to unlock the monitor
749+
// again at method exit or in the case of an exception.
750750
elem->set_obj(NULL);
751-
#ifdef ASSERT
752-
thread->last_frame().interpreter_frame_verify_monitor(elem);
753-
#endif
754751
JRT_END
755752

756753

src/hotspot/share/interpreter/interpreterRuntime.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class InterpreterRuntime: AllStatic {
101101
public:
102102
// Synchronization
103103
static void monitorenter(JavaThread* thread, BasicObjectLock* elem);
104-
static void monitorexit (JavaThread* thread, BasicObjectLock* elem);
104+
static void monitorexit (BasicObjectLock* elem);
105105

106106
static void throw_illegal_monitor_state_exception(JavaThread* thread);
107107
static void new_illegal_monitor_state_exception(JavaThread* thread);

src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ BytecodeInterpreter::run(interpreterState istate) {
627627
(* BiasedLocking::rebiased_lock_entry_count_addr())++;
628628
}
629629
} else {
630-
CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
630+
InterpreterRuntime::monitorenter(THREAD, mon);
631631
}
632632
success = true;
633633
} else {
@@ -1822,7 +1822,7 @@ BytecodeInterpreter::run(interpreterState istate) {
18221822
if (call_vm || lockee->cas_set_mark(header, old_header) != old_header) {
18231823
// restore object for the slow case
18241824
most_recent->set_obj(lockee);
1825-
CALL_VM(InterpreterRuntime::monitorexit(THREAD, most_recent), handle_exception);
1825+
InterpreterRuntime::monitorexit(most_recent);
18261826
}
18271827
}
18281828
}
@@ -2959,11 +2959,7 @@ BytecodeInterpreter::run(interpreterState istate) {
29592959
if (lockee->cas_set_mark(header, old_header) != old_header) {
29602960
// restore object for the slow case
29612961
end->set_obj(lockee);
2962-
{
2963-
// Prevent any HandleMarkCleaner from freeing our live handles
2964-
HandleMark __hm(THREAD);
2965-
CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, end));
2966-
}
2962+
InterpreterRuntime::monitorexit(end);
29672963
}
29682964
}
29692965
}
@@ -3013,11 +3009,7 @@ BytecodeInterpreter::run(interpreterState istate) {
30133009
THREAD->clear_pending_exception();
30143010
}
30153011
} else if (UseHeavyMonitors) {
3016-
{
3017-
// Prevent any HandleMarkCleaner from freeing our live handles.
3018-
HandleMark __hm(THREAD);
3019-
CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, base));
3020-
}
3012+
InterpreterRuntime::monitorexit(base);
30213013
if (THREAD->has_pending_exception()) {
30223014
if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
30233015
THREAD->clear_pending_exception();
@@ -3035,11 +3027,7 @@ BytecodeInterpreter::run(interpreterState istate) {
30353027
if (rcvr->cas_set_mark(header, old_header) != old_header) {
30363028
// restore object for the slow case
30373029
base->set_obj(rcvr);
3038-
{
3039-
// Prevent any HandleMarkCleaner from freeing our live handles
3040-
HandleMark __hm(THREAD);
3041-
CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, base));
3042-
}
3030+
InterpreterRuntime::monitorexit(base);
30433031
if (THREAD->has_pending_exception()) {
30443032
if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
30453033
THREAD->clear_pending_exception();

src/hotspot/share/runtime/sharedRuntime.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,14 @@ void SharedRuntime::monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThrea
20972097
assert(JavaThread::current() == thread, "invariant");
20982098
// Exit must be non-blocking, and therefore no exceptions can be thrown.
20992099
EXCEPTION_MARK;
2100+
// The object could become unlocked through a JNI call, which we have no other checks for.
2101+
// Give a fatal message if CheckJNICalls. Otherwise we ignore it.
2102+
if (obj->is_unlocked()) {
2103+
if (CheckJNICalls) {
2104+
fatal("Object has been unlocked by JNI");
2105+
}
2106+
return;
2107+
}
21002108
ObjectSynchronizer::exit(obj, lock, THREAD);
21012109
}
21022110

0 commit comments

Comments
 (0)