Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/hotspot/share/interpreter/interpreterRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,13 +646,13 @@ JRT_END
// Fields
//

void InterpreterRuntime::resolve_get_put(JavaThread* current, Bytecodes::Code bytecode) {
JavaThread* THREAD = current;
void InterpreterRuntime::resolve_get_put(Bytecodes::Code bytecode, TRAPS) {
JavaThread* current = THREAD;
LastFrameAccessor last_frame(current);
constantPoolHandle pool(current, last_frame.method()->constants());
methodHandle m(current, last_frame.method());

resolve_get_put(bytecode, last_frame.get_index_u2(bytecode), m, pool, ClassInitMode::init_preemptable, CHECK_AND_CLEAR_PREEMPTED);
resolve_get_put(bytecode, last_frame.get_index_u2(bytecode), m, pool, ClassInitMode::init_preemptable, THREAD);
}

void InterpreterRuntime::resolve_get_put(Bytecodes::Code bytecode, int field_index,
Expand Down Expand Up @@ -794,7 +794,8 @@ JRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* current, Method* met
JvmtiExport::post_raw_breakpoint(current, method, bcp);
JRT_END

void InterpreterRuntime::resolve_invoke(JavaThread* current, Bytecodes::Code bytecode) {
void InterpreterRuntime::resolve_invoke(Bytecodes::Code bytecode, TRAPS) {
JavaThread* current = THREAD;
LastFrameAccessor last_frame(current);
// extract receiver from the outgoing argument list if necessary
Handle receiver(current, nullptr);
Expand Down Expand Up @@ -822,7 +823,6 @@ void InterpreterRuntime::resolve_invoke(JavaThread* current, Bytecodes::Code byt
int method_index = last_frame.get_index_u2(bytecode);
{
JvmtiHideSingleStepping jhss(current);
JavaThread* THREAD = current; // For exception macros.
LinkResolver::resolve_invoke(info, receiver, pool,
method_index, bytecode,
ClassInitMode::init_preemptable, THREAD);
Expand All @@ -834,7 +834,6 @@ void InterpreterRuntime::resolve_invoke(JavaThread* current, Bytecodes::Code byt
// Recording the trap will help the compiler to potentially recognize this exception as "hot"
note_trap(current, Deoptimization::Reason_null_check);
}
CLEAR_PENDING_PREEMPTED_EXCEPTION;
return;
}

Expand Down Expand Up @@ -933,7 +932,8 @@ void InterpreterRuntime::cds_resolve_invoke(Bytecodes::Code bytecode, int method
}

// First time execution: Resolve symbols, create a permanent MethodType object.
void InterpreterRuntime::resolve_invokehandle(JavaThread* current) {
void InterpreterRuntime::resolve_invokehandle(TRAPS) {
JavaThread* current = THREAD;
const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
LastFrameAccessor last_frame(current);

Expand Down Expand Up @@ -962,7 +962,8 @@ void InterpreterRuntime::cds_resolve_invokehandle(int raw_index,
}

// First time execution: Resolve symbols, create a permanent CallSite object.
void InterpreterRuntime::resolve_invokedynamic(JavaThread* current) {
void InterpreterRuntime::resolve_invokedynamic(TRAPS) {
JavaThread* current = THREAD;
LastFrameAccessor last_frame(current);
const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;

Expand Down Expand Up @@ -997,19 +998,19 @@ JRT_ENTRY(void, InterpreterRuntime::resolve_from_cache(JavaThread* current, Byte
case Bytecodes::_putstatic:
case Bytecodes::_getfield:
case Bytecodes::_putfield:
resolve_get_put(current, bytecode);
resolve_get_put(bytecode, CHECK_AND_CLEAR_PREEMPTED);
break;
case Bytecodes::_invokevirtual:
case Bytecodes::_invokespecial:
case Bytecodes::_invokestatic:
case Bytecodes::_invokeinterface:
resolve_invoke(current, bytecode);
resolve_invoke(bytecode, CHECK_AND_CLEAR_PREEMPTED);
break;
case Bytecodes::_invokehandle:
resolve_invokehandle(current);
resolve_invokehandle(THREAD);
break;
case Bytecodes::_invokedynamic:
resolve_invokedynamic(current);
resolve_invokedynamic(THREAD);
break;
default:
fatal("unexpected bytecode: %s", Bytecodes::name(bytecode));
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/interpreter/interpreterRuntime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ class InterpreterRuntime: AllStatic {
constantPoolHandle& pool, TRAPS);
private:
// Statics & fields
static void resolve_get_put(JavaThread* current, Bytecodes::Code bytecode);
static void resolve_get_put(Bytecodes::Code bytecode, TRAPS);

// Calls
static void resolve_invoke(JavaThread* current, Bytecodes::Code bytecode);
static void resolve_invokehandle (JavaThread* current);
static void resolve_invokedynamic(JavaThread* current);
static void resolve_invoke(Bytecodes::Code bytecode, TRAPS);
static void resolve_invokehandle (TRAPS);
static void resolve_invokedynamic(TRAPS);

static void update_invoke_cp_cache_entry(CallInfo& info, Bytecodes::Code bytecode,
methodHandle& resolved_method,
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/interpreter/linkResolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class LinkInfo : public StackObj {
void print() PRODUCT_RETURN;
};

enum class ClassInitMode : uint8_t {
enum class ClassInitMode {
dont_init,
init,
init_preemptable
Expand Down
30 changes: 29 additions & 1 deletion src/hotspot/share/oops/instanceKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,9 +805,26 @@ void InstanceKlass::fence_and_clear_init_lock() {
assert(!is_not_initialized(), "class must be initialized now");
}

class PreemptableInitCall {
JavaThread* _thread;
bool _previous;
DEBUG_ONLY(InstanceKlass* _previous_klass;)
public:
PreemptableInitCall(JavaThread* thread, InstanceKlass* ik) : _thread(thread) {
_previous = thread->at_preemptable_init();
_thread->set_at_preemptable_init(true);
DEBUG_ONLY(_previous_klass = _thread->preempt_init_klass();)
DEBUG_ONLY(_thread->set_preempt_init_klass(ik));
}
~PreemptableInitCall() {
_thread->set_at_preemptable_init(_previous);
DEBUG_ONLY(_thread->set_preempt_init_klass(_previous_klass));
}
};

void InstanceKlass::initialize_preemptable(TRAPS) {
if (this->should_be_initialized()) {
PREEMPT_ON_INIT_SUPPORTED_ONLY(PreemptableInitCall pic(THREAD, this);)
PreemptableInitCall pic(THREAD, this);
initialize_impl(THREAD);
} else {
assert(is_initialized(), "sanity check");
Expand Down Expand Up @@ -1188,6 +1205,17 @@ void InstanceKlass::clean_initialization_error_table() {
}
}

class ThreadWaitingForClassInit : public StackObj {
JavaThread* _thread;
public:
ThreadWaitingForClassInit(JavaThread* thread, InstanceKlass* ik) : _thread(thread) {
_thread->set_class_to_be_initialized(ik);
}
~ThreadWaitingForClassInit() {
_thread->set_class_to_be_initialized(nullptr);
}
};

void InstanceKlass::initialize_impl(TRAPS) {
HandleMark hm(THREAD);

Expand Down
17 changes: 9 additions & 8 deletions src/hotspot/share/runtime/continuationFreezeThaw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,7 @@ class ThawBase : public StackObj {
DEBUG_ONLY(intptr_t* _top_stack_address);

// Only used for preemption on ObjectLocker
ObjectMonitor* _monitor;
ObjectMonitor* _init_lock;

StackChunkFrameStream<ChunkFrames::Mixed> _stream;

Expand Down Expand Up @@ -2383,11 +2383,12 @@ NOINLINE intptr_t* Thaw<ConfigT>::thaw_slow(stackChunkOop chunk, Continuation::t
_process_args_at_top = false;
_preempted_case = chunk->preempted();
if (_preempted_case) {
ObjectMonitor* mon = nullptr;
ObjectWaiter* waiter = java_lang_VirtualThread::objectWaiter(_thread->vthread());
if (waiter != nullptr) {
// Mounted again after preemption. Resume the pending monitor operation,
// which will be either a monitorenter or Object.wait() call.
ObjectMonitor* mon = waiter->monitor();
mon = waiter->monitor();
preempt_kind = waiter->is_wait() ? Continuation::object_wait : Continuation::monitorenter;

bool mon_acquired = mon->resume_operation(_thread, waiter, _cont);
Expand All @@ -2397,17 +2398,15 @@ NOINLINE intptr_t* Thaw<ConfigT>::thaw_slow(stackChunkOop chunk, Continuation::t
log_develop_trace(continuations, preempt)("Failed to acquire monitor, unmounting again");
return push_cleanup_continuation();
}
_monitor = mon; // remember monitor since we might need it on handle_preempted_continuation()
chunk = _cont.tail(); // reload oop in case of safepoint in resume_operation (if posting JVMTI events).
JVMTI_ONLY(assert(_thread->contended_entered_monitor() == nullptr || _thread->contended_entered_monitor() == _monitor, ""));
JVMTI_ONLY(assert(_thread->contended_entered_monitor() == nullptr || _thread->contended_entered_monitor() == mon, ""));
} else {
// Preemption cancelled on moniterenter or ObjectLocker case. We
// actually acquired the monitor after freezing all frames so no
// need to call resume_operation. If this is the ObjectLocker case
// we released the monitor already at ~ObjectLocker, so here we set
// _monitor to nullptr to indicate there is no need to release it later.
// we released the monitor already at ~ObjectLocker, so _init_lock
// will be set to nullptr below since there is no monitor to release.
preempt_kind = Continuation::monitorenter;
_monitor = nullptr;
}

// Call this first to avoid racing with GC threads later when modifying the chunk flags.
Expand All @@ -2421,6 +2420,8 @@ NOINLINE intptr_t* Thaw<ConfigT>::thaw_slow(stackChunkOop chunk, Continuation::t
// Only needed for the top frame which will be thawed.
chunk->set_has_args_at_top(false);
}
assert(waiter == nullptr || mon != nullptr, "should have a monitor");
_init_lock = mon; // remember monitor since we will need it on handle_preempted_continuation()
}
chunk->set_preempted(false);
retry_fast_path = true;
Expand Down Expand Up @@ -2671,7 +2672,7 @@ intptr_t* ThawBase::handle_preempted_continuation(intptr_t* sp, Continuation::pr
// to exit the monitor we just acquired (except on preemption cancelled
// case where it was already released).
assert(preempt_kind == Continuation::object_locker, "");
if (_monitor != nullptr) _monitor->exit(_thread);
if (_init_lock != nullptr) _init_lock->exit(_thread);
sp = redo_vmcall(_thread, top);
}
return sp;
Expand Down
30 changes: 1 addition & 29 deletions src/hotspot/share/runtime/javaThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ class JavaThread: public Thread {
_thread->_interp_at_preemptable_vmcall_cnt);
}
};
#endif
#endif // ASSERT

private:
friend class VMThread;
Expand Down Expand Up @@ -1369,23 +1369,6 @@ class JNIHandleMark : public StackObj {
~JNIHandleMark() { _thread->pop_jni_handle_block(); }
};

class PreemptableInitCall {
JavaThread* _thread;
bool _previous;
DEBUG_ONLY(InstanceKlass* _previous_klass;)
public:
PreemptableInitCall(JavaThread* thread, InstanceKlass* ik) : _thread(thread) {
_previous = thread->at_preemptable_init();
_thread->set_at_preemptable_init(true);
DEBUG_ONLY(_previous_klass = _thread->preempt_init_klass();)
DEBUG_ONLY(_thread->set_preempt_init_klass(ik));
}
~PreemptableInitCall() {
_thread->set_at_preemptable_init(_previous);
DEBUG_ONLY(_thread->set_preempt_init_klass(_previous_klass));
}
};

class NoPreemptMark {
ContinuationEntry* _ce;
bool _unpin;
Expand Down Expand Up @@ -1418,15 +1401,4 @@ class ThreadInClassInitializer : public StackObj {
}
};

class ThreadWaitingForClassInit : public StackObj {
JavaThread* _thread;
public:
ThreadWaitingForClassInit(JavaThread* thread, InstanceKlass* ik) : _thread(thread) {
_thread->set_class_to_be_initialized(ik);
}
~ThreadWaitingForClassInit() {
_thread->set_class_to_be_initialized(nullptr);
}
};

#endif // SHARE_RUNTIME_JAVATHREAD_HPP
6 changes: 0 additions & 6 deletions src/hotspot/share/utilities/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,4 @@
#define INCLUDE_ASAN 0
#endif

#if defined(AARCH64) || defined(AMD64) || defined(RISCV64) || defined(PPC64)
#define PREEMPT_ON_INIT_SUPPORTED_ONLY(code) code
#else
#define PREEMPT_ON_INIT_SUPPORTED_ONLY(code)
#endif

#endif // SHARE_UTILITIES_MACROS_HPP