Skip to content

Commit ad326fc

Browse files
author
Doug Simon
committed
8299570: [JVMCI] Insufficient error handling when CodeBuffer is exhausted
Reviewed-by: never, adinn, aph
1 parent 05ceb37 commit ad326fc

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed

src/hotspot/cpu/aarch64/jvmciCodeInstaller_aarch64.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,21 @@ void CodeInstaller::pd_relocate_JavaMethod(CodeBuffer &cbuf, methodHandle& metho
130130
assert(!method->is_static(), "cannot call static method with invokeinterface");
131131
NativeCall* call = nativeCall_at(_instructions->start() + pc_offset);
132132
_instructions->relocate(call->instruction_address(), virtual_call_Relocation::spec(_invoke_mark_pc));
133-
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_virtual_call_stub());
133+
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_virtual_call_stub(), JVMCI_CHECK);
134134
break;
135135
}
136136
case INVOKESTATIC: {
137137
assert(method->is_static(), "cannot call non-static method with invokestatic");
138138
NativeCall* call = nativeCall_at(_instructions->start() + pc_offset);
139139
_instructions->relocate(call->instruction_address(), relocInfo::static_call_type);
140-
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_static_call_stub());
140+
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_static_call_stub(), JVMCI_CHECK);
141141
break;
142142
}
143143
case INVOKESPECIAL: {
144144
assert(!method->is_static(), "cannot call static method with invokespecial");
145145
NativeCall* call = nativeCall_at(_instructions->start() + pc_offset);
146146
_instructions->relocate(call->instruction_address(), relocInfo::opt_virtual_call_type);
147-
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_opt_virtual_call_stub());
147+
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_opt_virtual_call_stub(), JVMCI_CHECK);
148148
break;
149149
}
150150
default:

src/hotspot/cpu/aarch64/nativeInst_aarch64.cpp

+19-13
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
#ifdef COMPILER1
4040
#include "c1/c1_Runtime1.hpp"
4141
#endif
42+
#if INCLUDE_JVMCI
43+
#include "jvmci/jvmciEnv.hpp"
44+
#endif
4245

4346
void NativeCall::verify() {
4447
assert(NativeCall::is_call_at((address)this), "unexpected code at call site");
@@ -523,26 +526,29 @@ void NativeCallTrampolineStub::set_destination(address new_destination) {
523526
OrderAccess::release();
524527
}
525528

529+
#if INCLUDE_JVMCI
526530
// Generate a trampoline for a branch to dest. If there's no need for a
527531
// trampoline, simply patch the call directly to dest.
528-
address NativeCall::trampoline_jump(CodeBuffer &cbuf, address dest) {
532+
void NativeCall::trampoline_jump(CodeBuffer &cbuf, address dest, JVMCI_TRAPS) {
529533
MacroAssembler a(&cbuf);
530-
address stub = NULL;
531-
532-
if (a.far_branches()
533-
&& ! is_NativeCallTrampolineStub_at(instruction_address() + displacement())) {
534-
stub = a.emit_trampoline_stub(instruction_address() - cbuf.insts()->start(), dest);
535-
}
536534

537-
if (stub == NULL) {
538-
// If we generated no stub, patch this call directly to dest.
539-
// This will happen if we don't need far branches or if there
540-
// already was a trampoline.
535+
if (!a.far_branches()) {
536+
// If not using far branches, patch this call directly to dest.
541537
set_destination(dest);
538+
} else if (!is_NativeCallTrampolineStub_at(instruction_address() + displacement())) {
539+
// If we want far branches and there isn't a trampoline stub, emit one.
540+
address stub = a.emit_trampoline_stub(instruction_address() - cbuf.insts()->start(), dest);
541+
if (stub == nullptr) {
542+
JVMCI_ERROR("could not emit trampoline stub - code cache is full");
543+
}
544+
// The relocation created while emitting the stub will ensure this
545+
// call instruction is subsequently patched to call the stub.
546+
} else {
547+
// Not sure how this can be happen but be defensive
548+
JVMCI_ERROR("single-use stub should not exist");
542549
}
543-
544-
return stub;
545550
}
551+
#endif
546552

547553
void NativePostCallNop::make_deopt() {
548554
NativeDeoptInstruction::insert(addr_at(0));

src/hotspot/cpu/aarch64/nativeInst_aarch64.hpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
#include "asm/assembler.hpp"
3030
#include "runtime/icache.hpp"
3131
#include "runtime/os.hpp"
32+
#include "runtime/os.hpp"
33+
#if INCLUDE_JVMCI
34+
#include "jvmci/jvmciExceptions.hpp"
35+
#endif
36+
3237

3338
// We have interfaces for the following instructions:
3439
// - NativeInstruction
@@ -251,7 +256,9 @@ class NativeCall: public NativeInstruction {
251256
void set_destination_mt_safe(address dest, bool assert_lock = true);
252257

253258
address get_trampoline();
254-
address trampoline_jump(CodeBuffer &cbuf, address dest);
259+
#if INCLUDE_JVMCI
260+
void trampoline_jump(CodeBuffer &cbuf, address dest, JVMCI_TRAPS);
261+
#endif
255262
};
256263

257264
inline NativeCall* nativeCall_at(address address) {

src/hotspot/share/code/compiledIC.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ class StaticCallInfo {
338338
class CompiledStaticCall : public ResourceObj {
339339
public:
340340
// Code
341+
342+
// Returns NULL if CodeBuffer::expand fails
341343
static address emit_to_interp_stub(CodeBuffer &cbuf, address mark = nullptr);
342344
static int to_interp_stub_size();
343345
static int to_trampoline_stub_size();

src/hotspot/share/jvmci/jvmciCodeInstaller.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,9 @@ void CodeInstaller::site_Call(CodeBuffer& buffer, u1 tag, jint pc_offset, HotSpo
11781178
CodeInstaller::pd_relocate_JavaMethod(buffer, method, pc_offset, JVMCI_CHECK);
11791179
if (_next_call_type == INVOKESTATIC || _next_call_type == INVOKESPECIAL) {
11801180
// Need a static call stub for transitions from compiled to interpreted.
1181-
CompiledStaticCall::emit_to_interp_stub(buffer, _instructions->start() + pc_offset);
1181+
if (CompiledStaticCall::emit_to_interp_stub(buffer, _instructions->start() + pc_offset) == nullptr) {
1182+
JVMCI_ERROR("could not emit to_interp stub - code cache is full");
1183+
}
11821184
}
11831185
}
11841186

0 commit comments

Comments
 (0)