Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8263709: Cleanup THREAD/TRAPS/CHECK usage in JRT_ENTRY routines #3394

Closed
wants to merge 9 commits into from
@@ -165,8 +165,7 @@ address Runtime1::arraycopy_count_address(BasicType type) {
// Simple helper to see if the caller of a runtime stub which
// entered the VM has been deoptimized

static bool caller_is_deopted() {
JavaThread* current = JavaThread::current();
static bool caller_is_deopted(JavaThread* current) {
RegisterMap reg_map(current, false);
frame runtime_frame = current->last_frame();
frame caller_frame = runtime_frame.sender(&reg_map);
@@ -175,14 +174,13 @@ static bool caller_is_deopted() {
}

// Stress deoptimization
static void deopt_caller() {
if ( !caller_is_deopted()) {
JavaThread* current = JavaThread::current();
static void deopt_caller(JavaThread* current) {
if ( !caller_is_deopted(current)) {

This comment has been minimized.

Loading
@vnkozlov

vnkozlov Apr 14, 2021
Contributor Outdated

Can you remove space after ( ?

RegisterMap reg_map(current, false);
frame runtime_frame = current->last_frame();
frame caller_frame = runtime_frame.sender(&reg_map);
Deoptimization::deoptimize_frame(current, caller_frame.id());
assert(caller_is_deopted(), "Must be deoptimized");
assert(caller_is_deopted(current), "Must be deoptimized");
}
}

@@ -381,7 +379,7 @@ JRT_ENTRY(void, Runtime1::new_type_array(JavaThread* current, Klass* klass, jint
// This is pretty rare but this runtime patch is stressful to deoptimization
// if we deoptimize here so force a deopt to stress the path.
if (DeoptimizeALot) {
deopt_caller();
deopt_caller(current);
}

JRT_END
@@ -401,7 +399,7 @@ JRT_ENTRY(void, Runtime1::new_object_array(JavaThread* current, Klass* array_kla
// This is pretty rare but this runtime patch is stressful to deoptimization
// if we deoptimize here so force a deopt to stress the path.
if (DeoptimizeALot) {
deopt_caller();
deopt_caller(current);
}
JRT_END

@@ -569,7 +567,7 @@ JRT_ENTRY_NO_ASYNC(static address, exception_handler_for_pc_helper(JavaThread* c
// can actually continue in the exception handler ourselves but I
// don't see an easy way to have the desired effect.
Deoptimization::deoptimize_frame(current, caller_frame.id());
assert(caller_is_deopted(), "Must be deoptimized");
assert(caller_is_deopted(current), "Must be deoptimized");

return SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();
}
@@ -650,7 +648,7 @@ address Runtime1::exception_handler_for_pc(JavaThread* current) {

// Now check to see if the nmethod we were called from is now deoptimized.
// If so we must return to the deopt blob and deoptimize the nmethod
if (nm != NULL && caller_is_deopted()) {
if (nm != NULL && caller_is_deopted(current)) {
continuation = SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();
}

@@ -692,7 +690,7 @@ JRT_END
JRT_ENTRY(void, Runtime1::throw_class_cast_exception(JavaThread* current, oopDesc* object))
NOT_PRODUCT(_throw_class_cast_exception_count++;)
ResourceMark rm(current);
char* message = SharedRuntime::generate_class_cast_message(current, object->klass());
char* message = SharedRuntime::generate_class_cast_message(current, object->klass());
SharedRuntime::throw_and_post_jvmti_exception(current, vmSymbols::java_lang_ClassCastException(), message);
JRT_END

@@ -1042,7 +1040,7 @@ JRT_ENTRY(void, Runtime1::patch_code(JavaThread* current, Runtime1::StubID stub_
// Deoptimization may have happened while we waited for the lock.
// In that case we don't bother to do any patching we just return
// and let the deopt happen
if (!caller_is_deopted()) {
if (!caller_is_deopted(current)) {
NativeGeneralJump* jump = nativeGeneralJump_at(caller_frame.pc());
address instr_pc = jump->jump_destination();
NativeInstruction* ni = nativeInstruction_at(instr_pc);
@@ -1286,7 +1284,7 @@ void Runtime1::patch_code(JavaThread* current, Runtime1::StubID stub_id) {

Deoptimization::deoptimize_frame(current, caller_frame.id());
// Return to the now deoptimized frame.
postcond(caller_is_deopted());
postcond(caller_is_deopted(current));
}

#endif // DEOPTIMIZE_WHEN_PATCHING
@@ -1313,7 +1311,7 @@ int Runtime1::move_klass_patching(JavaThread* current) {

// Return true if calling code is deoptimized

return caller_is_deopted();
return caller_is_deopted(current);
}

int Runtime1::move_mirror_patching(JavaThread* current) {
@@ -1330,7 +1328,7 @@ int Runtime1::move_mirror_patching(JavaThread* current) {

// Return true if calling code is deoptimized

return caller_is_deopted();
return caller_is_deopted(current);
}

int Runtime1::move_appendix_patching(JavaThread* current) {
@@ -1347,7 +1345,7 @@ int Runtime1::move_appendix_patching(JavaThread* current) {

// Return true if calling code is deoptimized

return caller_is_deopted();
return caller_is_deopted(current);
}

// Entry point for compiled code. We want to patch a nmethod.
@@ -1374,7 +1372,7 @@ int Runtime1::access_field_patching(JavaThread* current) {

// Return true if calling code is deoptimized

return caller_is_deopted();
return caller_is_deopted(current);
}


@@ -128,7 +128,7 @@ class LastFrameAccessor : public StackObj {
//------------------------------------------------------------------------------------------------------------------------
// State accessors

void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread *current) {
void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread* current) {
LastFrameAccessor last_frame(current);
last_frame.set_bcp(bcp);
if (ProfileInterpreter) {
@@ -300,7 +300,7 @@ JRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* current))
ConstantPool* cpool = last_frame.method()->constants();
// We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
// program we might have seen an unquick'd bytecode in the interpreter but have another
// current quicken the bytecode before we get here.
// thread quicken the bytecode before we get here.
// assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
Klass* klass = cpool->klass_at(which, CHECK);
current->set_vm_result_2(klass);
@@ -1154,7 +1154,7 @@ JRT_LEAF(void, InterpreterRuntime::at_unwind(JavaThread* current))
StackWatermarkSet::before_unwind(current);
JRT_END

JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *current, oopDesc* obj,
JRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread* current, oopDesc* obj,
ConstantPoolCacheEntry *cp_entry))

// check the access_flags for the field in the klass
@@ -1234,7 +1234,7 @@ JRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread* current,
fid, sig_type, &fvalue);
JRT_END

JRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread *current))
JRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread* current))
LastFrameAccessor last_frame(current);
JvmtiExport::post_method_entry(current, last_frame.method(), last_frame.get_frame());
JRT_END
@@ -1243,7 +1243,7 @@ JRT_END
// This is a JRT_BLOCK_ENTRY because we have to stash away the return oop
// before transitioning to VM, and restore it after transitioning back
// to Java. The return oop at the top-of-stack, is not walked by the GC.
JRT_BLOCK_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread *current))
JRT_BLOCK_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread* current))
LastFrameAccessor last_frame(current);
JvmtiExport::post_method_exit(current, last_frame.method(), last_frame.get_frame());
JRT_END
@@ -41,7 +41,7 @@
#include "utilities/sizes.hpp"

// Resolve and allocate String
JRT_BLOCK_ENTRY(void, CompilerRuntime::resolve_string_by_symbol(JavaThread *thread, void* string_result, const char* name))
JRT_BLOCK_ENTRY(void, CompilerRuntime::resolve_string_by_symbol(JavaThread* current, void* string_result, const char* name))
JRT_BLOCK
oop str = *(oop*)string_result; // Is it resolved already?
if (str == NULL) { // Do resolution
@@ -54,26 +54,27 @@ JRT_BLOCK_ENTRY(void, CompilerRuntime::resolve_string_by_symbol(JavaThread *thre
*(oop*)string_result = str; // Store result
}
assert(str != NULL, "Should be allocated!");
thread->set_vm_result(str);
current->set_vm_result(str);
JRT_BLOCK_END
JRT_END



Klass* CompilerRuntime::resolve_klass_helper(JavaThread *thread, const char* name, int len, TRAPS) {
ResourceMark rm(THREAD);
Klass* CompilerRuntime::resolve_klass_helper(const char* name, int len, TRAPS) {
JavaThread* current = THREAD->as_Java_thread();
ResourceMark rm(current);
// last java frame on stack (which includes native call frames)
RegisterMap cbl_map(thread, false);
RegisterMap cbl_map(current, false);
// Skip stub
frame caller_frame = thread->last_frame().sender(&cbl_map);
frame caller_frame = current->last_frame().sender(&cbl_map);
CodeBlob* caller_cb = caller_frame.cb();
guarantee(caller_cb != NULL && caller_cb->is_compiled(), "must be called from compiled method");
CompiledMethod* caller_nm = caller_cb->as_compiled_method_or_null();
methodHandle caller(THREAD, caller_nm->method());
methodHandle caller(current, caller_nm->method());

// Use class loader of aot method.
Handle loader(THREAD, caller->method_holder()->class_loader());
Handle protection_domain(THREAD, caller->method_holder()->protection_domain());
Handle loader(current, caller->method_holder()->class_loader());
Handle protection_domain(current, caller->method_holder()->protection_domain());

TempNewSymbol sym = SymbolTable::new_symbol(name, len);
if (sym != NULL && Signature::has_envelope(sym)) {
@@ -89,15 +90,15 @@ Klass* CompilerRuntime::resolve_klass_helper(JavaThread *thread, const char* nam
}

// Resolve Klass
JRT_BLOCK_ENTRY(Klass*, CompilerRuntime::resolve_klass_by_symbol(JavaThread *thread, Klass** klass_result, const char* name))
JRT_BLOCK_ENTRY(Klass*, CompilerRuntime::resolve_klass_by_symbol(JavaThread* current, Klass** klass_result, const char* name))
Klass* k = NULL;
JRT_BLOCK
k = *klass_result; // Is it resolved already?
if (k == NULL) { // Do resolution
// First 2 bytes of name contains length (number of bytes).
int len = Bytes::get_Java_u2((address)name);
name += 2;
k = CompilerRuntime::resolve_klass_helper(thread, name, len, CHECK_NULL);
k = CompilerRuntime::resolve_klass_helper(name, len, CHECK_NULL);
*klass_result = k; // Store result
}
JRT_BLOCK_END
@@ -107,7 +108,7 @@ JRT_END


Method* CompilerRuntime::resolve_method_helper(Klass* klass, const char* method_name, int method_name_len,
const char* signature_name, int signature_name_len) {
const char* signature_name, int signature_name_len) {
Method* m = NULL;
TempNewSymbol name_symbol = SymbolTable::probe(method_name, method_name_len);
TempNewSymbol signature_symbol = SymbolTable::probe(signature_name, signature_name_len);
@@ -128,21 +129,21 @@ Method* CompilerRuntime::resolve_method_helper(Klass* klass, const char* method_
return m;
}

JRT_BLOCK_ENTRY(void, CompilerRuntime::resolve_dynamic_invoke(JavaThread *thread, oop* appendix_result))
JRT_BLOCK_ENTRY(void, CompilerRuntime::resolve_dynamic_invoke(JavaThread* current, oop* appendix_result))
JRT_BLOCK
{
ResourceMark rm(THREAD);
vframeStream vfst(thread, true); // Do not skip and javaCalls
ResourceMark rm(current);
vframeStream vfst(current, true); // Do not skip and javaCalls
assert(!vfst.at_end(), "Java frame must exist");
methodHandle caller(THREAD, vfst.method());
methodHandle caller(current, vfst.method());
InstanceKlass* holder = caller->method_holder();
int bci = vfst.bci();
Bytecode_invoke bytecode(caller, bci);
int index = bytecode.index();

// Make sure it's resolved first
CallInfo callInfo;
constantPoolHandle cp(THREAD, holder->constants());
constantPoolHandle cp(current, holder->constants());
ConstantPoolCacheEntry* cp_cache_entry = cp->cache()->entry_at(cp->decode_cpcache_index(index, true));
Bytecodes::Code invoke_code = bytecode.invoke_code();
if (!cp_cache_entry->is_resolved(invoke_code)) {
@@ -155,10 +156,10 @@ JRT_BLOCK_ENTRY(void, CompilerRuntime::resolve_dynamic_invoke(JavaThread *thread
vmassert(cp_cache_entry->is_resolved(invoke_code), "sanity");
}

Handle appendix(THREAD, cp_cache_entry->appendix_if_resolved(cp));
Handle appendix(current, cp_cache_entry->appendix_if_resolved(cp));
Klass *appendix_klass = appendix.is_null() ? NULL : appendix->klass();

methodHandle adapter_method(THREAD, cp_cache_entry->f1_as_method());
methodHandle adapter_method(current, cp_cache_entry->f1_as_method());
InstanceKlass *adapter_klass = adapter_method->method_holder();

if (appendix_klass != NULL && appendix_klass->is_instance_klass()) {
@@ -179,12 +180,12 @@ JRT_BLOCK_ENTRY(void, CompilerRuntime::resolve_dynamic_invoke(JavaThread *thread
}

*appendix_result = appendix();
thread->set_vm_result(appendix());
current->set_vm_result(appendix());
}
JRT_BLOCK_END
JRT_END

JRT_BLOCK_ENTRY(MethodCounters*, CompilerRuntime::resolve_method_by_symbol_and_load_counters(JavaThread *thread, MethodCounters** counters_result, Klass* klass, const char* data))
JRT_BLOCK_ENTRY(MethodCounters*, CompilerRuntime::resolve_method_by_symbol_and_load_counters(JavaThread* current, MethodCounters** counters_result, Klass* klass, const char* data))
MethodCounters* c = *counters_result; // Is it resolved already?
JRT_BLOCK
if (c == NULL) { // Do resolution
@@ -204,7 +205,7 @@ JRT_BLOCK_ENTRY(MethodCounters*, CompilerRuntime::resolve_method_by_symbol_and_l
assert(m != NULL, "Method must resolve successfully");

// Create method counters immediately to avoid check at runtime.
c = m->get_method_counters(thread);
c = m->get_method_counters(current);
if (c == NULL) {
THROW_MSG_NULL(vmSymbols::java_lang_OutOfMemoryError(), "Cannot allocate method counters");
}
@@ -216,7 +217,7 @@ JRT_BLOCK_ENTRY(MethodCounters*, CompilerRuntime::resolve_method_by_symbol_and_l
JRT_END

// Resolve and initialize Klass
JRT_BLOCK_ENTRY(Klass*, CompilerRuntime::initialize_klass_by_symbol(JavaThread *thread, Klass** klass_result, const char* name))
JRT_BLOCK_ENTRY(Klass*, CompilerRuntime::initialize_klass_by_symbol(JavaThread* current, Klass** klass_result, const char* name))
Klass* k = NULL;
JRT_BLOCK
k = klass_result[0]; // Is it initialized already?
@@ -226,7 +227,7 @@ JRT_BLOCK_ENTRY(Klass*, CompilerRuntime::initialize_klass_by_symbol(JavaThread *
// First 2 bytes of name contains length (number of bytes).
int len = Bytes::get_Java_u2((address)name);
const char *cname = name + 2;
k = CompilerRuntime::resolve_klass_helper(thread, cname, len, CHECK_NULL);
k = CompilerRuntime::resolve_klass_helper(cname, len, CHECK_NULL);
klass_result[1] = k; // Store resolved result
}
Klass* k0 = klass_result[0]; // Is it initialized already?
@@ -247,34 +248,34 @@ JRT_BLOCK_ENTRY(Klass*, CompilerRuntime::initialize_klass_by_symbol(JavaThread *
JRT_END


JRT_BLOCK_ENTRY(void, CompilerRuntime::invocation_event(JavaThread *thread, MethodCounters* counters))
JRT_BLOCK_ENTRY(void, CompilerRuntime::invocation_event(JavaThread* current, MethodCounters* counters))
JRT_BLOCK
methodHandle mh(THREAD, counters->method());
RegisterMap map(thread, false);
methodHandle mh(current, counters->method());
RegisterMap map(current, false);
// Compute the enclosing method
frame fr = thread->last_frame().sender(&map);
frame fr = current->last_frame().sender(&map);
CompiledMethod* cm = fr.cb()->as_compiled_method_or_null();
assert(cm != NULL && cm->is_compiled(), "Sanity check");
methodHandle emh(THREAD, cm->method());
CompilationPolicy::event(emh, mh, InvocationEntryBci, InvocationEntryBci, CompLevel_aot, cm, THREAD);
methodHandle emh(current, cm->method());
CompilationPolicy::event(emh, mh, InvocationEntryBci, InvocationEntryBci, CompLevel_aot, cm, CHECK);
JRT_BLOCK_END
JRT_END

JRT_BLOCK_ENTRY(void, CompilerRuntime::backedge_event(JavaThread *thread, MethodCounters* counters, int branch_bci, int target_bci))
JRT_BLOCK_ENTRY(void, CompilerRuntime::backedge_event(JavaThread* current, MethodCounters* counters, int branch_bci, int target_bci))
assert(branch_bci != InvocationEntryBci && target_bci != InvocationEntryBci, "Wrong bci");
assert(target_bci <= branch_bci, "Expected a back edge");
JRT_BLOCK
methodHandle mh(THREAD, counters->method());
RegisterMap map(thread, false);
methodHandle mh(current, counters->method());
RegisterMap map(current, false);

// Compute the enclosing method
frame fr = thread->last_frame().sender(&map);
frame fr = current->last_frame().sender(&map);
CompiledMethod* cm = fr.cb()->as_compiled_method_or_null();
assert(cm != NULL && cm->is_compiled(), "Sanity check");
methodHandle emh(THREAD, cm->method());
nmethod* osr_nm = CompilationPolicy::event(emh, mh, branch_bci, target_bci, CompLevel_aot, cm, THREAD);
methodHandle emh(current, cm->method());
nmethod* osr_nm = CompilationPolicy::event(emh, mh, branch_bci, target_bci, CompLevel_aot, cm, CHECK);
if (osr_nm != NULL) {
Deoptimization::deoptimize_frame(thread, fr.id());
Deoptimization::deoptimize_frame(current, fr.id());
}
JRT_BLOCK_END
JRT_END
Loading