Skip to content

Commit 6115652

Browse files
committed
Initial JVMCI support for Valhalla.
1 parent 67d181d commit 6115652

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1650
-98
lines changed

src/hotspot/cpu/aarch64/jvmciCodeInstaller_aarch64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,23 @@ void CodeInstaller::pd_relocate_JavaMethod(CodeBuffer &cbuf, methodHandle& metho
133133
case INVOKEINTERFACE: {
134134
assert(!method->is_static(), "cannot call static method with invokeinterface");
135135
call = nativeCall_at(_instructions->start() + pc_offset);
136+
// TODO: attach method for valhalla calling convention see jvmciCodeInstaller_x86.cpp
136137
_instructions->relocate(call->instruction_address(), virtual_call_Relocation::spec(_invoke_mark_pc));
137138
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_virtual_call_stub(), JVMCI_CHECK);
138139
break;
139140
}
140141
case INVOKESTATIC: {
141142
assert(method->is_static(), "cannot call non-static method with invokestatic");
142143
call = nativeCall_at(_instructions->start() + pc_offset);
144+
// TODO: attach method for valhalla calling convention see jvmciCodeInstaller_x86.cpp
143145
_instructions->relocate(call->instruction_address(), relocInfo::static_call_type);
144146
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_static_call_stub(), JVMCI_CHECK);
145147
break;
146148
}
147149
case INVOKESPECIAL: {
148150
assert(!method->is_static(), "cannot call static method with invokespecial");
149151
call = nativeCall_at(_instructions->start() + pc_offset);
152+
// TODO: attach method for valhalla calling convention see jvmciCodeInstaller_x86.cpp
150153
_instructions->relocate(call->instruction_address(), relocInfo::opt_virtual_call_type);
151154
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_opt_virtual_call_stub(), JVMCI_CHECK);
152155
break;

src/hotspot/cpu/x86/jvmciCodeInstaller_x86.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,26 +164,48 @@ void CodeInstaller::pd_relocate_JavaMethod(CodeBuffer &, methodHandle& method, j
164164

165165
call = nativeCall_at(_instructions->start() + pc_offset);
166166
call->set_destination(SharedRuntime::get_resolve_virtual_call_stub());
167+
if (method->has_scalarized_args() && !method->mismatch()) {
167168
_instructions->relocate(call->instruction_address(),
168-
virtual_call_Relocation::spec(_invoke_mark_pc),
169+
virtual_call_Relocation::spec(_invoke_mark_pc, _oop_recorder->find_index(method())),
169170
Assembler::call32_operand);
171+
} else {
172+
_instructions->relocate(call->instruction_address(),
173+
virtual_call_Relocation::spec(_invoke_mark_pc),
174+
Assembler::call32_operand);
175+
}
170176
break;
171177
}
172178
case INVOKESTATIC: {
173179
assert(method->is_static(), "cannot call non-static method with invokestatic");
174180

175181
call = nativeCall_at(_instructions->start() + pc_offset);
176182
call->set_destination(SharedRuntime::get_resolve_static_call_stub());
177-
_instructions->relocate(call->instruction_address(),
183+
// calls to the ValueObjectMethods class do not exist in bytecode, need to attach them
184+
if (method->has_scalarized_args() || method() == Universe::is_substitutable_method() || method() == Universe::value_object_hash_code_method()) {
185+
_instructions->relocate(call->instruction_address(),
186+
relocInfo::static_call_type, Assembler::call32_operand,_oop_recorder->find_index(method()));
187+
}else{
188+
_instructions->relocate(call->instruction_address(),
178189
relocInfo::static_call_type, Assembler::call32_operand);
190+
}
191+
179192
break;
180193
}
181194
case INVOKESPECIAL: {
182195
assert(!method->is_static(), "cannot call static method with invokespecial");
183196
call = nativeCall_at(_instructions->start() + pc_offset);
184197
call->set_destination(SharedRuntime::get_resolve_opt_virtual_call_stub());
185-
_instructions->relocate(call->instruction_address(),
198+
199+
// attach the target method only for scalarized args to avoid a null check on the receiver if receiver was optimized from non-scalarized to scalarized
200+
// attach only for scalarized args otherwise assert(attached_method->has_scalarized_args(), "invalid use of attached method"); will trigger
201+
// see resolved_method_index in machnode.hpp
202+
if (method->has_scalarized_args() && !method->mismatch()) {
203+
_instructions->relocate(call->instruction_address(),
204+
relocInfo::opt_virtual_call_type, Assembler::call32_operand, _oop_recorder->find_index(method()));
205+
} else {
206+
_instructions->relocate(call->instruction_address(),
186207
relocInfo::opt_virtual_call_type, Assembler::call32_operand);
208+
}
187209
break;
188210
}
189211
default:

src/hotspot/share/code/nmethod.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ void nmethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map
727727

728728
// If inline types are passed as fields, use the extended signature
729729
// which contains the types of all (oop) fields of the inline type.
730-
if (is_compiled_by_c2() && callee->has_scalarized_args()) {
730+
if ((is_compiled_by_c2() || is_compiled_by_jvmci()) && callee->has_scalarized_args()) {
731731
const GrowableArray<SigEntry>* sig = callee->adapter()->get_sig_cc();
732732
assert(sig != nullptr, "sig should never be null");
733733
TempNewSymbol tmp_sig = SigEntry::create_symbol(sig);

src/hotspot/share/code/nmethod.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ class nmethod : public CodeBlob {
685685
bool needs_stack_repair() const {
686686
if (is_compiled_by_c1()) {
687687
return method()->c1_needs_stack_repair();
688-
} else if (is_compiled_by_c2()) {
688+
} else if (is_compiled_by_c2() || is_compiled_by_jvmci()) {
689689
return method()->c2_needs_stack_repair();
690690
} else {
691691
return false;

src/hotspot/share/jvmci/jvmciCodeInstaller.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#include "runtime/os.hpp"
4242
#include "runtime/sharedRuntime.hpp"
4343
#include "utilities/align.hpp"
44+
#include "ci/ciSignature.hpp"
45+
#include "oops/inlineKlass.hpp"
46+
#include "runtime/globals.hpp"
4447

4548
// frequently used constants
4649
// Allocate them with new so they are never destroyed (otherwise, a
@@ -778,6 +781,14 @@ JVMCI::CodeInstallResult CodeInstaller::install(JVMCICompiler* compiler,
778781
JVMCI_THROW_MSG_(IllegalArgumentException, "nmethod entry barrier is missing", JVMCI::ok);
779782
}
780783

784+
if(_offsets.value(CodeOffsets::Verified_Inline_Entry) == -1) {
785+
_offsets.set_value(CodeOffsets::Verified_Inline_Entry, _offsets.value(CodeOffsets::Verified_Entry));
786+
}
787+
788+
if(_offsets.value(CodeOffsets::Verified_Inline_Entry_RO) == -1) {
789+
_offsets.set_value(CodeOffsets::Verified_Inline_Entry_RO, _offsets.value(CodeOffsets::Verified_Entry));
790+
}
791+
781792
JVMCIObject mirror = installed_code;
782793
nmethod* nm = nullptr; // nm is an out parameter of register_method
783794
result = runtime()->register_method(jvmci_env(),
@@ -1098,9 +1109,19 @@ void CodeInstaller::read_virtual_objects(HotSpotCompiledCodeStream* stream, JVMC
10981109
if (is_auto_box) {
10991110
_has_auto_box = true;
11001111
}
1112+
// see code in output.cpp (PhaseOutput::FillLocArray)
1113+
bool check_is_not_null = stream->read_bool("nonNull");
1114+
ScopeValue *is_init = nullptr;
1115+
if (check_is_not_null) {
1116+
ScopeValue* cur_second = nullptr;
1117+
BasicType type = (BasicType) stream->read_u1("basicType");
1118+
ScopeValue* value;
1119+
u1 tag = stream->read_u1("tag");
1120+
is_init = get_scope_value(stream, tag, type, cur_second, JVMCI_CHECK);
1121+
}
11011122
oop javaMirror = klass->java_mirror();
11021123
ScopeValue *klass_sv = new ConstantOopWriteValue(JNIHandles::make_local(javaMirror));
1103-
ObjectValue* sv = is_auto_box ? new AutoBoxObjectValue(id, klass_sv) : new ObjectValue(id, klass_sv);
1124+
ObjectValue* sv = is_auto_box ? new AutoBoxObjectValue(id, klass_sv) : new ObjectValue(id, klass_sv, true, is_init);
11041125
objects->at_put(id, sv);
11051126
}
11061127
// All the values which could be referenced by the VirtualObjects
@@ -1128,6 +1149,18 @@ int CodeInstaller::map_jvmci_bci(int bci) {
11281149
return bci;
11291150
}
11301151

1152+
bool has_scalarized_return(methodHandle& methodHandle){
1153+
if (!InlineTypeReturnedAsFields) {
1154+
return false;
1155+
}
1156+
Method* method = methodHandle();
1157+
InlineKlass* klass = method->returns_inline_type(Thread::current());
1158+
if (klass != nullptr) {
1159+
return !method->is_native() && klass->can_be_returned_as_fields();
1160+
}
1161+
return false;
1162+
}
1163+
11311164
void CodeInstaller::record_scope(jint pc_offset, HotSpotCompiledCodeStream* stream, u1 debug_info_flags, bool full_info, bool is_mh_invoke, bool return_oop, JVMCI_TRAPS) {
11321165
if (full_info) {
11331166
read_virtual_objects(stream, JVMCI_CHECK);
@@ -1169,7 +1202,7 @@ void CodeInstaller::record_scope(jint pc_offset, HotSpotCompiledCodeStream* stre
11691202
}
11701203

11711204
// has_ea_local_in_scope and arg_escape should be added to JVMCI
1172-
const bool return_scalarized = false;
1205+
const bool return_scalarized = has_scalarized_return(method);
11731206
const bool has_ea_local_in_scope = false;
11741207
const bool arg_escape = false;
11751208
_debug_recorder->describe_scope(pc_offset, method, nullptr, bci, reexecute, rethrow_exception, is_mh_invoke, return_oop,
@@ -1315,9 +1348,16 @@ void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, HotSpotCompile
13151348
case UNVERIFIED_ENTRY:
13161349
_offsets.set_value(CodeOffsets::Entry, pc_offset);
13171350
break;
1351+
case INLINE_ENTRY:
1352+
_offsets.set_value(CodeOffsets::Inline_Entry, pc_offset);
1353+
break;
13181354
case VERIFIED_ENTRY:
13191355
_offsets.set_value(CodeOffsets::Verified_Entry, pc_offset);
1356+
break;
1357+
case VERIFIED_INLINE_ENTRY:
13201358
_offsets.set_value(CodeOffsets::Verified_Inline_Entry, pc_offset);
1359+
break;
1360+
case VERIFIED_INLINE_ENTRY_RO:
13211361
_offsets.set_value(CodeOffsets::Verified_Inline_Entry_RO, pc_offset);
13221362
break;
13231363
case OSR_ENTRY:

src/hotspot/share/jvmci/jvmciCodeInstaller.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ class CodeInstaller : public StackObj {
147147
enum MarkId {
148148
INVALID_MARK,
149149
VERIFIED_ENTRY,
150+
VERIFIED_INLINE_ENTRY,
151+
VERIFIED_INLINE_ENTRY_RO,
150152
UNVERIFIED_ENTRY,
153+
INLINE_ENTRY,
151154
OSR_ENTRY,
152155
EXCEPTION_HANDLER_ENTRY,
153156
DEOPT_HANDLER_ENTRY,

0 commit comments

Comments
 (0)