Skip to content

Commit dd7f2d9

Browse files
xmas92fisk
authored andcommittedAug 5, 2022
8290090: Change CodeBlobType from unscoped enum to enum class
Reviewed-by: eosterlund, kvn
1 parent 4c652d9 commit dd7f2d9

File tree

11 files changed

+74
-71
lines changed

11 files changed

+74
-71
lines changed
 

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

+6-8
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@ class OopMapSet;
4141

4242
// CodeBlob Types
4343
// Used in the CodeCache to assign CodeBlobs to different CodeHeaps
44-
struct CodeBlobType {
45-
enum {
46-
MethodNonProfiled = 0, // Execution level 1 and 4 (non-profiled) nmethods (including native nmethods)
47-
MethodProfiled = 1, // Execution level 2 and 3 (profiled) nmethods
48-
NonNMethod = 2, // Non-nmethods like Buffers, Adapters and Runtime Stubs
49-
All = 3, // All types (No code cache segmentation)
50-
NumTypes = 4 // Number of CodeBlobTypes
51-
};
44+
enum class CodeBlobType {
45+
MethodNonProfiled = 0, // Execution level 1 and 4 (non-profiled) nmethods (including native nmethods)
46+
MethodProfiled = 1, // Execution level 2 and 3 (profiled) nmethods
47+
NonNMethod = 2, // Non-nmethods like Buffers, Adapters and Runtime Stubs
48+
All = 3, // All types (No code cache segmentation)
49+
NumTypes = 4 // Number of CodeBlobTypes
5250
};
5351

5452
// CodeBlob - superclass for all entries in the CodeCache.

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

+25-22
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ int CodeCache::Sweep::_compiled_method_iterators = 0;
173173
bool CodeCache::Sweep::_pending_sweep = false;
174174

175175
// Initialize arrays of CodeHeap subsets
176-
GrowableArray<CodeHeap*>* CodeCache::_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<CodeHeap*> (CodeBlobType::All, mtCode);
177-
GrowableArray<CodeHeap*>* CodeCache::_compiled_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<CodeHeap*> (CodeBlobType::All, mtCode);
178-
GrowableArray<CodeHeap*>* CodeCache::_nmethod_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<CodeHeap*> (CodeBlobType::All, mtCode);
179-
GrowableArray<CodeHeap*>* CodeCache::_allocable_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<CodeHeap*> (CodeBlobType::All, mtCode);
176+
GrowableArray<CodeHeap*>* CodeCache::_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<CodeHeap*> (static_cast<int>(CodeBlobType::All), mtCode);
177+
GrowableArray<CodeHeap*>* CodeCache::_compiled_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<CodeHeap*> (static_cast<int>(CodeBlobType::All), mtCode);
178+
GrowableArray<CodeHeap*>* CodeCache::_nmethod_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<CodeHeap*> (static_cast<int>(CodeBlobType::All), mtCode);
179+
GrowableArray<CodeHeap*>* CodeCache::_allocable_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<CodeHeap*> (static_cast<int>(CodeBlobType::All), mtCode);
180180

181181
void CodeCache::check_heap_sizes(size_t non_nmethod_size, size_t profiled_size, size_t non_profiled_size, size_t cache_size, bool all_set) {
182182
size_t total_size = non_nmethod_size + profiled_size + non_profiled_size;
@@ -370,7 +370,7 @@ ReservedCodeSpace CodeCache::reserve_heap_memory(size_t size) {
370370
}
371371

372372
// Heaps available for allocation
373-
bool CodeCache::heap_available(int code_blob_type) {
373+
bool CodeCache::heap_available(CodeBlobType code_blob_type) {
374374
if (!SegmentedCodeCache) {
375375
// No segmentation: use a single code heap
376376
return (code_blob_type == CodeBlobType::All);
@@ -387,7 +387,7 @@ bool CodeCache::heap_available(int code_blob_type) {
387387
}
388388
}
389389

390-
const char* CodeCache::get_code_heap_flag_name(int code_blob_type) {
390+
const char* CodeCache::get_code_heap_flag_name(CodeBlobType code_blob_type) {
391391
switch(code_blob_type) {
392392
case CodeBlobType::NonNMethod:
393393
return "NonNMethodCodeHeapSize";
@@ -398,16 +398,17 @@ const char* CodeCache::get_code_heap_flag_name(int code_blob_type) {
398398
case CodeBlobType::MethodProfiled:
399399
return "ProfiledCodeHeapSize";
400400
break;
401+
default:
402+
ShouldNotReachHere();
403+
return NULL;
401404
}
402-
ShouldNotReachHere();
403-
return NULL;
404405
}
405406

406407
int CodeCache::code_heap_compare(CodeHeap* const &lhs, CodeHeap* const &rhs) {
407408
if (lhs->code_blob_type() == rhs->code_blob_type()) {
408409
return (lhs > rhs) ? 1 : ((lhs < rhs) ? -1 : 0);
409410
} else {
410-
return lhs->code_blob_type() - rhs->code_blob_type();
411+
return static_cast<int>(lhs->code_blob_type()) - static_cast<int>(rhs->code_blob_type());
411412
}
412413
}
413414

@@ -416,7 +417,7 @@ void CodeCache::add_heap(CodeHeap* heap) {
416417

417418
_heaps->insert_sorted<code_heap_compare>(heap);
418419

419-
int type = heap->code_blob_type();
420+
CodeBlobType type = heap->code_blob_type();
420421
if (code_blob_type_accepts_compiled(type)) {
421422
_compiled_heaps->insert_sorted<code_heap_compare>(heap);
422423
}
@@ -428,7 +429,7 @@ void CodeCache::add_heap(CodeHeap* heap) {
428429
}
429430
}
430431

431-
void CodeCache::add_heap(ReservedSpace rs, const char* name, int code_blob_type) {
432+
void CodeCache::add_heap(ReservedSpace rs, const char* name, CodeBlobType code_blob_type) {
432433
// Check if heap is needed
433434
if (!heap_available(code_blob_type)) {
434435
return;
@@ -470,7 +471,7 @@ CodeHeap* CodeCache::get_code_heap(const CodeBlob* cb) {
470471
return NULL;
471472
}
472473

473-
CodeHeap* CodeCache::get_code_heap(int code_blob_type) {
474+
CodeHeap* CodeCache::get_code_heap(CodeBlobType code_blob_type) {
474475
FOR_ALL_HEAPS(heap) {
475476
if ((*heap)->accepts(code_blob_type)) {
476477
return *heap;
@@ -519,7 +520,7 @@ CodeBlob* CodeCache::first_blob(CodeHeap* heap) {
519520
return (CodeBlob*)heap->first();
520521
}
521522

522-
CodeBlob* CodeCache::first_blob(int code_blob_type) {
523+
CodeBlob* CodeCache::first_blob(CodeBlobType code_blob_type) {
523524
if (heap_available(code_blob_type)) {
524525
return first_blob(get_code_heap(code_blob_type));
525526
} else {
@@ -540,7 +541,7 @@ CodeBlob* CodeCache::next_blob(CodeHeap* heap, CodeBlob* cb) {
540541
* run the constructor for the CodeBlob subclass he is busy
541542
* instantiating.
542543
*/
543-
CodeBlob* CodeCache::allocate(int size, int code_blob_type, bool handle_alloc_failure, int orig_code_blob_type) {
544+
CodeBlob* CodeCache::allocate(int size, CodeBlobType code_blob_type, bool handle_alloc_failure, CodeBlobType orig_code_blob_type) {
544545
// Possibly wakes up the sweeper thread.
545546
NMethodSweeper::report_allocation();
546547
assert_locked_or_safepoint(CodeCache_lock);
@@ -568,7 +569,7 @@ CodeBlob* CodeCache::allocate(int size, int code_blob_type, bool handle_alloc_fa
568569
// NonNMethod -> MethodNonProfiled -> MethodProfiled (-> MethodNonProfiled)
569570
// Note that in the sweeper, we check the reverse_free_ratio of the code heap
570571
// and force stack scanning if less than 10% of the entire code cache are free.
571-
int type = code_blob_type;
572+
CodeBlobType type = code_blob_type;
572573
switch (type) {
573574
case CodeBlobType::NonNMethod:
574575
type = CodeBlobType::MethodNonProfiled;
@@ -582,6 +583,8 @@ CodeBlob* CodeCache::allocate(int size, int code_blob_type, bool handle_alloc_fa
582583
type = CodeBlobType::MethodNonProfiled;
583584
}
584585
break;
586+
default:
587+
break;
585588
}
586589
if (type != code_blob_type && type != orig_code_blob_type && heap_available(type)) {
587590
if (PrintCodeCacheExtension) {
@@ -873,7 +876,7 @@ void CodeCache::verify_oops() {
873876
}
874877
}
875878

876-
int CodeCache::blob_count(int code_blob_type) {
879+
int CodeCache::blob_count(CodeBlobType code_blob_type) {
877880
CodeHeap* heap = get_code_heap(code_blob_type);
878881
return (heap != NULL) ? heap->blob_count() : 0;
879882
}
@@ -886,7 +889,7 @@ int CodeCache::blob_count() {
886889
return count;
887890
}
888891

889-
int CodeCache::nmethod_count(int code_blob_type) {
892+
int CodeCache::nmethod_count(CodeBlobType code_blob_type) {
890893
CodeHeap* heap = get_code_heap(code_blob_type);
891894
return (heap != NULL) ? heap->nmethod_count() : 0;
892895
}
@@ -899,7 +902,7 @@ int CodeCache::nmethod_count() {
899902
return count;
900903
}
901904

902-
int CodeCache::adapter_count(int code_blob_type) {
905+
int CodeCache::adapter_count(CodeBlobType code_blob_type) {
903906
CodeHeap* heap = get_code_heap(code_blob_type);
904907
return (heap != NULL) ? heap->adapter_count() : 0;
905908
}
@@ -912,12 +915,12 @@ int CodeCache::adapter_count() {
912915
return count;
913916
}
914917

915-
address CodeCache::low_bound(int code_blob_type) {
918+
address CodeCache::low_bound(CodeBlobType code_blob_type) {
916919
CodeHeap* heap = get_code_heap(code_blob_type);
917920
return (heap != NULL) ? (address)heap->low_boundary() : NULL;
918921
}
919922

920-
address CodeCache::high_bound(int code_blob_type) {
923+
address CodeCache::high_bound(CodeBlobType code_blob_type) {
921924
CodeHeap* heap = get_code_heap(code_blob_type);
922925
return (heap != NULL) ? (address)heap->high_boundary() : NULL;
923926
}
@@ -930,7 +933,7 @@ size_t CodeCache::capacity() {
930933
return cap;
931934
}
932935

933-
size_t CodeCache::unallocated_capacity(int code_blob_type) {
936+
size_t CodeCache::unallocated_capacity(CodeBlobType code_blob_type) {
934937
CodeHeap* heap = get_code_heap(code_blob_type);
935938
return (heap != NULL) ? heap->unallocated_capacity() : 0;
936939
}
@@ -1305,7 +1308,7 @@ void CodeCache::verify() {
13051308
// A CodeHeap is full. Print out warning and report event.
13061309
PRAGMA_DIAG_PUSH
13071310
PRAGMA_FORMAT_NONLITERAL_IGNORED
1308-
void CodeCache::report_codemem_full(int code_blob_type, bool print) {
1311+
void CodeCache::report_codemem_full(CodeBlobType code_blob_type, bool print) {
13091312
// Get nmethod heap for the given CodeBlobType and build CodeCacheFull event
13101313
CodeHeap* heap = get_code_heap(code_blob_type);
13111314
assert(heap != NULL, "heap is null");

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

+22-22
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,17 @@ class CodeCache : AllStatic {
104104
// Check the code heap sizes set by the user via command line
105105
static void check_heap_sizes(size_t non_nmethod_size, size_t profiled_size, size_t non_profiled_size, size_t cache_size, bool all_set);
106106
// Creates a new heap with the given name and size, containing CodeBlobs of the given type
107-
static void add_heap(ReservedSpace rs, const char* name, int code_blob_type);
107+
static void add_heap(ReservedSpace rs, const char* name, CodeBlobType code_blob_type);
108108
static CodeHeap* get_code_heap_containing(void* p); // Returns the CodeHeap containing the given pointer, or NULL
109109
static CodeHeap* get_code_heap(const CodeBlob* cb); // Returns the CodeHeap for the given CodeBlob
110-
static CodeHeap* get_code_heap(int code_blob_type); // Returns the CodeHeap for the given CodeBlobType
110+
static CodeHeap* get_code_heap(CodeBlobType code_blob_type); // Returns the CodeHeap for the given CodeBlobType
111111
// Returns the name of the VM option to set the size of the corresponding CodeHeap
112-
static const char* get_code_heap_flag_name(int code_blob_type);
112+
static const char* get_code_heap_flag_name(CodeBlobType code_blob_type);
113113
static ReservedCodeSpace reserve_heap_memory(size_t size); // Reserves one continuous chunk of memory for the CodeHeaps
114114

115115
// Iteration
116116
static CodeBlob* first_blob(CodeHeap* heap); // Returns the first CodeBlob on the given CodeHeap
117-
static CodeBlob* first_blob(int code_blob_type); // Returns the first CodeBlob of the given type
117+
static CodeBlob* first_blob(CodeBlobType code_blob_type); // Returns the first CodeBlob of the given type
118118
static CodeBlob* next_blob(CodeHeap* heap, CodeBlob* cb); // Returns the next CodeBlob on the given CodeHeap
119119
public:
120120

@@ -153,7 +153,7 @@ class CodeCache : AllStatic {
153153
static const GrowableArray<CodeHeap*>* nmethod_heaps() { return _nmethod_heaps; }
154154

155155
// Allocation/administration
156-
static CodeBlob* allocate(int size, int code_blob_type, bool handle_alloc_failure = true, int orig_code_blob_type = CodeBlobType::All); // allocates a new CodeBlob
156+
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
157157
static void commit(CodeBlob* cb); // called when the allocated CodeBlob has been filled
158158
static int alignment_unit(); // guaranteed alignment of all CodeBlobs
159159
static int alignment_offset(); // guaranteed offset of first CodeBlob byte within alignment unit (i.e., allocation header)
@@ -176,11 +176,11 @@ class CodeCache : AllStatic {
176176
static CompiledMethod* find_compiled(void* start);
177177

178178
static int blob_count(); // Returns the total number of CodeBlobs in the cache
179-
static int blob_count(int code_blob_type);
179+
static int blob_count(CodeBlobType code_blob_type);
180180
static int adapter_count(); // Returns the total number of Adapters in the cache
181-
static int adapter_count(int code_blob_type);
181+
static int adapter_count(CodeBlobType code_blob_type);
182182
static int nmethod_count(); // Returns the total number of nmethods in the cache
183-
static int nmethod_count(int code_blob_type);
183+
static int nmethod_count(CodeBlobType code_blob_type);
184184

185185
// GC support
186186
static void verify_oops();
@@ -214,22 +214,22 @@ class CodeCache : AllStatic {
214214
static void print_summary(outputStream* st, bool detailed = true); // Prints a summary of the code cache usage
215215
static void log_state(outputStream* st);
216216
LINUX_ONLY(static void write_perf_map();)
217-
static const char* get_code_heap_name(int code_blob_type) { return (heap_available(code_blob_type) ? get_code_heap(code_blob_type)->name() : "Unused"); }
218-
static void report_codemem_full(int code_blob_type, bool print);
217+
static const char* get_code_heap_name(CodeBlobType code_blob_type) { return (heap_available(code_blob_type) ? get_code_heap(code_blob_type)->name() : "Unused"); }
218+
static void report_codemem_full(CodeBlobType code_blob_type, bool print);
219219

220220
// Dcmd (Diagnostic commands)
221221
static void print_codelist(outputStream* st);
222222
static void print_layout(outputStream* st);
223223

224224
// The full limits of the codeCache
225225
static address low_bound() { return _low_bound; }
226-
static address low_bound(int code_blob_type);
226+
static address low_bound(CodeBlobType code_blob_type);
227227
static address high_bound() { return _high_bound; }
228-
static address high_bound(int code_blob_type);
228+
static address high_bound(CodeBlobType code_blob_type);
229229

230230
// Profiling
231231
static size_t capacity();
232-
static size_t unallocated_capacity(int code_blob_type);
232+
static size_t unallocated_capacity(CodeBlobType code_blob_type);
233233
static size_t unallocated_capacity();
234234
static size_t max_capacity();
235235

@@ -242,29 +242,29 @@ class CodeCache : AllStatic {
242242
static void cleanup_inline_caches(); // clean unloaded/zombie nmethods from inline caches
243243

244244
// Returns true if an own CodeHeap for the given CodeBlobType is available
245-
static bool heap_available(int code_blob_type);
245+
static bool heap_available(CodeBlobType code_blob_type);
246246

247247
// Returns the CodeBlobType for the given CompiledMethod
248-
static int get_code_blob_type(CompiledMethod* cm) {
248+
static CodeBlobType get_code_blob_type(CompiledMethod* cm) {
249249
return get_code_heap(cm)->code_blob_type();
250250
}
251251

252-
static bool code_blob_type_accepts_compiled(int type) {
253-
bool result = type == CodeBlobType::All || type <= CodeBlobType::MethodProfiled;
252+
static bool code_blob_type_accepts_compiled(CodeBlobType code_blob_type) {
253+
bool result = code_blob_type == CodeBlobType::All || code_blob_type <= CodeBlobType::MethodProfiled;
254254
return result;
255255
}
256256

257-
static bool code_blob_type_accepts_nmethod(int type) {
257+
static bool code_blob_type_accepts_nmethod(CodeBlobType type) {
258258
return type == CodeBlobType::All || type <= CodeBlobType::MethodProfiled;
259259
}
260260

261-
static bool code_blob_type_accepts_allocable(int type) {
261+
static bool code_blob_type_accepts_allocable(CodeBlobType type) {
262262
return type <= CodeBlobType::All;
263263
}
264264

265265

266266
// Returns the CodeBlobType for the given compilation level
267-
static int get_code_blob_type(int comp_level) {
267+
static CodeBlobType get_code_blob_type(int comp_level) {
268268
if (comp_level == CompLevel_none ||
269269
comp_level == CompLevel_simple ||
270270
comp_level == CompLevel_full_optimization) {
@@ -276,7 +276,7 @@ class CodeCache : AllStatic {
276276
return CodeBlobType::MethodProfiled;
277277
}
278278
ShouldNotReachHere();
279-
return 0;
279+
return static_cast<CodeBlobType>(0);
280280
}
281281

282282
static void verify_clean_inline_caches();
@@ -309,7 +309,7 @@ class CodeCache : AllStatic {
309309
// tells how many nmethods have dependencies
310310
static int number_of_nmethods_with_dependencies();
311311

312-
static int get_codemem_full_count(int code_blob_type) {
312+
static int get_codemem_full_count(CodeBlobType code_blob_type) {
313313
CodeHeap* heap = get_code_heap(code_blob_type);
314314
return (heap != NULL) ? heap->full_count() : 0;
315315
}

‎src/hotspot/share/compiler/compileBroker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,7 @@ void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
24172417
* This function needs to be called only from CodeCache::allocate(),
24182418
* since we currently handle a full code cache uniformly.
24192419
*/
2420-
void CompileBroker::handle_full_code_cache(int code_blob_type) {
2420+
void CompileBroker::handle_full_code_cache(CodeBlobType code_blob_type) {
24212421
UseInterpreter = true;
24222422
if (UseCompiler || AlwaysCompileLoopMethods ) {
24232423
if (xtty != NULL) {

‎src/hotspot/share/compiler/compileBroker.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class CompileBroker: AllStatic {
358358
static bool is_compilation_disabled_forever() {
359359
return _should_compile_new_jobs == shutdown_compilation;
360360
}
361-
static void handle_full_code_cache(int code_blob_type);
361+
static void handle_full_code_cache(CodeBlobType code_blob_type);
362362
// Ensures that warning is only printed once.
363363
static bool should_print_compiler_warning() {
364364
jint old = Atomic::cmpxchg(&_print_compilation_warning, 0, 1);

‎src/hotspot/share/jfr/periodic/jfrPeriodic.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,8 @@ TRACE_REQUEST_FUNC(CompilerConfiguration) {
577577

578578
TRACE_REQUEST_FUNC(CodeCacheStatistics) {
579579
// Emit stats for all available code heaps
580-
for (int bt = 0; bt < CodeBlobType::NumTypes; ++bt) {
580+
for (int bt_index = 0; bt_index < static_cast<int>(CodeBlobType::NumTypes); ++bt_index) {
581+
const CodeBlobType bt = static_cast<CodeBlobType>(bt_index);
581582
if (CodeCache::heap_available(bt)) {
582583
EventCodeCacheStatistics event;
583584
event.set_codeBlobType((u1)bt);

‎src/hotspot/share/jfr/recorder/checkpoint/types/jfrType.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ void NarrowOopModeConstant::serialize(JfrCheckpointWriter& writer) {
248248
}
249249

250250
void CodeBlobTypeConstant::serialize(JfrCheckpointWriter& writer) {
251-
static const u4 nof_entries = CodeBlobType::NumTypes;
251+
static const u4 nof_entries = static_cast<u4>(CodeBlobType::NumTypes);
252252
writer.write_count(nof_entries);
253253
for (u4 i = 0; i < nof_entries; ++i) {
254254
writer.write_key(i);
255-
writer.write(CodeCache::get_code_heap_name(i));
255+
writer.write(CodeCache::get_code_heap_name(static_cast<CodeBlobType>(i)));
256256
}
257257
};
258258

‎src/hotspot/share/memory/heap.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
// Implementation of Heap
3535

36-
CodeHeap::CodeHeap(const char* name, const int code_blob_type)
36+
CodeHeap::CodeHeap(const char* name, const CodeBlobType code_blob_type)
3737
: _code_blob_type(code_blob_type) {
3838
_name = name;
3939
_number_of_committed_segments = 0;

0 commit comments

Comments
 (0)
Please sign in to comment.