190
191 void CodeBlob::restore_mutable_data(address reloc_data) {
192 // Relocation data is now stored as part of the mutable data area; allocate it before copy relocations
193 if (_mutable_data_size > 0) {
194 _mutable_data = (address)os::malloc(_mutable_data_size, mtCode);
195 if (_mutable_data == nullptr) {
196 vm_exit_out_of_memory(_mutable_data_size, OOM_MALLOC_ERROR, "codebuffer: no space for mutable data");
197 }
198 }
199 if (_relocation_size > 0) {
200 memcpy((address)relocation_begin(), reloc_data, relocation_size());
201 }
202 }
203
204 void CodeBlob::purge() {
205 assert(_mutable_data != nullptr, "should never be null");
206 if (_mutable_data != blob_end()) {
207 os::free(_mutable_data);
208 _mutable_data = blob_end(); // Valid not null address
209 }
210 if (_oop_maps != nullptr) {
211 delete _oop_maps;
212 _oop_maps = nullptr;
213 }
214 NOT_PRODUCT(_asm_remarks.clear());
215 NOT_PRODUCT(_dbg_strings.clear());
216 }
217
218 void CodeBlob::set_oop_maps(OopMapSet* p) {
219 // Danger Will Robinson! This method allocates a big
220 // chunk of memory, its your job to free it.
221 if (p != nullptr) {
222 _oop_maps = ImmutableOopMapSet::build_from(p);
223 } else {
224 _oop_maps = nullptr;
225 }
226 }
227
228 const ImmutableOopMap* CodeBlob::oop_map_for_return_address(address return_address) const {
229 assert(_oop_maps != nullptr, "nope");
230 return _oop_maps->find_map_at_offset((intptr_t) return_address - (intptr_t) code_begin());
264 vptr(_kind)->post_restore(this);
265 }
266
267 CodeBlob* CodeBlob::restore(address code_cache_buffer,
268 const char* name,
269 address archived_reloc_data,
270 ImmutableOopMapSet* archived_oop_maps)
271 {
272 copy_to(code_cache_buffer);
273 CodeBlob* code_blob = (CodeBlob*)code_cache_buffer;
274 code_blob->set_name(name);
275 code_blob->restore_mutable_data(archived_reloc_data);
276 code_blob->set_oop_maps(archived_oop_maps);
277 return code_blob;
278 }
279
280 CodeBlob* CodeBlob::create(CodeBlob* archived_blob,
281 const char* name,
282 address archived_reloc_data,
283 ImmutableOopMapSet* archived_oop_maps
284 #ifndef PRODUCT
285 , AsmRemarks& archived_asm_remarks
286 , DbgStrings& archived_dbg_strings
287 #endif // PRODUCT
288 )
289 {
290 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
291
292 CodeCache::gc_on_allocation();
293
294 CodeBlob* blob = nullptr;
295 unsigned int size = archived_blob->size();
296 {
297 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
298 address code_cache_buffer = (address)CodeCache::allocate(size, CodeBlobType::NonNMethod);
299 if (code_cache_buffer != nullptr) {
300 blob = archived_blob->restore(code_cache_buffer,
301 name,
302 archived_reloc_data,
303 archived_oop_maps);
304 #ifndef PRODUCT
305 blob->use_remarks(archived_asm_remarks);
306 archived_asm_remarks.clear();
307 blob->use_strings(archived_dbg_strings);
308 archived_dbg_strings.clear();
309 #endif // PRODUCT
310
311 assert(blob != nullptr, "sanity check");
312 // Flush the code block
313 ICache::invalidate_range(blob->code_begin(), blob->code_size());
314 CodeCache::commit(blob); // Count adapters
315 }
316 }
317 if (blob != nullptr) {
318 blob->post_restore();
319 }
320 return blob;
321 }
322
323 //-----------------------------------------------------------------------------------------
324 // Creates a RuntimeBlob from a CodeBuffer and copy code and relocation info.
325
326 RuntimeBlob::RuntimeBlob(
327 const char* name,
328 CodeBlobKind kind,
329 CodeBuffer* cb,
|
190
191 void CodeBlob::restore_mutable_data(address reloc_data) {
192 // Relocation data is now stored as part of the mutable data area; allocate it before copy relocations
193 if (_mutable_data_size > 0) {
194 _mutable_data = (address)os::malloc(_mutable_data_size, mtCode);
195 if (_mutable_data == nullptr) {
196 vm_exit_out_of_memory(_mutable_data_size, OOM_MALLOC_ERROR, "codebuffer: no space for mutable data");
197 }
198 }
199 if (_relocation_size > 0) {
200 memcpy((address)relocation_begin(), reloc_data, relocation_size());
201 }
202 }
203
204 void CodeBlob::purge() {
205 assert(_mutable_data != nullptr, "should never be null");
206 if (_mutable_data != blob_end()) {
207 os::free(_mutable_data);
208 _mutable_data = blob_end(); // Valid not null address
209 }
210 if (_oop_maps != nullptr && !AOTCodeCache::is_address_in_aot_cache((address)_oop_maps)) {
211 delete _oop_maps;
212 _oop_maps = nullptr;
213 }
214 NOT_PRODUCT(_asm_remarks.clear());
215 NOT_PRODUCT(_dbg_strings.clear());
216 }
217
218 void CodeBlob::set_oop_maps(OopMapSet* p) {
219 // Danger Will Robinson! This method allocates a big
220 // chunk of memory, its your job to free it.
221 if (p != nullptr) {
222 _oop_maps = ImmutableOopMapSet::build_from(p);
223 } else {
224 _oop_maps = nullptr;
225 }
226 }
227
228 const ImmutableOopMap* CodeBlob::oop_map_for_return_address(address return_address) const {
229 assert(_oop_maps != nullptr, "nope");
230 return _oop_maps->find_map_at_offset((intptr_t) return_address - (intptr_t) code_begin());
264 vptr(_kind)->post_restore(this);
265 }
266
267 CodeBlob* CodeBlob::restore(address code_cache_buffer,
268 const char* name,
269 address archived_reloc_data,
270 ImmutableOopMapSet* archived_oop_maps)
271 {
272 copy_to(code_cache_buffer);
273 CodeBlob* code_blob = (CodeBlob*)code_cache_buffer;
274 code_blob->set_name(name);
275 code_blob->restore_mutable_data(archived_reloc_data);
276 code_blob->set_oop_maps(archived_oop_maps);
277 return code_blob;
278 }
279
280 CodeBlob* CodeBlob::create(CodeBlob* archived_blob,
281 const char* name,
282 address archived_reloc_data,
283 ImmutableOopMapSet* archived_oop_maps
284 )
285 {
286 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
287
288 CodeCache::gc_on_allocation();
289
290 CodeBlob* blob = nullptr;
291 unsigned int size = archived_blob->size();
292 {
293 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
294 address code_cache_buffer = (address)CodeCache::allocate(size, CodeBlobType::NonNMethod);
295 if (code_cache_buffer != nullptr) {
296 blob = archived_blob->restore(code_cache_buffer,
297 name,
298 archived_reloc_data,
299 archived_oop_maps);
300
301 assert(blob != nullptr, "sanity check");
302 // Flush the code block
303 ICache::invalidate_range(blob->code_begin(), blob->code_size());
304 CodeCache::commit(blob); // Count adapters
305 }
306 }
307 if (blob != nullptr) {
308 blob->post_restore();
309 }
310 return blob;
311 }
312
313 //-----------------------------------------------------------------------------------------
314 // Creates a RuntimeBlob from a CodeBuffer and copy code and relocation info.
315
316 RuntimeBlob::RuntimeBlob(
317 const char* name,
318 CodeBlobKind kind,
319 CodeBuffer* cb,
|