Skip to content

Commit e052d7f

Browse files
author
Boris Ulasevich
committed
8288477: nmethod header size reduction
Reviewed-by: kvn, never
1 parent 54a2c5a commit e052d7f

File tree

11 files changed

+80
-73
lines changed

11 files changed

+80
-73
lines changed

src/hotspot/share/ci/ciEnv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ void ciEnv::register_method(ciMethod* target,
11481148
debug_info(), dependencies(), code_buffer,
11491149
frame_words, oop_map_set,
11501150
handler_table, inc_table,
1151-
compiler, task()->comp_level());
1151+
compiler, CompLevel(task()->comp_level()));
11521152

11531153
// Free codeBlobs
11541154
code_buffer->free_blob();

src/hotspot/share/code/codeBlob.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,22 @@ unsigned int CodeBlob::allocation_size(CodeBuffer* cb, int header_size) {
7979
}
8080

8181
CodeBlob::CodeBlob(const char* name, CompilerType type, const CodeBlobLayout& layout, int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments, bool compiled) :
82-
_type(type),
83-
_size(layout.size()),
84-
_header_size(layout.header_size()),
85-
_frame_complete_offset(frame_complete_offset),
86-
_data_offset(layout.data_offset()),
87-
_frame_size(frame_size),
8882
_code_begin(layout.code_begin()),
8983
_code_end(layout.code_end()),
9084
_content_begin(layout.content_begin()),
9185
_data_end(layout.data_end()),
9286
_relocation_begin(layout.relocation_begin()),
9387
_relocation_end(layout.relocation_end()),
9488
_oop_maps(oop_maps),
89+
_name(name),
90+
_size(layout.size()),
91+
_header_size(layout.header_size()),
92+
_frame_complete_offset(frame_complete_offset),
93+
_data_offset(layout.data_offset()),
94+
_frame_size(frame_size),
9595
_caller_must_gc_arguments(caller_must_gc_arguments),
9696
_is_compiled(compiled),
97-
_name(name)
97+
_type(type)
9898
{
9999
assert(is_aligned(layout.size(), oopSize), "unaligned size");
100100
assert(is_aligned(layout.header_size(), oopSize), "unaligned size");
@@ -108,21 +108,21 @@ CodeBlob::CodeBlob(const char* name, CompilerType type, const CodeBlobLayout& la
108108
}
109109

110110
CodeBlob::CodeBlob(const char* name, CompilerType type, const CodeBlobLayout& layout, CodeBuffer* cb /*UNUSED*/, int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments, bool compiled) :
111-
_type(type),
112-
_size(layout.size()),
113-
_header_size(layout.header_size()),
114-
_frame_complete_offset(frame_complete_offset),
115-
_data_offset(layout.data_offset()),
116-
_frame_size(frame_size),
117111
_code_begin(layout.code_begin()),
118112
_code_end(layout.code_end()),
119113
_content_begin(layout.content_begin()),
120114
_data_end(layout.data_end()),
121115
_relocation_begin(layout.relocation_begin()),
122116
_relocation_end(layout.relocation_end()),
117+
_name(name),
118+
_size(layout.size()),
119+
_header_size(layout.header_size()),
120+
_frame_complete_offset(frame_complete_offset),
121+
_data_offset(layout.data_offset()),
122+
_frame_size(frame_size),
123123
_caller_must_gc_arguments(caller_must_gc_arguments),
124124
_is_compiled(compiled),
125-
_name(name)
125+
_type(type)
126126
{
127127
assert(is_aligned(_size, oopSize), "unaligned size");
128128
assert(is_aligned(_header_size, oopSize), "unaligned size");

src/hotspot/share/code/codeBlob.hpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,7 @@ class CodeBlob {
9090

9191
protected:
9292

93-
const CompilerType _type; // CompilerType
94-
int _size; // total size of CodeBlob in bytes
95-
int _header_size; // size of header (depends on subclass)
96-
int _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have
97-
// not finished setting up their frame. Beware of pc's in
98-
// that range. There is a similar range(s) on returns
99-
// which we don't detect.
100-
int _data_offset; // offset to where data region begins
101-
int _frame_size; // size of stack frame
102-
93+
// order fields from large to small to minimize padding between fields
10394
address _code_begin;
10495
address _code_end;
10596
address _content_begin; // address to where content region begins (this includes consts, insts, stubs)
@@ -109,13 +100,24 @@ class CodeBlob {
109100
address _relocation_end;
110101

111102
ImmutableOopMapSet* _oop_maps; // OopMap for this CodeBlob
112-
bool _caller_must_gc_arguments;
113-
114-
bool _is_compiled;
115103

116104
const char* _name;
117105
S390_ONLY(int _ctable_offset;)
118106

107+
int _size; // total size of CodeBlob in bytes
108+
int _header_size; // size of header (depends on subclass)
109+
int _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have
110+
// not finished setting up their frame. Beware of pc's in
111+
// that range. There is a similar range(s) on returns
112+
// which we don't detect.
113+
int _data_offset; // offset to where data region begins
114+
int _frame_size; // size of stack frame
115+
116+
bool _caller_must_gc_arguments;
117+
118+
bool _is_compiled;
119+
const CompilerType _type; // CompilerType
120+
119121
#ifndef PRODUCT
120122
AsmRemarks _asm_remarks;
121123
DbgStrings _dbg_strings;

src/hotspot/share/code/nmethod.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ nmethod* nmethod::new_nmethod(const methodHandle& method,
511511
ExceptionHandlerTable* handler_table,
512512
ImplicitExceptionTable* nul_chk_table,
513513
AbstractCompiler* compiler,
514-
int comp_level
514+
CompLevel comp_level
515515
#if INCLUDE_JVMCI
516516
, char* speculations,
517517
int speculations_len,
@@ -611,9 +611,9 @@ nmethod::nmethod(
611611
ByteSize basic_lock_sp_offset,
612612
OopMapSet* oop_maps )
613613
: CompiledMethod(method, "native nmethod", type, nmethod_size, sizeof(nmethod), code_buffer, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps, false, true),
614-
_is_unloading_state(0),
615614
_native_receiver_sp_offset(basic_lock_owner_sp_offset),
616-
_native_basic_lock_sp_offset(basic_lock_sp_offset)
615+
_native_basic_lock_sp_offset(basic_lock_sp_offset),
616+
_is_unloading_state(0)
617617
{
618618
{
619619
int scopes_data_offset = 0;
@@ -624,6 +624,7 @@ nmethod::nmethod(
624624
assert_locked_or_safepoint(CodeCache_lock);
625625

626626
init_defaults();
627+
_comp_level = CompLevel_none;
627628
_entry_bci = InvocationEntryBci;
628629
// We have no exception handler or deopt handler make the
629630
// values something that will never match a pc like the nmethod vtable entry
@@ -648,7 +649,6 @@ nmethod::nmethod(
648649
_nmethod_end_offset = _nul_chk_table_offset;
649650
#endif
650651
_compile_id = compile_id;
651-
_comp_level = CompLevel_none;
652652
_entry_point = code_begin() + offsets->value(CodeOffsets::Entry);
653653
_verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry);
654654
_osr_entry_point = NULL;
@@ -738,17 +738,17 @@ nmethod::nmethod(
738738
ExceptionHandlerTable* handler_table,
739739
ImplicitExceptionTable* nul_chk_table,
740740
AbstractCompiler* compiler,
741-
int comp_level
741+
CompLevel comp_level
742742
#if INCLUDE_JVMCI
743743
, char* speculations,
744744
int speculations_len,
745745
int jvmci_data_size
746746
#endif
747747
)
748748
: CompiledMethod(method, "nmethod", type, nmethod_size, sizeof(nmethod), code_buffer, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps, false, true),
749-
_is_unloading_state(0),
750749
_native_receiver_sp_offset(in_ByteSize(-1)),
751-
_native_basic_lock_sp_offset(in_ByteSize(-1))
750+
_native_basic_lock_sp_offset(in_ByteSize(-1)),
751+
_is_unloading_state(0)
752752
{
753753
assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR");
754754
{

src/hotspot/share/code/nmethod.hpp

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,16 @@ class nmethod : public CompiledMethod {
7171
friend class JVMCINMethodData;
7272

7373
private:
74-
// Shared fields for all nmethod's
75-
int _entry_bci; // != InvocationEntryBci if this nmethod is an on-stack replacement method
7674

7775
uint64_t _gc_epoch;
7876

77+
// not_entrant method removal. Each mark_sweep pass will update
78+
// this mark to current sweep invocation count if it is seen on the
79+
// stack. An not_entrant method can be removed when there are no
80+
// more activations, i.e., when the _stack_traversal_mark is less than
81+
// current sweep traversal index.
82+
volatile int64_t _stack_traversal_mark;
83+
7984
// To support simple linked-list chaining of nmethods:
8085
nmethod* _osr_link; // from InstanceKlass::osr_nmethods_head
8186

@@ -198,6 +203,9 @@ class nmethod : public CompiledMethod {
198203
address _verified_entry_point; // entry point without class check
199204
address _osr_entry_point; // entry point for on stack replacement
200205

206+
// Shared fields for all nmethod's
207+
int _entry_bci; // != InvocationEntryBci if this nmethod is an on-stack replacement method
208+
201209
// Offsets for different nmethod parts
202210
int _exception_offset;
203211
// Offset of the unwind handler if it exists
@@ -225,21 +233,6 @@ class nmethod : public CompiledMethod {
225233
int _orig_pc_offset;
226234

227235
int _compile_id; // which compilation made this nmethod
228-
int _comp_level; // compilation level
229-
230-
// protected by CodeCache_lock
231-
bool _has_flushed_dependencies; // Used for maintenance of dependencies (CodeCache_lock)
232-
233-
// used by jvmti to track if an event has been posted for this nmethod.
234-
bool _unload_reported;
235-
bool _load_reported;
236-
237-
// Protected by CompiledMethod_lock
238-
volatile signed char _state; // {not_installed, in_use, not_entrant, zombie, unloaded}
239-
240-
#ifdef ASSERT
241-
bool _oops_are_stale; // indicates that it's no longer safe to access oops section
242-
#endif
243236

244237
#if INCLUDE_RTM_OPT
245238
// RTM state at compile time. Used during deoptimization to decide
@@ -253,23 +246,13 @@ class nmethod : public CompiledMethod {
253246
// event processing needs to be done.
254247
volatile jint _lock_count;
255248

256-
// not_entrant method removal. Each mark_sweep pass will update
257-
// this mark to current sweep invocation count if it is seen on the
258-
// stack. An not_entrant method can be removed when there are no
259-
// more activations, i.e., when the _stack_traversal_mark is less than
260-
// current sweep traversal index.
261-
volatile int64_t _stack_traversal_mark;
262-
263249
// The _hotness_counter indicates the hotness of a method. The higher
264250
// the value the hotter the method. The hotness counter of a nmethod is
265251
// set to [(ReservedCodeCacheSize / (1024 * 1024)) * 2] each time the method
266252
// is active while stack scanning (do_stack_scanning()). The hotness
267253
// counter is decreased (by 1) while sweeping.
268254
int _hotness_counter;
269255

270-
// Local state used to keep track of whether unloading is happening or not
271-
volatile uint8_t _is_unloading_state;
272-
273256
// These are used for compiled synchronized native methods to
274257
// locate the owner and stack slot for the BasicLock. They are
275258
// needed because there is no debug information for compiled native
@@ -281,6 +264,25 @@ class nmethod : public CompiledMethod {
281264
ByteSize _native_receiver_sp_offset;
282265
ByteSize _native_basic_lock_sp_offset;
283266

267+
CompLevel _comp_level; // compilation level
268+
269+
// Local state used to keep track of whether unloading is happening or not
270+
volatile uint8_t _is_unloading_state;
271+
272+
// protected by CodeCache_lock
273+
bool _has_flushed_dependencies; // Used for maintenance of dependencies (CodeCache_lock)
274+
275+
// used by jvmti to track if an event has been posted for this nmethod.
276+
bool _unload_reported;
277+
bool _load_reported;
278+
279+
// Protected by CompiledMethod_lock
280+
volatile signed char _state; // {not_installed, in_use, not_entrant, zombie, unloaded}
281+
282+
#ifdef ASSERT
283+
bool _oops_are_stale; // indicates that it's no longer safe to access oops section
284+
#endif
285+
284286
friend class nmethodLocker;
285287

286288
// For native wrappers
@@ -311,7 +313,7 @@ class nmethod : public CompiledMethod {
311313
ExceptionHandlerTable* handler_table,
312314
ImplicitExceptionTable* nul_chk_table,
313315
AbstractCompiler* compiler,
314-
int comp_level
316+
CompLevel comp_level
315317
#if INCLUDE_JVMCI
316318
, char* speculations,
317319
int speculations_len,
@@ -359,7 +361,7 @@ class nmethod : public CompiledMethod {
359361
ExceptionHandlerTable* handler_table,
360362
ImplicitExceptionTable* nul_chk_table,
361363
AbstractCompiler* compiler,
362-
int comp_level
364+
CompLevel comp_level
363365
#if INCLUDE_JVMCI
364366
, char* speculations = NULL,
365367
int speculations_len = 0,
@@ -372,9 +374,9 @@ class nmethod : public CompiledMethod {
372374
// Only used for unit tests.
373375
nmethod()
374376
: CompiledMethod(),
375-
_is_unloading_state(0),
376377
_native_receiver_sp_offset(in_ByteSize(-1)),
377-
_native_basic_lock_sp_offset(in_ByteSize(-1)) {}
378+
_native_basic_lock_sp_offset(in_ByteSize(-1)),
379+
_is_unloading_state(0) {}
378380

379381

380382
static nmethod* new_native_nmethod(const methodHandle& method,

src/hotspot/share/compiler/compilerDefinitions.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "runtime/globals.hpp"
3232

3333
// The (closed set) of concrete compiler classes.
34-
enum CompilerType {
34+
enum CompilerType : u1 {
3535
compiler_none,
3636
compiler_c1,
3737
compiler_c2,
@@ -54,7 +54,7 @@ enum MethodCompilation {
5454
};
5555

5656
// Enumeration to distinguish tiers of compilation
57-
enum CompLevel {
57+
enum CompLevel : s1 {
5858
CompLevel_any = -1, // Used for querying the state
5959
CompLevel_all = -1, // Used for changing the state
6060
CompLevel_none = 0, // Interpreter

src/hotspot/share/jvmci/jvmciRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,7 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
20632063
int speculations_len) {
20642064
JVMCI_EXCEPTION_CONTEXT;
20652065
nmethod* nm = NULL;
2066-
int comp_level = CompLevel_full_optimization;
2066+
CompLevel comp_level = CompLevel_full_optimization;
20672067
char* failure_detail = NULL;
20682068

20692069
bool install_default = JVMCIENV->get_HotSpotNmethod_isDefault(nmethod_mirror) != 0;

src/hotspot/share/jvmci/vmStructs_jvmci.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
nonstatic_field(MethodData, _jvmci_ir_size, int) \
256256
\
257257
nonstatic_field(nmethod, _verified_entry_point, address) \
258-
nonstatic_field(nmethod, _comp_level, int) \
258+
nonstatic_field(nmethod, _comp_level, CompLevel) \
259259
\
260260
nonstatic_field(ObjArrayKlass, _element_klass, Klass*) \
261261
\
@@ -366,6 +366,7 @@
366366
declare_unsigned_integer_type(size_t) \
367367
declare_integer_type(intx) \
368368
declare_unsigned_integer_type(uintx) \
369+
declare_integer_type(CompLevel) \
369370
\
370371
declare_toplevel_type(BasicLock) \
371372
declare_toplevel_type(CompilerToVM) \

src/hotspot/share/runtime/vmStructs.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@
665665
volatile_nonstatic_field(nmethod, _lock_count, jint) \
666666
volatile_nonstatic_field(nmethod, _stack_traversal_mark, int64_t) \
667667
nonstatic_field(nmethod, _compile_id, int) \
668-
nonstatic_field(nmethod, _comp_level, int) \
668+
nonstatic_field(nmethod, _comp_level, CompLevel) \
669669
\
670670
unchecked_c2_static_field(Deoptimization, _trap_reason_name, void*) \
671671
\
@@ -1971,6 +1971,8 @@
19711971
declare_integer_type(AccessFlags) /* FIXME: wrong type (not integer) */\
19721972
declare_toplevel_type(address) /* FIXME: should this be an integer type? */\
19731973
declare_integer_type(BasicType) /* FIXME: wrong type (not integer) */ \
1974+
\
1975+
declare_integer_type(CompLevel) \
19741976
JVMTI_ONLY(declare_toplevel_type(BreakpointInfo)) \
19751977
JVMTI_ONLY(declare_toplevel_type(BreakpointInfo*)) \
19761978
declare_toplevel_type(CodeBlob*) \

src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ public boolean hasCompiledCode() {
459459
public boolean hasCompiledCodeAtLevel(int level) {
460460
long compiledCode = getCompiledCode();
461461
if (compiledCode != 0) {
462-
return UNSAFE.getInt(compiledCode + config().nmethodCompLevelOffset) == level;
462+
return UNSAFE.getByte(compiledCode + config().nmethodCompLevelOffset) == level;
463463
}
464464
return false;
465465
}

0 commit comments

Comments
 (0)