Skip to content

Commit 3a0aff2

Browse files
committed
8299570: [JVMCI] Insufficient error handling when CodeBuffer is exhausted
Reviewed-by: shade Backport-of: ad326fc62be9fa29438fb4b59a51c38dd94afd68
1 parent 86aca8b commit 3a0aff2

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
@@ -138,21 +138,21 @@ void CodeInstaller::pd_relocate_JavaMethod(CodeBuffer &cbuf, JVMCIObject hotspot
138138
assert(method == NULL || !method->is_static(), "cannot call static method with invokeinterface");
139139
NativeCall* call = nativeCall_at(_instructions->start() + pc_offset);
140140
_instructions->relocate(call->instruction_address(), virtual_call_Relocation::spec(_invoke_mark_pc));
141-
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_virtual_call_stub());
141+
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_virtual_call_stub(), JVMCI_CHECK);
142142
break;
143143
}
144144
case INVOKESTATIC: {
145145
assert(method == NULL || method->is_static(), "cannot call non-static method with invokestatic");
146146
NativeCall* call = nativeCall_at(_instructions->start() + pc_offset);
147147
_instructions->relocate(call->instruction_address(), relocInfo::static_call_type);
148-
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_static_call_stub());
148+
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_static_call_stub(), JVMCI_CHECK);
149149
break;
150150
}
151151
case INVOKESPECIAL: {
152152
assert(method == NULL || !method->is_static(), "cannot call static method with invokespecial");
153153
NativeCall* call = nativeCall_at(_instructions->start() + pc_offset);
154154
_instructions->relocate(call->instruction_address(), relocInfo::opt_virtual_call_type);
155-
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_opt_virtual_call_stub());
155+
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_opt_virtual_call_stub(), JVMCI_CHECK);
156156
break;
157157
}
158158
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");
@@ -524,23 +527,26 @@ void NativeCallTrampolineStub::set_destination(address new_destination) {
524527
OrderAccess::release();
525528
}
526529

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

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

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 = NULL);
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
@@ -1147,7 +1147,9 @@ void CodeInstaller::site_Call(CodeBuffer& buffer, jint pc_offset, JVMCIObject si
11471147
CodeInstaller::pd_relocate_JavaMethod(buffer, hotspot_method, pc_offset, JVMCI_CHECK);
11481148
if (_next_call_type == INVOKESTATIC || _next_call_type == INVOKESPECIAL) {
11491149
// Need a static call stub for transitions from compiled to interpreted.
1150-
CompiledStaticCall::emit_to_interp_stub(buffer, _instructions->start() + pc_offset);
1150+
if (CompiledStaticCall::emit_to_interp_stub(buffer, _instructions->start() + pc_offset) == nullptr) {
1151+
JVMCI_ERROR("could not emit to_interp stub - code cache is full");
1152+
}
11511153
}
11521154
}
11531155

0 commit comments

Comments
 (0)