Skip to content
Permalink
Browse files
8252406: Introduce Thread::as_Java_thread() convenience function
Reviewed-by: shade, coleenp, kbarrett, dcubed
  • Loading branch information
David Holmes committed Sep 11, 2020
1 parent 4880226 commit 976acddeb5a8df1e868269787c023306aad3fe4a
Showing 110 changed files with 360 additions and 456 deletions.
@@ -101,7 +101,7 @@ void BarrierSetNMethod::deoptimize(nmethod* nm, address* return_address_ptr) {

frame_pointers_t *new_frame = (frame_pointers_t *)(return_address_ptr - 5);

JavaThread *thread = (JavaThread*)Thread::current();
JavaThread *thread = JavaThread::current();
RegisterMap reg_map(thread, false);
frame frame = thread->last_frame();

@@ -111,14 +111,11 @@ void BarrierSetNMethod::deoptimize(nmethod* nm, address* return_address_ptr) {

LogTarget(Trace, nmethod, barrier) out;
if (out.is_enabled()) {
Thread* thread = Thread::current();
assert(thread->is_Java_thread(), "must be JavaThread");
JavaThread* jth = (JavaThread*) thread;
ResourceMark mark;
log_trace(nmethod, barrier)("deoptimize(nmethod: %s(%p), return_addr: %p, osr: %d, thread: %p(%s), making rsp: %p) -> %p",
nm->method()->name_and_sig_as_C_string(),
nm, *(address *) return_address_ptr, nm->is_osr_method(), jth,
jth->get_thread_name(), frame.sp(), nm->verified_entry_point());
nm, *(address *) return_address_ptr, nm->is_osr_method(), thread,
thread->get_thread_name(), frame.sp(), nm->verified_entry_point());
}

new_frame->sp = frame.sp();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 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
@@ -128,9 +128,7 @@ void BarrierSetNMethod::deoptimize(nmethod* nm, address* return_address_ptr) {

LogTarget(Trace, nmethod, barrier) out;
if (out.is_enabled()) {
Thread* thread = Thread::current();
assert(thread->is_Java_thread(), "must be JavaThread");
JavaThread* jth = (JavaThread*) thread;
JavaThread* jth = JavaThread::current();
ResourceMark mark;
log_trace(nmethod, barrier)("deoptimize(nmethod: %p, return_addr: %p, osr: %d, thread: %p(%s), making rsp: %p) -> %p",
nm, (address *) return_address_ptr, nm->is_osr_method(), jth,
@@ -94,7 +94,7 @@ void frame::patch_pc(Thread* thread, address pc) {
// We borrow this call to set the thread pointer in the interpreter
// state; the hook to set up deoptimized frames isn't supplied it.
assert(pc == NULL, "should be");
get_interpreterState()->set_thread((JavaThread *) thread);
get_interpreterState()->set_thread(thread->as_Java_thread());
}
}

@@ -38,7 +38,7 @@

void MethodHandles::invoke_target(Method* method, TRAPS) {

JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();
ZeroStack *stack = thread->zero_stack();
InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame();
interpreterState istate = frame->interpreter_state();
@@ -55,7 +55,7 @@ void MethodHandles::invoke_target(Method* method, TRAPS) {

oop MethodHandles::popFromStack(TRAPS) {

JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();
InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame();
interpreterState istate = frame->interpreter_state();
intptr_t* topOfStack = istate->stack();
@@ -70,7 +70,7 @@ oop MethodHandles::popFromStack(TRAPS) {

void MethodHandles::throw_AME(Klass* rcvr, Method* interface_method, TRAPS) {

JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();
// Set up the frame anchor if it isn't already
bool has_last_Java_frame = thread->has_last_Java_frame();
if (!has_last_Java_frame) {
@@ -101,7 +101,7 @@ void MethodHandles::throw_AME(Klass* rcvr, Method* interface_method, TRAPS) {

int MethodHandles::method_handle_entry_invokeBasic(Method* method, intptr_t UNUSED, TRAPS) {

JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();
InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame();
interpreterState istate = frame->interpreter_state();
intptr_t* topOfStack = istate->stack();
@@ -132,7 +132,7 @@ int MethodHandles::method_handle_entry_linkToStaticOrSpecial(Method* method, int
}

int MethodHandles::method_handle_entry_linkToInterface(Method* method, intptr_t UNUSED, TRAPS) {
JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();
InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame();
interpreterState istate = frame->interpreter_state();

@@ -172,7 +172,7 @@ int MethodHandles::method_handle_entry_linkToInterface(Method* method, intptr_t
}

int MethodHandles::method_handle_entry_linkToVirtual(Method* method, intptr_t UNUSED, TRAPS) {
JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();

InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame();
interpreterState istate = frame->interpreter_state();
@@ -46,7 +46,7 @@ int ZeroStack::suggest_size(Thread *thread) const {
}

void ZeroStack::handle_overflow(TRAPS) {
JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();

// Set up the frame anchor if it isn't already
bool has_last_Java_frame = thread->has_last_Java_frame();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright 2007, 2008, 2010, 2015 Red Hat, Inc.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -72,7 +72,7 @@ class StubGenerator: public StubCodeGenerator {
intptr_t* parameters,
int parameter_words,
TRAPS) {
JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();
ZeroStack *stack = thread->zero_stack();

// Make sure we have no pending exceptions
@@ -316,7 +316,7 @@ EntryFrame *EntryFrame::build(const intptr_t* parameters,
JavaCallWrapper* call_wrapper,
TRAPS) {

ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack();
ZeroStack *stack = THREAD->as_Java_thread()->zero_stack();
stack->overflow_check(header_words + parameter_words, CHECK_NULL);

stack->push(0); // next_frame, filled in later
@@ -106,7 +106,7 @@ InterpreterCodelet* ZeroInterpreter::codelet_containing(address pc) {
fixup_after_potential_safepoint()

int ZeroInterpreter::normal_entry(Method* method, intptr_t UNUSED, TRAPS) {
JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();

// Allocate and initialize our frame.
InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0);
@@ -144,7 +144,7 @@ intptr_t narrow(BasicType type, intptr_t result) {


void ZeroInterpreter::main_loop(int recurse, TRAPS) {
JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();
ZeroStack *stack = thread->zero_stack();

// If we are entering from a deopt we may need to call
@@ -277,7 +277,7 @@ int ZeroInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) {
// Make sure method is native and not abstract
assert(method->is_native() && !method->is_abstract(), "should be");

JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();
ZeroStack *stack = thread->zero_stack();

// Allocate and initialize our frame
@@ -546,7 +546,7 @@ int ZeroInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) {
}

int ZeroInterpreter::accessor_entry(Method* method, intptr_t UNUSED, TRAPS) {
JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();
ZeroStack *stack = thread->zero_stack();
intptr_t *locals = stack->sp();

@@ -679,7 +679,7 @@ int ZeroInterpreter::accessor_entry(Method* method, intptr_t UNUSED, TRAPS) {
}

int ZeroInterpreter::empty_entry(Method* method, intptr_t UNUSED, TRAPS) {
JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();
ZeroStack *stack = thread->zero_stack();

// Drop into the slow path if we need a safepoint check
@@ -698,7 +698,7 @@ int ZeroInterpreter::empty_entry(Method* method, intptr_t UNUSED, TRAPS) {
// Slots < insert_before will have the same slot number after the insert.
// Slots >= insert_before will become old_slot + num_slots.
void ZeroInterpreter::insert_vmslots(int insert_before, int num_slots, TRAPS) {
JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();
ZeroStack *stack = thread->zero_stack();

// Allocate the space
@@ -712,7 +712,7 @@ void ZeroInterpreter::insert_vmslots(int insert_before, int num_slots, TRAPS) {
}

void ZeroInterpreter::remove_vmslots(int first_slot, int num_slots, TRAPS) {
JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();
ZeroStack *stack = thread->zero_stack();
intptr_t *vmslots = stack->sp();

@@ -745,7 +745,7 @@ JRT_ENTRY(void, ZeroInterpreter::throw_exception(JavaThread* thread,
JRT_END

InterpreterFrame *InterpreterFrame::build(Method* const method, TRAPS) {
JavaThread *thread = (JavaThread *) THREAD;
JavaThread *thread = THREAD->as_Java_thread();
ZeroStack *stack = thread->zero_stack();

// Calculate the size of the frame we'll build, including
@@ -821,7 +821,7 @@ InterpreterFrame *InterpreterFrame::build(Method* const method, TRAPS) {
}

InterpreterFrame *InterpreterFrame::build(int size, TRAPS) {
ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack();
ZeroStack *stack = THREAD->as_Java_thread()->zero_stack();

int size_in_words = size >> LogBytesPerWord;
assert(size_in_words * wordSize == size, "unaligned");
@@ -1040,13 +1040,12 @@ bool os::create_attached_thread(JavaThread* thread) {
// enabling yellow zone first will crash JVM on SuSE Linux), so there
// is no gap between the last two virtual memory regions.

JavaThread *jt = (JavaThread *)thread;
address addr = jt->stack_reserved_zone_base();
address addr = thread->stack_reserved_zone_base();
assert(addr != NULL, "initialization problem?");
assert(jt->stack_available(addr) > 0, "stack guard should not be enabled");
assert(thread->stack_available(addr) > 0, "stack guard should not be enabled");

osthread->set_expanding_stack();
os::Linux::manually_expand_stack(jt, addr);
os::Linux::manually_expand_stack(thread, addr);
osthread->clear_expanding_stack();
}

@@ -1781,7 +1780,6 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
"'execstack -c <libfile>', or link it with '-z noexecstack'.",
filename);

assert(Thread::current()->is_Java_thread(), "must be Java thread");
JavaThread *jt = JavaThread::current();
if (jt->thread_state() != _thread_in_native) {
// This happens when a compiler thread tries to load a hsdis-<arch>.so file
@@ -2073,9 +2073,7 @@ void Parker::park(bool isAbsolute, jlong time) {
// since we are doing a lock-free update to _counter.
if (Atomic::xchg(&_counter, 0) > 0) return;

Thread* thread = Thread::current();
assert(thread->is_Java_thread(), "Must be JavaThread");
JavaThread *jt = (JavaThread *)thread;
JavaThread *jt = JavaThread::current();

// Optional optimization -- avoid state transitions if there's
// an interrupt pending.
@@ -2120,7 +2118,7 @@ void Parker::park(bool isAbsolute, jlong time) {
return;
}

OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
OSThreadWaitState osts(jt->osthread(), false /* not Object.wait() */);
jt->set_suspend_equivalent();
// cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()

@@ -2136,19 +2136,19 @@ int os::signal_wait() {

LONG Handle_Exception(struct _EXCEPTION_POINTERS* exceptionInfo,
address handler) {
JavaThread* thread = (JavaThread*) Thread::current_or_null();
Thread* thread = Thread::current_or_null();
// Save pc in thread
#ifdef _M_AMD64
// Do not blow up if no thread info available.
if (thread) {
thread->set_saved_exception_pc((address)(DWORD_PTR)exceptionInfo->ContextRecord->Rip);
if (thread != NULL) {
thread->as_Java_thread()->set_saved_exception_pc((address)(DWORD_PTR)exceptionInfo->ContextRecord->Rip);
}
// Set pc to handler
exceptionInfo->ContextRecord->Rip = (DWORD64)handler;
#else
// Do not blow up if no thread info available.
if (thread) {
thread->set_saved_exception_pc((address)(DWORD_PTR)exceptionInfo->ContextRecord->Eip);
if (thread != NULL) {
thread->as_Java_thread()->set_saved_exception_pc((address)(DWORD_PTR)exceptionInfo->ContextRecord->Eip);
}
// Set pc to handler
exceptionInfo->ContextRecord->Eip = (DWORD)(DWORD_PTR)handler;
@@ -2477,7 +2477,7 @@ LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) {
}

if (t != NULL && t->is_Java_thread()) {
JavaThread* thread = (JavaThread*) t;
JavaThread* thread = t->as_Java_thread();
bool in_java = thread->thread_state() == _thread_in_Java;
bool in_native = thread->thread_state() == _thread_in_native;
bool in_vm = thread->thread_state() == _thread_in_vm;
@@ -2570,7 +2570,6 @@ LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) {

if (exception_code == EXCEPTION_IN_PAGE_ERROR) {
CompiledMethod* nm = NULL;
JavaThread* thread = (JavaThread*)t;
if (in_java) {
CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL;
@@ -228,7 +228,7 @@ JVM_handle_aix_signal(int sig, siginfo_t* info, void* ucVoid, int abort_if_unrec
if (os::Aix::signal_handlers_are_installed) {
if (t != NULL) {
if(t->is_Java_thread()) {
thread = (JavaThread*)t;
thread = t->as_Java_thread();
}
else if(t->is_VM_thread()) {
vmthread = (VMThread *)t;
@@ -457,7 +457,7 @@ JVM_handle_bsd_signal(int sig,
if (os::Bsd::signal_handlers_are_installed) {
if (t != NULL ){
if(t->is_Java_thread()) {
thread = (JavaThread*)t;
thread = t->as_Java_thread();
}
else if(t->is_VM_thread()){
vmthread = (VMThread *)t;
@@ -46,13 +46,10 @@ bool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext,
}

bool JavaThread::pd_get_top_frame(frame* fr_addr, void* ucontext, bool isInJava) {
assert(this->is_Java_thread(), "must be JavaThread");
JavaThread* jt = (JavaThread *)this;

// If we have a last_Java_frame, then we should use it even if
// isInJava == true. It should be more reliable than ucontext info.
if (jt->has_last_Java_frame() && jt->frame_anchor()->walkable()) {
*fr_addr = jt->pd_last_frame();
if (has_last_Java_frame() && frame_anchor()->walkable()) {
*fr_addr = pd_last_frame();
return true;
}

@@ -77,11 +74,11 @@ bool JavaThread::pd_get_top_frame(frame* fr_addr, void* ucontext, bool isInJava)
}

frame ret_frame(ret_sp, ret_fp, addr);
if (!ret_frame.safe_for_sender(jt)) {
if (!ret_frame.safe_for_sender(this)) {
#if COMPILER2_OR_JVMCI
// C2 and JVMCI use ebp as a general register see if NULL fp helps
frame ret_frame2(ret_sp, NULL, addr);
if (!ret_frame2.safe_for_sender(jt)) {
if (!ret_frame2.safe_for_sender(this)) {
// nothing else to try if the frame isn't good
return false;
}
@@ -156,7 +156,7 @@ JVM_handle_bsd_signal(int sig,
if (os::Bsd::signal_handlers_are_installed) {
if (t != NULL ){
if(t->is_Java_thread()) {
thread = (JavaThread*)t;
thread = t->as_Java_thread();
}
else if(t->is_VM_thread()){
vmthread = (VMThread *)t;
@@ -237,7 +237,7 @@ JVM_handle_linux_signal(int sig,
if (os::Linux::signal_handlers_are_installed) {
if (t != NULL ){
if(t->is_Java_thread()) {
thread = (JavaThread*)t;
thread = t->as_Java_thread();
}
else if(t->is_VM_thread()){
vmthread = (VMThread *)t;

1 comment on commit 976acdd

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 976acdd Sep 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Issues

Please sign in to comment.