Skip to content

Commit c8fa3e2

Browse files
committed
8320310: CompiledMethod::has_monitors flag can be incorrect
Reviewed-by: vlivanov, thartmann
1 parent 57a65fe commit c8fa3e2

File tree

5 files changed

+31
-39
lines changed

5 files changed

+31
-39
lines changed

src/hotspot/share/c1/c1_Compilation.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,6 @@ int Compilation::compile_java_method() {
390390
BAILOUT_("mdo allocation failed", no_frame_size);
391391
}
392392

393-
if (method()->is_synchronized()) {
394-
set_has_monitors(true);
395-
}
396-
397393
{
398394
PhaseTraceTime timeit(_t_buildIR);
399395
build_hir();
@@ -581,7 +577,7 @@ Compilation::Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* metho
581577
, _would_profile(false)
582578
, _has_method_handle_invokes(false)
583579
, _has_reserved_stack_access(method->has_reserved_stack_access())
584-
, _has_monitors(false)
580+
, _has_monitors(method->is_synchronized() || method->has_monitor_bytecodes())
585581
, _install_code(install_code)
586582
, _bailout_msg(nullptr)
587583
, _first_failure_details(nullptr)

src/hotspot/share/c1/c1_GraphBuilder.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,7 +2316,6 @@ void GraphBuilder::instance_of(int klass_index) {
23162316
void GraphBuilder::monitorenter(Value x, int bci) {
23172317
// save state before locking in case of deoptimization after a NullPointerException
23182318
ValueStack* state_before = copy_state_for_exception_with_bci(bci);
2319-
compilation()->set_has_monitors(true);
23202319
append_with_bci(new MonitorEnter(x, state()->lock(x), state_before), bci);
23212320
kill_all();
23222321
}
@@ -3510,6 +3509,15 @@ int GraphBuilder::recursive_inline_level(ciMethod* cur_callee) const {
35103509
return recur_level;
35113510
}
35123511

3512+
static void set_flags_for_inlined_callee(Compilation* compilation, ciMethod* callee) {
3513+
if (callee->has_reserved_stack_access()) {
3514+
compilation->set_has_reserved_stack_access(true);
3515+
}
3516+
if (callee->is_synchronized() || callee->has_monitor_bytecodes()) {
3517+
compilation->set_has_monitors(true);
3518+
}
3519+
}
3520+
35133521
bool GraphBuilder::try_inline(ciMethod* callee, bool holder_known, bool ignore_return, Bytecodes::Code bc, Value receiver) {
35143522
const char* msg = nullptr;
35153523

@@ -3526,9 +3534,7 @@ bool GraphBuilder::try_inline(ciMethod* callee, bool holder_known, bool ignore_r
35263534
// method handle invokes
35273535
if (callee->is_method_handle_intrinsic()) {
35283536
if (try_method_handle_inline(callee, ignore_return)) {
3529-
if (callee->has_reserved_stack_access()) {
3530-
compilation()->set_has_reserved_stack_access(true);
3531-
}
3537+
set_flags_for_inlined_callee(compilation(), callee);
35323538
return true;
35333539
}
35343540
return false;
@@ -3539,9 +3545,7 @@ bool GraphBuilder::try_inline(ciMethod* callee, bool holder_known, bool ignore_r
35393545
callee->check_intrinsic_candidate()) {
35403546
if (try_inline_intrinsics(callee, ignore_return)) {
35413547
print_inlining(callee, "intrinsic");
3542-
if (callee->has_reserved_stack_access()) {
3543-
compilation()->set_has_reserved_stack_access(true);
3544-
}
3548+
set_flags_for_inlined_callee(compilation(), callee);
35453549
return true;
35463550
}
35473551
// try normal inlining
@@ -3559,9 +3563,7 @@ bool GraphBuilder::try_inline(ciMethod* callee, bool holder_known, bool ignore_r
35593563
bc = code();
35603564
}
35613565
if (try_inline_full(callee, holder_known, ignore_return, bc, receiver)) {
3562-
if (callee->has_reserved_stack_access()) {
3563-
compilation()->set_has_reserved_stack_access(true);
3564-
}
3566+
set_flags_for_inlined_callee(compilation(), callee);
35653567
return true;
35663568
}
35673569

src/hotspot/share/opto/locknode.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ void FastLockNode::create_rtm_lock_counter(JVMState* state) {
179179
void Parse::do_monitor_enter() {
180180
kill_dead_locals();
181181

182-
C->set_has_monitors(true);
183-
184182
// Null check; get casted pointer.
185183
Node* obj = null_check(peek());
186184
// Check for locking null object
@@ -198,10 +196,6 @@ void Parse::do_monitor_enter() {
198196
void Parse::do_monitor_exit() {
199197
kill_dead_locals();
200198

201-
// need to set it for monitor exit as well.
202-
// OSR compiled methods can start with lock taken
203-
C->set_has_monitors(true);
204-
205199
pop(); // Pop oop to unlock
206200
// Because monitors are guaranteed paired (else we bail out), we know
207201
// the matching Lock for this Unlock. Hence we know there is no need

src/hotspot/share/opto/parse1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ Parse::Parse(JVMState* caller, ciMethod* parse_method, float expected_uses)
423423
C->set_has_reserved_stack_access(true);
424424
}
425425

426-
if (parse_method->is_synchronized()) {
426+
if (parse_method->is_synchronized() || parse_method->has_monitor_bytecodes()) {
427427
C->set_has_monitors(true);
428428
}
429429

src/hotspot/share/runtime/continuationFreezeThaw.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,21 +1498,21 @@ static void jvmti_yield_cleanup(JavaThread* thread, ContinuationWrapper& cont) {
14981498
#endif // INCLUDE_JVMTI
14991499

15001500
#ifdef ASSERT
1501-
// static bool monitors_on_stack(JavaThread* thread) {
1502-
// ContinuationEntry* ce = thread->last_continuation();
1503-
// RegisterMap map(thread,
1504-
// RegisterMap::UpdateMap::include,
1505-
// RegisterMap::ProcessFrames::include,
1506-
// RegisterMap::WalkContinuation::skip);
1507-
// map.set_include_argument_oops(false);
1508-
// for (frame f = thread->last_frame(); Continuation::is_frame_in_continuation(ce, f); f = f.sender(&map)) {
1509-
// if ((f.is_interpreted_frame() && ContinuationHelper::InterpretedFrame::is_owning_locks(f)) ||
1510-
// (f.is_compiled_frame() && ContinuationHelper::CompiledFrame::is_owning_locks(map.thread(), &map, f))) {
1511-
// return true;
1512-
// }
1513-
// }
1514-
// return false;
1515-
// }
1501+
static bool monitors_on_stack(JavaThread* thread) {
1502+
ContinuationEntry* ce = thread->last_continuation();
1503+
RegisterMap map(thread,
1504+
RegisterMap::UpdateMap::include,
1505+
RegisterMap::ProcessFrames::include,
1506+
RegisterMap::WalkContinuation::skip);
1507+
map.set_include_argument_oops(false);
1508+
for (frame f = thread->last_frame(); Continuation::is_frame_in_continuation(ce, f); f = f.sender(&map)) {
1509+
if ((f.is_interpreted_frame() && ContinuationHelper::InterpretedFrame::is_owning_locks(f)) ||
1510+
(f.is_compiled_frame() && ContinuationHelper::CompiledFrame::is_owning_locks(map.thread(), &map, f))) {
1511+
return true;
1512+
}
1513+
}
1514+
return false;
1515+
}
15161516

15171517
bool FreezeBase::interpreted_native_or_deoptimized_on_stack() {
15181518
ContinuationEntry* ce = _thread->last_continuation();
@@ -1575,8 +1575,8 @@ static inline int freeze_internal(JavaThread* current, intptr_t* const sp) {
15751575

15761576
assert(entry->is_virtual_thread() == (entry->scope(current) == java_lang_VirtualThread::vthread_scope()), "");
15771577

1578-
// assert(monitors_on_stack(current) == ((current->held_monitor_count() - current->jni_monitor_count()) > 0),
1579-
// "Held monitor count and locks on stack invariant: " INT64_FORMAT " JNI: " INT64_FORMAT, (int64_t)current->held_monitor_count(), (int64_t)current->jni_monitor_count());
1578+
assert(monitors_on_stack(current) == ((current->held_monitor_count() - current->jni_monitor_count()) > 0),
1579+
"Held monitor count and locks on stack invariant: " INT64_FORMAT " JNI: " INT64_FORMAT, (int64_t)current->held_monitor_count(), (int64_t)current->jni_monitor_count());
15801580

15811581
if (entry->is_pinned() || current->held_monitor_count() > 0) {
15821582
log_develop_debug(continuations)("PINNED due to critical section/hold monitor");

0 commit comments

Comments
 (0)