Skip to content

Commit b704e91

Browse files
author
Vladimir Kozlov
committed
8329433: Reduce nmethod header size
Reviewed-by: dlong, iveresov
1 parent 8da175d commit b704e91

File tree

15 files changed

+337
-388
lines changed

15 files changed

+337
-388
lines changed

src/hotspot/share/code/codeBlob.cpp

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -73,82 +73,56 @@ unsigned int CodeBlob::allocation_size(CodeBuffer* cb, int header_size) {
7373
return size;
7474
}
7575

76-
#ifdef ASSERT
77-
void CodeBlob::verify_parameters() {
78-
assert(is_aligned(_size, oopSize), "unaligned size");
79-
assert(is_aligned(_header_size, oopSize), "unaligned size");
80-
assert(is_aligned(_relocation_size, oopSize), "unaligned size");
81-
assert(_data_offset <= size(), "codeBlob is too small");
82-
assert(code_end() == content_end(), "must be the same - see code_end()");
83-
#ifdef COMPILER1
84-
// probably wrong for tiered
85-
assert(frame_size() >= -1, "must use frame size or -1 for runtime stubs");
86-
#endif // COMPILER1
87-
}
88-
#endif
89-
90-
CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, int size, int header_size, int relocation_size,
91-
int content_offset, int code_offset, int frame_complete_offset, int data_offset,
92-
int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments) :
93-
_oop_maps(oop_maps),
94-
_name(name),
95-
_size(size),
96-
_header_size(header_size),
97-
_relocation_size(relocation_size),
98-
_content_offset(content_offset),
99-
_code_offset(code_offset),
100-
_frame_complete_offset(frame_complete_offset),
101-
_data_offset(data_offset),
102-
_frame_size(frame_size),
103-
S390_ONLY(_ctable_offset(0) COMMA)
104-
_kind(kind),
105-
_caller_must_gc_arguments(caller_must_gc_arguments)
106-
{
107-
DEBUG_ONLY( verify_parameters(); )
108-
}
109-
110-
CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, int header_size,
111-
int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments) :
76+
CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size,
77+
int16_t frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments) :
11278
_oop_maps(nullptr), // will be set by set_oop_maps() call
11379
_name(name),
11480
_size(size),
115-
_header_size(header_size),
11681
_relocation_size(align_up(cb->total_relocation_size(), oopSize)),
117-
_content_offset(CodeBlob::align_code_offset(_header_size + _relocation_size)),
82+
_content_offset(CodeBlob::align_code_offset(header_size + _relocation_size)),
11883
_code_offset(_content_offset + cb->total_offset_of(cb->insts())),
119-
_frame_complete_offset(frame_complete_offset),
12084
_data_offset(_content_offset + align_up(cb->total_content_size(), oopSize)),
12185
_frame_size(frame_size),
12286
S390_ONLY(_ctable_offset(0) COMMA)
87+
_header_size(header_size),
88+
_frame_complete_offset(frame_complete_offset),
12389
_kind(kind),
12490
_caller_must_gc_arguments(caller_must_gc_arguments)
12591
{
126-
DEBUG_ONLY( verify_parameters(); )
92+
assert(is_aligned(_size, oopSize), "unaligned size");
93+
assert(is_aligned(header_size, oopSize), "unaligned size");
94+
assert(is_aligned(_relocation_size, oopSize), "unaligned size");
95+
assert(_data_offset <= _size, "codeBlob is too small: %d > %d", _data_offset, _size);
96+
assert(code_end() == content_end(), "must be the same - see code_end()");
97+
#ifdef COMPILER1
98+
// probably wrong for tiered
99+
assert(_frame_size >= -1, "must use frame size or -1 for runtime stubs");
100+
#endif // COMPILER1
127101

128102
set_oop_maps(oop_maps);
129103
}
130104

131105
// Simple CodeBlob used for simple BufferBlob.
132-
CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, int size, int header_size) :
106+
CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size) :
133107
_oop_maps(nullptr),
134108
_name(name),
135109
_size(size),
136-
_header_size(header_size),
137110
_relocation_size(0),
138111
_content_offset(CodeBlob::align_code_offset(header_size)),
139112
_code_offset(_content_offset),
140-
_frame_complete_offset(CodeOffsets::frame_never_safe),
141113
_data_offset(size),
142114
_frame_size(0),
143115
S390_ONLY(_ctable_offset(0) COMMA)
116+
_header_size(header_size),
117+
_frame_complete_offset(CodeOffsets::frame_never_safe),
144118
_kind(kind),
145119
_caller_must_gc_arguments(false)
146120
{
147121
assert(is_aligned(size, oopSize), "unaligned size");
148122
assert(is_aligned(header_size, oopSize), "unaligned size");
149123
}
150124

151-
void CodeBlob::purge(bool free_code_cache_data, bool unregister_nmethod) {
125+
void CodeBlob::purge() {
152126
if (_oop_maps != nullptr) {
153127
delete _oop_maps;
154128
_oop_maps = nullptr;
@@ -185,8 +159,8 @@ RuntimeBlob::RuntimeBlob(
185159
CodeBlobKind kind,
186160
CodeBuffer* cb,
187161
int size,
188-
int header_size,
189-
int frame_complete,
162+
uint16_t header_size,
163+
int16_t frame_complete,
190164
int frame_size,
191165
OopMapSet* oop_maps,
192166
bool caller_must_gc_arguments)
@@ -198,7 +172,7 @@ RuntimeBlob::RuntimeBlob(
198172
void RuntimeBlob::free(RuntimeBlob* blob) {
199173
assert(blob != nullptr, "caller must check for nullptr");
200174
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
201-
blob->purge(true /* free_code_cache_data */, true /* unregister_nmethod */);
175+
blob->purge();
202176
{
203177
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
204178
CodeCache::free(blob);
@@ -408,7 +382,7 @@ RuntimeStub::RuntimeStub(
408382
const char* name,
409383
CodeBuffer* cb,
410384
int size,
411-
int frame_complete,
385+
int16_t frame_complete,
412386
int frame_size,
413387
OopMapSet* oop_maps,
414388
bool caller_must_gc_arguments
@@ -420,7 +394,7 @@ RuntimeStub::RuntimeStub(
420394

421395
RuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name,
422396
CodeBuffer* cb,
423-
int frame_complete,
397+
int16_t frame_complete,
424398
int frame_size,
425399
OopMapSet* oop_maps,
426400
bool caller_must_gc_arguments,
@@ -668,10 +642,6 @@ void UpcallStub::free(UpcallStub* blob) {
668642
RuntimeBlob::free(blob);
669643
}
670644

671-
void UpcallStub::preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) {
672-
ShouldNotReachHere(); // caller should never have to gc arguments
673-
}
674-
675645
//----------------------------------------------------------------------------------------------------
676646
// Verification and printing
677647

src/hotspot/share/code/codeBlob.hpp

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ enum class CodeBlobKind : u1 {
9090
Number_Of_Kinds
9191
};
9292

93-
class UpcallStub; // for as_upcall_stub()
94-
class RuntimeStub; // for as_runtime_stub()
93+
class UpcallStub; // for as_upcall_stub()
94+
class RuntimeStub; // for as_runtime_stub()
9595
class JavaFrameAnchor; // for UpcallStub::jfa_for_frame
9696

9797
class CodeBlob {
@@ -101,43 +101,39 @@ class CodeBlob {
101101

102102
protected:
103103
// order fields from large to small to minimize padding between fields
104-
ImmutableOopMapSet* _oop_maps; // OopMap for this CodeBlob
104+
ImmutableOopMapSet* _oop_maps; // OopMap for this CodeBlob
105105
const char* _name;
106106

107-
int _size; // total size of CodeBlob in bytes
108-
int _header_size; // size of header (depends on subclass)
109-
int _relocation_size; // size of relocation
110-
int _content_offset; // offset to where content region begins (this includes consts, insts, stubs)
111-
int _code_offset; // offset to where instructions region begins (this includes insts, stubs)
112-
int _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have
113-
// not finished setting up their frame. Beware of pc's in
114-
// that range. There is a similar range(s) on returns
115-
// which we don't detect.
116-
int _data_offset; // offset to where data region begins
117-
int _frame_size; // size of stack frame in words (NOT slots. On x64 these are 64bit words)
107+
int _size; // total size of CodeBlob in bytes
108+
int _relocation_size; // size of relocation (could be bigger than 64Kb)
109+
int _content_offset; // offset to where content region begins (this includes consts, insts, stubs)
110+
int _code_offset; // offset to where instructions region begins (this includes insts, stubs)
118111

119-
S390_ONLY(int _ctable_offset;)
112+
int _data_offset; // offset to where data region begins
113+
int _frame_size; // size of stack frame in words (NOT slots. On x64 these are 64bit words)
120114

121-
CodeBlobKind _kind; // Kind of this code blob
115+
S390_ONLY(int _ctable_offset;)
122116

123-
bool _caller_must_gc_arguments;
117+
uint16_t _header_size; // size of header (depends on subclass)
118+
int16_t _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have
119+
// not finished setting up their frame. Beware of pc's in
120+
// that range. There is a similar range(s) on returns
121+
// which we don't detect.
122+
123+
CodeBlobKind _kind; // Kind of this code blob
124+
125+
bool _caller_must_gc_arguments;
124126

125127
#ifndef PRODUCT
126128
AsmRemarks _asm_remarks;
127129
DbgStrings _dbg_strings;
128-
#endif // not PRODUCT
129-
130-
DEBUG_ONLY( void verify_parameters() );
131-
132-
CodeBlob(const char* name, CodeBlobKind kind, int size, int header_size, int relocation_size,
133-
int content_offset, int code_offset, int data_offset, int frame_complete_offset,
134-
int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments);
130+
#endif
135131

136-
CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, int header_size,
137-
int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments);
132+
CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size,
133+
int16_t frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments);
138134

139135
// Simple CodeBlob used for simple BufferBlob.
140-
CodeBlob(const char* name, CodeBlobKind kind, int size, int header_size);
136+
CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size);
141137

142138
void operator delete(void* p) { }
143139

@@ -152,7 +148,7 @@ class CodeBlob {
152148
static unsigned int align_code_offset(int offset);
153149

154150
// Deletion
155-
virtual void purge(bool free_code_cache_data, bool unregister_nmethod);
151+
void purge();
156152

157153
// Typing
158154
bool is_nmethod() const { return _kind == CodeBlobKind::Nmethod; }
@@ -225,7 +221,6 @@ class CodeBlob {
225221

226222
const ImmutableOopMap* oop_map_for_slot(int slot, address return_address) const;
227223
const ImmutableOopMap* oop_map_for_return_address(address return_address) const;
228-
virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) = 0;
229224

230225
// Frame support. Sizes are in word units.
231226
int frame_size() const { return _frame_size; }
@@ -273,7 +268,7 @@ class RuntimeBlob : public CodeBlob {
273268

274269
// Creation
275270
// a) simple CodeBlob
276-
RuntimeBlob(const char* name, CodeBlobKind kind, int size, int header_size)
271+
RuntimeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size)
277272
: CodeBlob(name, kind, size, header_size)
278273
{}
279274

@@ -285,8 +280,8 @@ class RuntimeBlob : public CodeBlob {
285280
CodeBlobKind kind,
286281
CodeBuffer* cb,
287282
int size,
288-
int header_size,
289-
int frame_complete,
283+
uint16_t header_size,
284+
int16_t frame_complete,
290285
int frame_size,
291286
OopMapSet* oop_maps,
292287
bool caller_must_gc_arguments = false
@@ -324,10 +319,9 @@ class BufferBlob: public RuntimeBlob {
324319

325320
static void free(BufferBlob* buf);
326321

327-
// GC/Verification support
328-
void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) override { /* nothing to do */ }
329-
322+
// Verification support
330323
void verify() override;
324+
331325
void print_on(outputStream* st) const override;
332326
void print_value_on(outputStream* st) const override;
333327
};
@@ -381,7 +375,7 @@ class RuntimeStub: public RuntimeBlob {
381375
const char* name,
382376
CodeBuffer* cb,
383377
int size,
384-
int frame_complete,
378+
int16_t frame_complete,
385379
int frame_size,
386380
OopMapSet* oop_maps,
387381
bool caller_must_gc_arguments
@@ -394,7 +388,7 @@ class RuntimeStub: public RuntimeBlob {
394388
static RuntimeStub* new_runtime_stub(
395389
const char* stub_name,
396390
CodeBuffer* cb,
397-
int frame_complete,
391+
int16_t frame_complete,
398392
int frame_size,
399393
OopMapSet* oop_maps,
400394
bool caller_must_gc_arguments,
@@ -405,10 +399,9 @@ class RuntimeStub: public RuntimeBlob {
405399

406400
address entry_point() const { return code_begin(); }
407401

408-
// GC/Verification support
409-
void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) override { /* nothing to do */ }
410-
402+
// Verification support
411403
void verify() override;
404+
412405
void print_on(outputStream* st) const override;
413406
void print_value_on(outputStream* st) const override;
414407
};
@@ -429,7 +422,7 @@ class SingletonBlob: public RuntimeBlob {
429422
CodeBlobKind kind,
430423
CodeBuffer* cb,
431424
int size,
432-
int header_size,
425+
uint16_t header_size,
433426
int frame_size,
434427
OopMapSet* oop_maps
435428
)
@@ -438,9 +431,9 @@ class SingletonBlob: public RuntimeBlob {
438431

439432
address entry_point() { return code_begin(); }
440433

441-
// GC/Verification support
442-
void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) override { /* nothing to do */ }
434+
// Verification support
443435
void verify() override; // does nothing
436+
444437
void print_on(outputStream* st) const override;
445438
void print_value_on(outputStream* st) const override;
446439
};
@@ -632,7 +625,6 @@ class UpcallStub: public RuntimeBlob {
632625

633626
// GC/Verification support
634627
void oops_do(OopClosure* f, const frame& frame);
635-
void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) override;
636628
void verify() override;
637629

638630
// Misc.

src/hotspot/share/code/debugInfoRec.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,11 @@ static
244244
struct dir_stats_struct {
245245
int chunks_queried;
246246
int chunks_shared;
247-
int chunks_reshared;
248247
int chunks_elided;
249248

250249
void print() {
251-
tty->print_cr("Debug Data Chunks: %d, shared %d+%d, non-SP's elided %d",
252-
chunks_queried,
253-
chunks_shared, chunks_reshared,
254-
chunks_elided);
250+
tty->print_cr("Debug Data Chunks: %d, shared %d, non-SP's elided %d",
251+
chunks_queried, chunks_shared, chunks_elided);
255252
}
256253
} dir_stats;
257254
#endif //PRODUCT

src/hotspot/share/code/dependencies.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -388,9 +388,7 @@ void Dependencies::copy_to(nmethod* nm) {
388388
address beg = nm->dependencies_begin();
389389
address end = nm->dependencies_end();
390390
guarantee(end - beg >= (ptrdiff_t) size_in_bytes(), "bad sizing");
391-
Copy::disjoint_words((HeapWord*) content_bytes(),
392-
(HeapWord*) beg,
393-
size_in_bytes() / sizeof(HeapWord));
391+
(void)memcpy(beg, content_bytes(), size_in_bytes());
394392
assert(size_in_bytes() % sizeof(HeapWord) == 0, "copy by words");
395393
}
396394

0 commit comments

Comments
 (0)