--- old/src/hotspot/share/c1/c1_Runtime1.cpp 2020-03-30 15:59:24.000000000 +0200 +++ new/src/hotspot/share/c1/c1_Runtime1.cpp 2020-03-30 15:59:24.000000000 +0200 @@ -699,30 +699,22 @@ JRT_END -JRT_ENTRY_NO_ASYNC(void, Runtime1::monitorenter(JavaThread* thread, oopDesc* obj, BasicObjectLock* lock)) +JRT_BLOCK_ENTRY(void, Runtime1::monitorenter(JavaThread* thread, oopDesc* obj, BasicObjectLock* lock)) NOT_PRODUCT(_monitorenter_slowcase_cnt++;) - if (PrintBiasedLockingStatistics) { - Atomic::inc(BiasedLocking::slow_path_entry_count_addr()); - } - Handle h_obj(thread, obj); if (!UseFastLocking) { lock->set_obj(obj); } assert(obj == lock->obj(), "must match"); - ObjectSynchronizer::enter(h_obj, lock->lock(), THREAD); + SharedRuntime::monitor_enter_helper(obj, lock->lock(), thread); JRT_END JRT_LEAF(void, Runtime1::monitorexit(JavaThread* thread, BasicObjectLock* lock)) NOT_PRODUCT(_monitorexit_slowcase_cnt++;) - assert(thread == JavaThread::current(), "threads must correspond"); assert(thread->last_Java_sp(), "last_Java_sp must be set"); - // monitorexit is non-blocking (leaf routine) => no exceptions can be thrown - EXCEPTION_MARK; - oop obj = lock->obj(); assert(oopDesc::is_oop(obj), "must be NULL or an object"); - ObjectSynchronizer::exit(obj, lock->lock(), THREAD); + SharedRuntime::monitor_exit_helper(obj, lock->lock(), thread); JRT_END // Cf. OptoRuntime::deoptimize_caller_frame --- old/src/hotspot/share/jvmci/jvmciRuntime.cpp 2020-03-30 15:59:25.000000000 +0200 +++ new/src/hotspot/share/jvmci/jvmciRuntime.cpp 2020-03-30 15:59:25.000000000 +0200 @@ -382,48 +382,14 @@ return continuation; } -JRT_ENTRY_NO_ASYNC(void, JVMCIRuntime::monitorenter(JavaThread* thread, oopDesc* obj, BasicLock* lock)) - IF_TRACE_jvmci_3 { - char type[O_BUFLEN]; - obj->klass()->name()->as_C_string(type, O_BUFLEN); - markWord mark = obj->mark(); - TRACE_jvmci_3("%s: entered locking slow case with obj=" INTPTR_FORMAT ", type=%s, mark=" INTPTR_FORMAT ", lock=" INTPTR_FORMAT, thread->name(), p2i(obj), type, mark.value(), p2i(lock)); - tty->flush(); - } - if (PrintBiasedLockingStatistics) { - Atomic::inc(BiasedLocking::slow_path_entry_count_addr()); - } - Handle h_obj(thread, obj); - assert(oopDesc::is_oop(h_obj()), "must be NULL or an object"); - ObjectSynchronizer::enter(h_obj, lock, THREAD); - TRACE_jvmci_3("%s: exiting locking slow with obj=" INTPTR_FORMAT, thread->name(), p2i(obj)); +JRT_BLOCK_ENTRY(void, JVMCIRuntime::monitorenter(JavaThread* thread, oopDesc* obj, BasicLock* lock)) + SharedRuntime::monitor_enter_helper(obj, lock, thread); JRT_END JRT_LEAF(void, JVMCIRuntime::monitorexit(JavaThread* thread, oopDesc* obj, BasicLock* lock)) - assert(thread == JavaThread::current(), "threads must correspond"); assert(thread->last_Java_sp(), "last_Java_sp must be set"); - // monitorexit is non-blocking (leaf routine) => no exceptions can be thrown - EXCEPTION_MARK; - -#ifdef ASSERT - if (!oopDesc::is_oop(obj)) { - ResetNoHandleMark rhm; - nmethod* method = thread->last_frame().cb()->as_nmethod_or_null(); - if (method != NULL) { - tty->print_cr("ERROR in monitorexit in method %s wrong obj " INTPTR_FORMAT, method->name(), p2i(obj)); - } - thread->print_stack_on(tty); - assert(false, "invalid lock object pointer dected"); - } -#endif - - ObjectSynchronizer::exit(obj, lock, THREAD); - IF_TRACE_jvmci_3 { - char type[O_BUFLEN]; - obj->klass()->name()->as_C_string(type, O_BUFLEN); - TRACE_jvmci_3("%s: exited locking slow case with obj=" INTPTR_FORMAT ", type=%s, mark=" INTPTR_FORMAT ", lock=" INTPTR_FORMAT, thread->name(), p2i(obj), type, obj->mark().value(), p2i(lock)); - tty->flush(); - } + assert(oopDesc::is_oop(obj), "invalid lock object pointer dected"); + SharedRuntime::monitor_exit_helper(obj, lock, thread); JRT_END // Object.notify() fast path, caller does slow path --- old/src/hotspot/share/runtime/sharedRuntime.cpp 2020-03-30 15:59:26.000000000 +0200 +++ new/src/hotspot/share/runtime/sharedRuntime.cpp 2020-03-30 15:59:26.000000000 +0200 @@ -2072,20 +2072,17 @@ (void) JavaThread::current()->reguard_stack(); JRT_END - -// Handles the uncommon case in locking, i.e., contention or an inflated lock. -JRT_BLOCK_ENTRY(void, SharedRuntime::complete_monitor_locking_C(oopDesc* _obj, BasicLock* lock, JavaThread* thread)) +void SharedRuntime::monitor_enter_helper(oopDesc* obj, BasicLock* lock, JavaThread* thread) { if (!SafepointSynchronize::is_synchronizing()) { // Only try quick_enter() if we're not trying to reach a safepoint // so that the calling thread reaches the safepoint more quickly. - if (ObjectSynchronizer::quick_enter(_obj, thread, lock)) return; + if (ObjectSynchronizer::quick_enter(obj, thread, lock)) return; } // NO_ASYNC required because an async exception on the state transition destructor // would leave you with the lock held and it would never be released. // The normal monitorenter NullPointerException is thrown without acquiring a lock // and the model is that an exception implies the method failed. JRT_BLOCK_NO_ASYNC - oop obj(_obj); if (PrintBiasedLockingStatistics) { Atomic::inc(BiasedLocking::slow_path_entry_count_addr()); } @@ -2093,42 +2090,23 @@ ObjectSynchronizer::enter(h_obj, lock, CHECK); assert(!HAS_PENDING_EXCEPTION, "Should have no exception here"); JRT_BLOCK_END -JRT_END +} -// Handles the uncommon cases of monitor unlocking in compiled code -JRT_LEAF(void, SharedRuntime::complete_monitor_unlocking_C(oopDesc* _obj, BasicLock* lock, JavaThread * THREAD)) - oop obj(_obj); - assert(JavaThread::current() == THREAD, "invariant"); - // I'm not convinced we need the code contained by MIGHT_HAVE_PENDING anymore - // testing was unable to ever fire the assert that guarded it so I have removed it. - assert(!HAS_PENDING_EXCEPTION, "Do we need code below anymore?"); -#undef MIGHT_HAVE_PENDING -#ifdef MIGHT_HAVE_PENDING - // Save and restore any pending_exception around the exception mark. - // While the slow_exit must not throw an exception, we could come into - // this routine with one set. - oop pending_excep = NULL; - const char* pending_file; - int pending_line; - if (HAS_PENDING_EXCEPTION) { - pending_excep = PENDING_EXCEPTION; - pending_file = THREAD->exception_file(); - pending_line = THREAD->exception_line(); - CLEAR_PENDING_EXCEPTION; - } -#endif /* MIGHT_HAVE_PENDING */ +// Handles the uncommon case in locking, i.e., contention or an inflated lock. +JRT_BLOCK_ENTRY(void, SharedRuntime::complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* thread)) + SharedRuntime::monitor_enter_helper(obj, lock, thread); +JRT_END - { - // Exit must be non-blocking, and therefore no exceptions can be thrown. - EXCEPTION_MARK; - ObjectSynchronizer::exit(obj, lock, THREAD); - } +void SharedRuntime::monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThread* thread) { + assert(JavaThread::current() == thread, "invariant"); + // Exit must be non-blocking, and therefore no exceptions can be thrown. + EXCEPTION_MARK; + ObjectSynchronizer::exit(obj, lock, THREAD); +} -#ifdef MIGHT_HAVE_PENDING - if (pending_excep != NULL) { - THREAD->set_pending_exception(pending_excep, pending_file, pending_line); - } -#endif /* MIGHT_HAVE_PENDING */ +// Handles the uncommon cases of monitor unlocking in compiled code +JRT_LEAF(void, SharedRuntime::complete_monitor_unlocking_C(oopDesc* obj, BasicLock* lock, JavaThread* thread)) + SharedRuntime::monitor_exit_helper(obj, lock, thread); JRT_END #ifndef PRODUCT --- old/src/hotspot/share/runtime/sharedRuntime.hpp 2020-03-30 15:59:27.000000000 +0200 +++ new/src/hotspot/share/runtime/sharedRuntime.hpp 2020-03-30 15:59:26.000000000 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -341,6 +341,9 @@ // Find the method that called us. static methodHandle find_callee_method(JavaThread* thread, TRAPS); + static void monitor_enter_helper(oopDesc* obj, BasicLock* lock, JavaThread* thread); + + static void monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThread* thread); private: static Handle find_callee_info(JavaThread* thread,