Skip to content

Commit 878d27d

Browse files
author
Doug Simon
committed
8317273: compiler/codecache/OverflowCodeCacheTest.java fails transiently on Graal
Reviewed-by: never, thartmann
1 parent 2637e8d commit 878d27d

File tree

5 files changed

+94
-17
lines changed

5 files changed

+94
-17
lines changed

src/hotspot/share/code/codeBlob.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,21 @@ RuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name,
414414
int frame_complete,
415415
int frame_size,
416416
OopMapSet* oop_maps,
417-
bool caller_must_gc_arguments)
417+
bool caller_must_gc_arguments,
418+
bool alloc_fail_is_fatal)
418419
{
419420
RuntimeStub* stub = nullptr;
420421
unsigned int size = CodeBlob::allocation_size(cb, sizeof(RuntimeStub));
421422
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
422423
{
423424
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
424425
stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments);
426+
if (stub == nullptr) {
427+
if (!alloc_fail_is_fatal) {
428+
return nullptr;
429+
}
430+
fatal("Initial size of CodeCache is too small");
431+
}
425432
}
426433

427434
trace_new_stub(stub, "RuntimeStub - ", stub_name);
@@ -431,9 +438,7 @@ RuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name,
431438

432439

433440
void* RuntimeStub::operator new(size_t s, unsigned size) throw() {
434-
void* p = CodeCache::allocate(size, CodeBlobType::NonNMethod);
435-
if (!p) fatal("Initial size of CodeCache is too small");
436-
return p;
441+
return CodeCache::allocate(size, CodeBlobType::NonNMethod);
437442
}
438443

439444
// operator new shared by all singletons:

src/hotspot/share/code/codeBlob.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ class RuntimeStub: public RuntimeBlob {
500500
int frame_complete,
501501
int frame_size,
502502
OopMapSet* oop_maps,
503-
bool caller_must_gc_arguments
503+
bool caller_must_gc_arguments,
504+
bool alloc_fail_is_fatal=true
504505
);
505506

506507
static void free(RuntimeStub* stub) { RuntimeBlob::free(stub); }

src/hotspot/share/jvmci/jvmciCodeInstaller.cpp

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "oops/klass.inline.hpp"
3737
#include "prims/jvmtiExport.hpp"
3838
#include "prims/methodHandles.hpp"
39+
#include "runtime/arguments.hpp"
3940
#include "runtime/interfaceSupport.inline.hpp"
4041
#include "runtime/jniHandles.inline.hpp"
4142
#include "runtime/os.hpp"
@@ -650,6 +651,53 @@ void CodeInstaller::initialize_dependencies(HotSpotCompiledCodeStream* stream, u
650651
}
651652
}
652653

654+
JVMCI::CodeInstallResult CodeInstaller::install_runtime_stub(CodeBlob*& cb,
655+
const char* name,
656+
CodeBuffer* buffer,
657+
int stack_slots,
658+
JVMCI_TRAPS) {
659+
if (name == nullptr) {
660+
JVMCI_ERROR_OK("stub should have a name");
661+
}
662+
663+
name = os::strdup(name);
664+
GrowableArray<RuntimeStub*> *stubs_to_free = nullptr;
665+
#ifdef ASSERT
666+
const char* val = Arguments::PropertyList_get_value(Arguments::system_properties(), "test.jvmci.forceRuntimeStubAllocFail");
667+
if (val != nullptr && strstr(name , val) != 0) {
668+
stubs_to_free = new GrowableArray<RuntimeStub*>();
669+
JVMCI_event_1("forcing allocation of %s in code cache to fail", name);
670+
}
671+
#endif
672+
673+
do {
674+
RuntimeStub* stub = RuntimeStub::new_runtime_stub(name,
675+
buffer,
676+
_offsets.value(CodeOffsets::Frame_Complete),
677+
stack_slots,
678+
_debug_recorder->_oopmaps,
679+
/* caller_must_gc_arguments */ false,
680+
/* alloc_fail_is_fatal */ false);
681+
cb = stub;
682+
if (stub == nullptr) {
683+
// Allocation failed
684+
#ifdef ASSERT
685+
if (stubs_to_free != nullptr) {
686+
JVMCI_event_1("allocation of %s in code cache failed, freeing %d stubs", name, stubs_to_free->length());
687+
for (GrowableArrayIterator<RuntimeStub*> iter = stubs_to_free->begin(); iter != stubs_to_free->end(); ++iter) {
688+
RuntimeStub::free(*iter);
689+
}
690+
}
691+
#endif
692+
return JVMCI::cache_full;
693+
}
694+
if (stubs_to_free == nullptr) {
695+
return JVMCI::ok;
696+
}
697+
stubs_to_free->append(stub);
698+
} while (true);
699+
}
700+
653701
JVMCI::CodeInstallResult CodeInstaller::install(JVMCICompiler* compiler,
654702
jlong compiled_code_buffer,
655703
bool with_type_info,
@@ -707,17 +755,7 @@ JVMCI::CodeInstallResult CodeInstaller::install(JVMCICompiler* compiler,
707755
int stack_slots = _total_frame_size / HeapWordSize; // conversion to words
708756

709757
if (!is_nmethod) {
710-
if (name == nullptr) {
711-
JVMCI_ERROR_OK("stub should have a name");
712-
}
713-
name = os::strdup(name); // Note: this leaks. See JDK-8289632
714-
cb = RuntimeStub::new_runtime_stub(name,
715-
&buffer,
716-
_offsets.value(CodeOffsets::Frame_Complete),
717-
stack_slots,
718-
_debug_recorder->_oopmaps,
719-
false);
720-
result = JVMCI::ok;
758+
return install_runtime_stub(cb, name, &buffer, stack_slots, JVMCI_CHECK_OK);
721759
} else {
722760
if (compile_state != nullptr) {
723761
jvmci_env()->set_compile_state(compile_state);

src/hotspot/share/jvmci/jvmciCodeInstaller.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,12 @@ class CodeInstaller : public StackObj {
399399
void read_virtual_objects(HotSpotCompiledCodeStream* stream, JVMCI_TRAPS);
400400

401401
int estimateStubSpace(int static_call_stubs);
402+
403+
JVMCI::CodeInstallResult install_runtime_stub(CodeBlob*& cb,
404+
const char* name,
405+
CodeBuffer* buffer,
406+
int stack_slots,
407+
JVMCI_TRAPS);
402408
};
403409

404410
#endif // SHARE_JVMCI_JVMCICODEINSTALLER_HPP

test/hotspot/jtreg/compiler/jvmci/events/JvmciNotifyInstallEventTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
* compiler.jvmci.common.JVMCIHelpers$EmptyVMEventListener
4949
* @run main/othervm -XX:+UnlockExperimentalVMOptions
5050
* -Djvmci.Compiler=EmptyCompiler -Xbootclasspath/a:.
51-
* -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI -XX:-UseJVMCINativeLibrary
51+
* -XX:+UseJVMCICompiler -XX:-BootstrapJVMCI
52+
* -XX:-UseJVMCINativeLibrary -XX:JVMCITraceLevel=1
53+
* -Dtest.jvmci.forceRuntimeStubAllocFail=test_stub_that_fails_to_be_allocated
5254
* compiler.jvmci.events.JvmciNotifyInstallEventTest
5355
* @run main/othervm -XX:+UnlockExperimentalVMOptions
5456
* -Djvmci.Compiler=EmptyCompiler -Xbootclasspath/a:.
@@ -62,8 +64,10 @@
6264
import compiler.jvmci.common.CTVMUtilities;
6365
import compiler.jvmci.common.testcases.SimpleClass;
6466
import jdk.test.lib.Asserts;
67+
import jdk.test.lib.Platform;
6568
import jdk.test.lib.Utils;
6669
import jdk.vm.ci.services.JVMCIServiceLocator;
70+
import jdk.vm.ci.code.BailoutException;
6771
import jdk.vm.ci.code.CompiledCode;
6872
import jdk.vm.ci.code.InstalledCode;
6973
import jdk.vm.ci.code.site.DataPatch;
@@ -142,6 +146,29 @@ private void runTest() {
142146
}, NullPointerException.class);
143147
Asserts.assertEQ(gotInstallNotification, 2,
144148
"Got unexpected event count after 4th install attempt");
149+
150+
String stubToFail = System.getProperty("test.jvmci.forceRuntimeStubAllocFail");
151+
if (Platform.isDebugBuild() && stubToFail != null) {
152+
HotSpotCompiledCode stub = new HotSpotCompiledCode(stubToFail,
153+
/* targetCode */ new byte[0],
154+
/* targetCodeSize */ 0,
155+
/* sites */ new Site[0],
156+
/* assumptions */ new Assumption[0],
157+
/* methods */ new ResolvedJavaMethod[0],
158+
/* comments */ new Comment[0],
159+
/* dataSection */ new byte[0],
160+
dataSectionAlignment,
161+
/* dataSectionPatches */ new DataPatch[0],
162+
/* isImmutablePIC */ false,
163+
/* totalFrameSize */ 0,
164+
/* deoptRescueSlot */ null);
165+
try {
166+
codeCache.installCode(null, stub, null, null, true);
167+
throw new AssertionError("Didn't get expected " + BailoutException.class.getName());
168+
} catch (BailoutException e) {
169+
Asserts.assertEQ(e.getMessage(), "Error installing " + stubToFail + ": code cache is full");
170+
}
171+
}
145172
}
146173

147174
@Override

0 commit comments

Comments
 (0)