@@ -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.
111111unsigned 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
122119CodeBlob::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.
152160CodeBlob::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
171180void 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}
0 commit comments