Skip to content

Commit

Permalink
8289094: [JVMCI] reduce JNI overhead and other VM rounds trips in JVMCI
Browse files Browse the repository at this point in the history
Reviewed-by: kvn, dlong
  • Loading branch information
Doug Simon committed Jun 29, 2022
1 parent 0709a6a commit ba670ec
Show file tree
Hide file tree
Showing 53 changed files with 3,496 additions and 1,996 deletions.
30 changes: 11 additions & 19 deletions src/hotspot/cpu/aarch64/jvmciCodeInstaller_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "runtime/sharedRuntime.hpp"
#include "vmreg_aarch64.inline.hpp"

jint CodeInstaller::pd_next_offset(NativeInstruction* inst, jint pc_offset, JVMCIObject method, JVMCI_TRAPS) {
jint CodeInstaller::pd_next_offset(NativeInstruction* inst, jint pc_offset, JVMCI_TRAPS) {
if (inst->is_call() || inst->is_jump() || inst->is_blr()) {
return pc_offset + NativeCall::instruction_size;
} else if (inst->is_general_jump()) {
Expand All @@ -47,12 +47,12 @@ jint CodeInstaller::pd_next_offset(NativeInstruction* inst, jint pc_offset, JVMC
}
}

void CodeInstaller::pd_patch_OopConstant(int pc_offset, JVMCIObject constant, JVMCI_TRAPS) {
void CodeInstaller::pd_patch_OopConstant(int pc_offset, Handle& obj, bool compressed, JVMCI_TRAPS) {
address pc = _instructions->start() + pc_offset;
#ifdef ASSERT
{
NativeInstruction *insn = nativeInstruction_at(pc);
if (jvmci_env()->get_HotSpotObjectConstantImpl_compressed(constant)) {
if (compressed) {
// Mov narrow constant: movz n << 16, movk
assert(Instruction_aarch64::extract(insn->encoding(), 31, 21) == 0b11010010101 &&
nativeInstruction_at(pc+4)->is_movk(), "wrong insn in patch");
Expand All @@ -63,23 +63,22 @@ void CodeInstaller::pd_patch_OopConstant(int pc_offset, JVMCIObject constant, JV
}
}
#endif // ASSERT
Handle obj = jvmci_env()->asConstant(constant, JVMCI_CHECK);
jobject value = JNIHandles::make_local(obj());
MacroAssembler::patch_oop(pc, cast_from_oop<address>(obj()));
int oop_index = _oop_recorder->find_index(value);
RelocationHolder rspec = oop_Relocation::spec(oop_index);
_instructions->relocate(pc, rspec);
}

void CodeInstaller::pd_patch_MetaspaceConstant(int pc_offset, JVMCIObject constant, JVMCI_TRAPS) {
void CodeInstaller::pd_patch_MetaspaceConstant(int pc_offset, HotSpotCompiledCodeStream* stream, u1 tag, JVMCI_TRAPS) {
address pc = _instructions->start() + pc_offset;
if (jvmci_env()->get_HotSpotMetaspaceConstantImpl_compressed(constant)) {
narrowKlass narrowOop = record_narrow_metadata_reference(_instructions, pc, constant, JVMCI_CHECK);
if (tag == PATCH_NARROW_KLASS) {
narrowKlass narrowOop = record_narrow_metadata_reference(_instructions, pc, stream, tag, JVMCI_CHECK);
MacroAssembler::patch_narrow_klass(pc, narrowOop);
JVMCI_event_3("relocating (narrow metaspace constant) at " PTR_FORMAT "/0x%x", p2i(pc), narrowOop);
} else {
NativeMovConstReg* move = nativeMovConstReg_at(pc);
void* reference = record_metadata_reference(_instructions, pc, constant, JVMCI_CHECK);
void* reference = record_metadata_reference(_instructions, pc, stream, tag, JVMCI_CHECK);
move->set_data((intptr_t) reference);
JVMCI_event_3("relocating (metaspace constant) at " PTR_FORMAT "/" PTR_FORMAT, p2i(pc), p2i(reference));
}
Expand Down Expand Up @@ -122,34 +121,27 @@ void CodeInstaller::pd_relocate_ForeignCall(NativeInstruction* inst, jlong forei
JVMCI_event_3("relocating (foreign call) at " PTR_FORMAT, p2i(inst));
}

void CodeInstaller::pd_relocate_JavaMethod(CodeBuffer &cbuf, JVMCIObject hotspot_method, jint pc_offset, JVMCI_TRAPS) {
#ifdef ASSERT
Method* method = NULL;
// we need to check, this might also be an unresolved method
if (JVMCIENV->isa_HotSpotResolvedJavaMethodImpl(hotspot_method)) {
method = JVMCIENV->asMethod(hotspot_method);
}
#endif
void CodeInstaller::pd_relocate_JavaMethod(CodeBuffer &cbuf, methodHandle& method, jint pc_offset, JVMCI_TRAPS) {
switch (_next_call_type) {
case INLINE_INVOKE:
break;
case INVOKEVIRTUAL:
case INVOKEINTERFACE: {
assert(method == NULL || !method->is_static(), "cannot call static method with invokeinterface");
assert(!method->is_static(), "cannot call static method with invokeinterface");
NativeCall* call = nativeCall_at(_instructions->start() + pc_offset);
_instructions->relocate(call->instruction_address(), virtual_call_Relocation::spec(_invoke_mark_pc));
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_virtual_call_stub());
break;
}
case INVOKESTATIC: {
assert(method == NULL || method->is_static(), "cannot call non-static method with invokestatic");
assert(method->is_static(), "cannot call non-static method with invokestatic");
NativeCall* call = nativeCall_at(_instructions->start() + pc_offset);
_instructions->relocate(call->instruction_address(), relocInfo::static_call_type);
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_static_call_stub());
break;
}
case INVOKESPECIAL: {
assert(method == NULL || !method->is_static(), "cannot call static method with invokespecial");
assert(!method->is_static(), "cannot call static method with invokespecial");
NativeCall* call = nativeCall_at(_instructions->start() + pc_offset);
_instructions->relocate(call->instruction_address(), relocInfo::opt_virtual_call_type);
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_opt_virtual_call_stub());
Expand Down
31 changes: 11 additions & 20 deletions src/hotspot/cpu/x86/jvmciCodeInstaller_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "code/vmreg.hpp"
#include "vmreg_x86.inline.hpp"

jint CodeInstaller::pd_next_offset(NativeInstruction* inst, jint pc_offset, JVMCIObject method, JVMCI_TRAPS) {
jint CodeInstaller::pd_next_offset(NativeInstruction* inst, jint pc_offset, JVMCI_TRAPS) {
if (inst->is_call() || inst->is_jump()) {
assert(NativeCall::instruction_size == (int)NativeJump::instruction_size, "unexpected size");
return (pc_offset + NativeCall::instruction_size);
Expand All @@ -56,7 +56,6 @@ jint CodeInstaller::pd_next_offset(NativeInstruction* inst, jint pc_offset, JVMC
return (offset);
} else if (inst->is_call_reg()) {
// the inlined vtable stub contains a "call register" instruction
assert(method.is_non_null(), "only valid for virtual calls");
return (pc_offset + ((NativeCallReg *) inst)->next_instruction_offset());
} else if (inst->is_cond_jump()) {
address pc = (address) (inst);
Expand All @@ -66,11 +65,10 @@ jint CodeInstaller::pd_next_offset(NativeInstruction* inst, jint pc_offset, JVMC
}
}

void CodeInstaller::pd_patch_OopConstant(int pc_offset, JVMCIObject constant, JVMCI_TRAPS) {
void CodeInstaller::pd_patch_OopConstant(int pc_offset, Handle& obj, bool compressed, JVMCI_TRAPS) {
address pc = _instructions->start() + pc_offset;
Handle obj = jvmci_env()->asConstant(constant, JVMCI_CHECK);
jobject value = JNIHandles::make_local(obj());
if (jvmci_env()->get_HotSpotObjectConstantImpl_compressed(constant)) {
if (compressed) {
#ifdef _LP64
address operand = Assembler::locate_operand(pc, Assembler::narrow_oop_operand);
int oop_index = _oop_recorder->find_index(value);
Expand All @@ -87,19 +85,19 @@ void CodeInstaller::pd_patch_OopConstant(int pc_offset, JVMCIObject constant, JV
}
}

void CodeInstaller::pd_patch_MetaspaceConstant(int pc_offset, JVMCIObject constant, JVMCI_TRAPS) {
void CodeInstaller::pd_patch_MetaspaceConstant(int pc_offset, HotSpotCompiledCodeStream* stream, u1 tag, JVMCI_TRAPS) {
address pc = _instructions->start() + pc_offset;
if (jvmci_env()->get_HotSpotMetaspaceConstantImpl_compressed(constant)) {
if (tag == PATCH_NARROW_KLASS) {
#ifdef _LP64
address operand = Assembler::locate_operand(pc, Assembler::narrow_oop_operand);
*((narrowKlass*) operand) = record_narrow_metadata_reference(_instructions, operand, constant, JVMCI_CHECK);
*((narrowKlass*) operand) = record_narrow_metadata_reference(_instructions, operand, stream, tag, JVMCI_CHECK);
JVMCI_event_3("relocating (narrow metaspace constant) at " PTR_FORMAT "/" PTR_FORMAT, p2i(pc), p2i(operand));
#else
JVMCI_ERROR("compressed Klass* on 32bit");
#endif
} else {
address operand = Assembler::locate_operand(pc, Assembler::imm_operand);
*((void**) operand) = record_metadata_reference(_instructions, operand, constant, JVMCI_CHECK);
*((void**) operand) = record_metadata_reference(_instructions, operand, stream, tag, JVMCI_CHECK);
JVMCI_event_3("relocating (metaspace constant) at " PTR_FORMAT "/" PTR_FORMAT, p2i(pc), p2i(operand));
}
}
Expand Down Expand Up @@ -147,21 +145,14 @@ void CodeInstaller::pd_relocate_ForeignCall(NativeInstruction* inst, jlong forei
JVMCI_event_3("relocating (foreign call) at " PTR_FORMAT, p2i(inst));
}

void CodeInstaller::pd_relocate_JavaMethod(CodeBuffer &, JVMCIObject hotspot_method, jint pc_offset, JVMCI_TRAPS) {
#ifdef ASSERT
Method* method = NULL;
// we need to check, this might also be an unresolved method
if (JVMCIENV->isa_HotSpotResolvedJavaMethodImpl(hotspot_method)) {
method = JVMCIENV->asMethod(hotspot_method);
}
#endif
void CodeInstaller::pd_relocate_JavaMethod(CodeBuffer &, methodHandle& method, jint pc_offset, JVMCI_TRAPS) {
NativeCall* call = NULL;
switch (_next_call_type) {
case INLINE_INVOKE:
return;
case INVOKEVIRTUAL:
case INVOKEINTERFACE: {
assert(method == NULL || !method->is_static(), "cannot call static method with invokeinterface");
assert(!method->is_static(), "cannot call static method with invokeinterface");

call = nativeCall_at(_instructions->start() + pc_offset);
call->set_destination(SharedRuntime::get_resolve_virtual_call_stub());
Expand All @@ -171,7 +162,7 @@ void CodeInstaller::pd_relocate_JavaMethod(CodeBuffer &, JVMCIObject hotspot_met
break;
}
case INVOKESTATIC: {
assert(method == NULL || method->is_static(), "cannot call non-static method with invokestatic");
assert(method->is_static(), "cannot call non-static method with invokestatic");

call = nativeCall_at(_instructions->start() + pc_offset);
call->set_destination(SharedRuntime::get_resolve_static_call_stub());
Expand All @@ -180,7 +171,7 @@ void CodeInstaller::pd_relocate_JavaMethod(CodeBuffer &, JVMCIObject hotspot_met
break;
}
case INVOKESPECIAL: {
assert(method == NULL || !method->is_static(), "cannot call static method with invokespecial");
assert(!method->is_static(), "cannot call static method with invokespecial");
call = nativeCall_at(_instructions->start() + pc_offset);
call->set_destination(SharedRuntime::get_resolve_opt_virtual_call_stub());
_instructions->relocate(call->instruction_address(),
Expand Down
6 changes: 6 additions & 0 deletions src/hotspot/share/code/debugInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
// - ConstantValue describes a constant

class ConstantOopReadValue;
class ConstantOopWriteValue;
class LocationValue;
class ObjectValue;

Expand All @@ -62,6 +63,11 @@ class ScopeValue: public ResourceObj {
return (ConstantOopReadValue*) this;
}

ConstantOopWriteValue* as_ConstantOopWriteValue() {
assert(is_constant_oop(), "must be");
return (ConstantOopWriteValue*) this;
}

ObjectValue* as_ObjectValue() {
assert(is_object(), "must be");
return (ObjectValue*)this;
Expand Down
7 changes: 5 additions & 2 deletions src/hotspot/share/compiler/compileBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2735,8 +2735,11 @@ void CompileBroker::print_times(bool per_compiler, bool aggregate) {
}
#if INCLUDE_JVMCI
if (EnableJVMCI) {
tty->cr();
JVMCICompiler::print_hosted_timers();
JVMCICompiler *jvmci_comp = JVMCICompiler::instance(false, JavaThread::current_or_null());
if (jvmci_comp != nullptr && jvmci_comp != comp) {
tty->cr();
jvmci_comp->print_timers();
}
}
#endif

Expand Down

1 comment on commit ba670ec

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.