Skip to content

Commit c36ec2c

Browse files
dlunderobcasloz
authored andcommittedNov 16, 2023
8316653: Large NMethodSizeLimit triggers assert during C1 code buffer allocation
Reviewed-by: kvn, rcastanedalo, thartmann
1 parent 2db9ea9 commit c36ec2c

File tree

8 files changed

+28
-14
lines changed

8 files changed

+28
-14
lines changed
 

‎src/hotspot/share/c1/c1_Compilation.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ class Compilation: public StackObj {
213213
bool bailed_out() const { return _bailout_msg != nullptr; }
214214
const char* bailout_msg() const { return _bailout_msg; }
215215

216-
static int desired_max_code_buffer_size() {
217-
return (int)NMethodSizeLimit; // default 64K
216+
static uint desired_max_code_buffer_size() {
217+
return (uint)NMethodSizeLimit; // default 64K
218218
}
219-
static int desired_max_constant_size() {
219+
static uint desired_max_constant_size() {
220220
return desired_max_code_buffer_size() / 10;
221221
}
222222

‎src/hotspot/share/c1/c1_Compiler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void Compiler::initialize() {
7777
}
7878
}
7979

80-
int Compiler::code_buffer_size() {
80+
uint Compiler::code_buffer_size() {
8181
return Compilation::desired_max_code_buffer_size() + Compilation::desired_max_constant_size();
8282
}
8383

‎src/hotspot/share/c1/c1_Compiler.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Compiler: public AbstractCompiler {
6060
static bool is_intrinsic_supported(vmIntrinsics::ID id);
6161

6262
// Size of the code buffer
63-
static int code_buffer_size();
63+
static uint code_buffer_size();
6464
};
6565

6666
#endif // SHARE_C1_C1_COMPILER_HPP

‎src/hotspot/share/code/codeBlob.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ BufferBlob::BufferBlob(const char* name, int size)
249249
: RuntimeBlob(name, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, /*locs_size:*/ 0)
250250
{}
251251

252-
BufferBlob* BufferBlob::create(const char* name, int buffer_size) {
252+
BufferBlob* BufferBlob::create(const char* name, uint buffer_size) {
253253
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
254254

255255
BufferBlob* blob = nullptr;

‎src/hotspot/share/code/codeBlob.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class BufferBlob: public RuntimeBlob {
410410

411411
public:
412412
// Creation
413-
static BufferBlob* create(const char* name, int buffer_size);
413+
static BufferBlob* create(const char* name, uint buffer_size);
414414
static BufferBlob* create(const char* name, CodeBuffer* cb);
415415

416416
static void free(BufferBlob* buf);

‎src/hotspot/share/code/codeCache.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,10 @@ CodeBlob* CodeCache::next_blob(CodeHeap* heap, CodeBlob* cb) {
520520
* run the constructor for the CodeBlob subclass he is busy
521521
* instantiating.
522522
*/
523-
CodeBlob* CodeCache::allocate(int size, CodeBlobType code_blob_type, bool handle_alloc_failure, CodeBlobType orig_code_blob_type) {
523+
CodeBlob* CodeCache::allocate(uint size, CodeBlobType code_blob_type, bool handle_alloc_failure, CodeBlobType orig_code_blob_type) {
524524
assert_locked_or_safepoint(CodeCache_lock);
525-
assert(size > 0, "Code cache allocation request must be > 0 but is %d", size);
526-
if (size <= 0) {
525+
assert(size > 0, "Code cache allocation request must be > 0");
526+
if (size == 0) {
527527
return nullptr;
528528
}
529529
CodeBlob* cb = nullptr;
@@ -1575,10 +1575,14 @@ void CodeCache::print_memory_overhead() {
15751575

15761576
#ifndef PRODUCT
15771577

1578-
void CodeCache::print_trace(const char* event, CodeBlob* cb, int size) {
1578+
void CodeCache::print_trace(const char* event, CodeBlob* cb, uint size) {
15791579
if (PrintCodeCache2) { // Need to add a new flag
15801580
ResourceMark rm;
1581-
if (size == 0) size = cb->size();
1581+
if (size == 0) {
1582+
int s = cb->size();
1583+
assert(s >= 0, "CodeBlob size is negative: %d", s);
1584+
size = (uint) s;
1585+
}
15821586
tty->print_cr("CodeCache %s: addr: " INTPTR_FORMAT ", size: 0x%x", event, p2i(cb), size);
15831587
}
15841588
}

‎src/hotspot/share/code/codeCache.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class CodeCache : AllStatic {
149149
static const GrowableArray<CodeHeap*>* nmethod_heaps() { return _nmethod_heaps; }
150150

151151
// Allocation/administration
152-
static CodeBlob* allocate(int size, CodeBlobType code_blob_type, bool handle_alloc_failure = true, CodeBlobType orig_code_blob_type = CodeBlobType::All); // allocates a new CodeBlob
152+
static CodeBlob* allocate(uint size, CodeBlobType code_blob_type, bool handle_alloc_failure = true, CodeBlobType orig_code_blob_type = CodeBlobType::All); // allocates a new CodeBlob
153153
static void commit(CodeBlob* cb); // called when the allocated CodeBlob has been filled
154154
static void free(CodeBlob* cb); // frees a CodeBlob
155155
static void free_unused_tail(CodeBlob* cb, size_t used); // frees the unused tail of a CodeBlob (only used by TemplateInterpreter::initialize())
@@ -226,7 +226,7 @@ class CodeCache : AllStatic {
226226
static void print_internals();
227227
static void print_memory_overhead();
228228
static void verify(); // verifies the code cache
229-
static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN;
229+
static void print_trace(const char* event, CodeBlob* cb, uint size = 0) PRODUCT_RETURN;
230230
static void print_summary(outputStream* st, bool detailed = true); // Prints a summary of the code cache usage
231231
static void log_state(outputStream* st);
232232
LINUX_ONLY(static void write_perf_map();)

‎test/hotspot/jtreg/compiler/arguments/TestC1Globals.java

+10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@
4141
* compiler.arguments.TestC1Globals
4242
*/
4343

44+
/**
45+
* @test
46+
* @bug 8316653
47+
* @requires vm.debug
48+
* @summary Test flag with max value
49+
*
50+
* @run main/othervm -XX:NMethodSizeLimit=2147483647
51+
* compiler.arguments.TestC1Globals
52+
*/
53+
4454
/**
4555
* @test
4656
* @bug 8318817

0 commit comments

Comments
 (0)
Please sign in to comment.