Skip to content

Commit 83de340

Browse files
author
Boris Ulasevich
committed
8343789: Move mutable nmethod data out of CodeCache
Reviewed-by: kvn, dlong
1 parent 0de2cdd commit 83de340

File tree

7 files changed

+155
-105
lines changed

7 files changed

+155
-105
lines changed

src/hotspot/share/code/codeBlob.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,26 @@ unsigned int CodeBlob::align_code_offset(int offset) {
109109

110110
// This must be consistent with the CodeBlob constructor's layout actions.
111111
unsigned int CodeBlob::allocation_size(CodeBuffer* cb, int header_size) {
112-
unsigned int size = header_size;
113-
size += align_up(cb->total_relocation_size(), oopSize);
114112
// align the size to CodeEntryAlignment
115-
size = align_code_offset(size);
113+
unsigned int size = align_code_offset(header_size);
116114
size += align_up(cb->total_content_size(), oopSize);
117115
size += align_up(cb->total_oop_size(), oopSize);
118-
size += align_up(cb->total_metadata_size(), oopSize);
119116
return size;
120117
}
121118

122119
CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size,
123-
int16_t frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments) :
120+
int16_t frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments,
121+
int mutable_data_size) :
124122
_oop_maps(nullptr), // will be set by set_oop_maps() call
125123
_name(name),
124+
_mutable_data(nullptr),
126125
_size(size),
127126
_relocation_size(align_up(cb->total_relocation_size(), oopSize)),
128-
_content_offset(CodeBlob::align_code_offset(header_size + _relocation_size)),
127+
_content_offset(CodeBlob::align_code_offset(header_size)),
129128
_code_offset(_content_offset + cb->total_offset_of(cb->insts())),
130129
_data_offset(_content_offset + align_up(cb->total_content_size(), oopSize)),
131130
_frame_size(frame_size),
131+
_mutable_data_size(mutable_data_size),
132132
S390_ONLY(_ctable_offset(0) COMMA)
133133
_header_size(header_size),
134134
_frame_complete_offset(frame_complete_offset),
@@ -139,19 +139,28 @@ CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size
139139
assert(is_aligned(header_size, oopSize), "unaligned size");
140140
assert(is_aligned(_relocation_size, oopSize), "unaligned size");
141141
assert(_data_offset <= _size, "codeBlob is too small: %d > %d", _data_offset, _size);
142+
assert(is_nmethod() || (cb->total_oop_size() + cb->total_metadata_size() == 0), "must be nmethod");
142143
assert(code_end() == content_end(), "must be the same - see code_end()");
143144
#ifdef COMPILER1
144145
// probably wrong for tiered
145146
assert(_frame_size >= -1, "must use frame size or -1 for runtime stubs");
146147
#endif // COMPILER1
147148

149+
if (_mutable_data_size > 0) {
150+
_mutable_data = (address)os::malloc(_mutable_data_size, mtCode);
151+
if (_mutable_data == nullptr) {
152+
vm_exit_out_of_memory(_mutable_data_size, OOM_MALLOC_ERROR, "codebuffer: no space for mutable data");
153+
}
154+
}
155+
148156
set_oop_maps(oop_maps);
149157
}
150158

151159
// Simple CodeBlob used for simple BufferBlob.
152160
CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size) :
153161
_oop_maps(nullptr),
154162
_name(name),
163+
_mutable_data(nullptr),
155164
_size(size),
156165
_relocation_size(0),
157166
_content_offset(CodeBlob::align_code_offset(header_size)),
@@ -169,6 +178,10 @@ CodeBlob::CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t heade
169178
}
170179

171180
void CodeBlob::purge() {
181+
if (_mutable_data != nullptr) {
182+
os::free(_mutable_data);
183+
_mutable_data = nullptr;
184+
}
172185
if (_oop_maps != nullptr) {
173186
delete _oop_maps;
174187
_oop_maps = nullptr;
@@ -210,7 +223,8 @@ RuntimeBlob::RuntimeBlob(
210223
int frame_size,
211224
OopMapSet* oop_maps,
212225
bool caller_must_gc_arguments)
213-
: CodeBlob(name, kind, cb, size, header_size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments)
226+
: CodeBlob(name, kind, cb, size, header_size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments,
227+
align_up(cb->total_relocation_size(), oopSize))
214228
{
215229
cb->copy_code_and_locs_to(this);
216230
}

src/hotspot/share/code/codeBlob.hpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ enum class CodeBlobType {
6767
// UpcallStub : Used for upcalls from native code
6868
//
6969
//
70-
// Layout : continuous in the CodeCache
70+
// Layout in the CodeCache:
7171
// - header
72-
// - relocation
7372
// - content space
7473
// - instruction space
75-
// - data space
74+
// Outside of the CodeCache:
75+
// - mutable_data
76+
// - relocation info
77+
// - additional data for subclasses
7678

7779
enum class CodeBlobKind : u1 {
7880
None,
@@ -104,14 +106,15 @@ class CodeBlob {
104106
// order fields from large to small to minimize padding between fields
105107
ImmutableOopMapSet* _oop_maps; // OopMap for this CodeBlob
106108
const char* _name;
109+
address _mutable_data;
107110

108111
int _size; // total size of CodeBlob in bytes
109112
int _relocation_size; // size of relocation (could be bigger than 64Kb)
110113
int _content_offset; // offset to where content region begins (this includes consts, insts, stubs)
111114
int _code_offset; // offset to where instructions region begins (this includes insts, stubs)
112-
113115
int _data_offset; // offset to where data region begins
114116
int _frame_size; // size of stack frame in words (NOT slots. On x64 these are 64bit words)
117+
int _mutable_data_size;
115118

116119
S390_ONLY(int _ctable_offset;)
117120

@@ -142,7 +145,8 @@ class CodeBlob {
142145
const Vptr* vptr() const;
143146

144147
CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size,
145-
int16_t frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments);
148+
int16_t frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments,
149+
int mutable_data_size);
146150

147151
// Simple CodeBlob used for simple BufferBlob.
148152
CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size);
@@ -190,20 +194,25 @@ class CodeBlob {
190194
// Boundaries
191195
address header_begin() const { return (address) this; }
192196
address header_end() const { return ((address) this) + _header_size; }
193-
relocInfo* relocation_begin() const { return (relocInfo*) header_end(); }
194-
relocInfo* relocation_end() const { return (relocInfo*)(header_end() + _relocation_size); }
195197
address content_begin() const { return (address) header_begin() + _content_offset; }
196198
address content_end() const { return (address) header_begin() + _data_offset; }
197199
address code_begin() const { return (address) header_begin() + _code_offset; }
198-
// code_end == content_end is true for all types of blobs for now, it is also checked in the constructor
199200
address code_end() const { return (address) header_begin() + _data_offset; }
200201
address data_begin() const { return (address) header_begin() + _data_offset; }
201202
address data_end() const { return (address) header_begin() + _size; }
203+
address blob_end() const { return (address) header_begin() + _size; }
204+
// code_end == content_end is true for all types of blobs for now, it is also checked in the constructor
205+
206+
int mutable_data_size() const { return _mutable_data_size; }
207+
address mutable_data_begin() const { return _mutable_data; }
208+
address mutable_data_end() const { return _mutable_data + _mutable_data_size; }
209+
210+
relocInfo* relocation_begin() const { return (relocInfo*)_mutable_data; }
211+
relocInfo* relocation_end() const { return (relocInfo*)((address)relocation_begin() + _relocation_size); }
202212

203213
// Offsets
204214
int content_offset() const { return _content_offset; }
205215
int code_offset() const { return _code_offset; }
206-
int data_offset() const { return _data_offset; }
207216

208217
// This field holds the beginning of the const section in the old code buffer.
209218
// It is needed to fix relocations of pc-relative loads when resizing the
@@ -221,11 +230,11 @@ class CodeBlob {
221230
// Only used from CodeCache::free_unused_tail() after the Interpreter blob was trimmed
222231
void adjust_size(size_t used) {
223232
_size = (int)used;
224-
_data_offset = (int)used;
233+
_data_offset = _size;
225234
}
226235

227236
// Containment
228-
bool blob_contains(address addr) const { return header_begin() <= addr && addr < data_end(); }
237+
bool blob_contains(address addr) const { return header_begin() <= addr && addr < blob_end(); }
229238
bool code_contains(address addr) const { return code_begin() <= addr && addr < code_end(); }
230239
bool contains(address addr) const { return content_begin() <= addr && addr < content_end(); }
231240
bool is_frame_complete_at(address addr) const { return _frame_complete_offset != CodeOffsets::frame_never_safe &&

0 commit comments

Comments
 (0)