230 BufferBlob* BufferBlob::create(const char* name, uint buffer_size) {
231 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
232
233 BufferBlob* blob = nullptr;
234 unsigned int size = sizeof(BufferBlob);
235 // align the size to CodeEntryAlignment
236 size = CodeBlob::align_code_offset(size);
237 size += align_up(buffer_size, oopSize);
238 assert(name != nullptr, "must provide a name");
239 {
240 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
241 blob = new (size) BufferBlob(name, CodeBlobKind::Buffer, size);
242 }
243 // Track memory usage statistic after releasing CodeCache_lock
244 MemoryService::track_code_cache_memory_usage();
245
246 return blob;
247 }
248
249
250 BufferBlob::BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size)
251 : RuntimeBlob(name, kind, cb, size, sizeof(BufferBlob), CodeOffsets::frame_never_safe, 0, nullptr)
252 {}
253
254 // Used by gtest
255 BufferBlob* BufferBlob::create(const char* name, CodeBuffer* cb) {
256 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
257
258 BufferBlob* blob = nullptr;
259 unsigned int size = CodeBlob::allocation_size(cb, sizeof(BufferBlob));
260 assert(name != nullptr, "must provide a name");
261 {
262 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
263 blob = new (size) BufferBlob(name, CodeBlobKind::Buffer, cb, size);
264 }
265 // Track memory usage statistic after releasing CodeCache_lock
266 MemoryService::track_code_cache_memory_usage();
267
268 return blob;
269 }
270
271 void* BufferBlob::operator new(size_t s, unsigned size) throw() {
272 return CodeCache::allocate(size, CodeBlobType::NonNMethod);
273 }
274
275 void BufferBlob::free(BufferBlob *blob) {
276 RuntimeBlob::free(blob);
277 }
278
279
280 //----------------------------------------------------------------------------------------------------
281 // Implementation of AdapterBlob
282
283 AdapterBlob::AdapterBlob(int size, CodeBuffer* cb) :
284 BufferBlob("I2C/C2I adapters", CodeBlobKind::Adapter, cb, size) {
285 CodeCache::commit(this);
286 }
287
288 AdapterBlob* AdapterBlob::create(CodeBuffer* cb) {
289 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
290
291 CodeCache::gc_on_allocation();
292
293 AdapterBlob* blob = nullptr;
294 unsigned int size = CodeBlob::allocation_size(cb, sizeof(AdapterBlob));
295 {
296 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
297 blob = new (size) AdapterBlob(size, cb);
298 }
299 // Track memory usage statistic after releasing CodeCache_lock
300 MemoryService::track_code_cache_memory_usage();
301
302 return blob;
303 }
304
305 //----------------------------------------------------------------------------------------------------
306 // Implementation of VtableBlob
307
308 void* VtableBlob::operator new(size_t s, unsigned size) throw() {
309 // Handling of allocation failure stops compilation and prints a bunch of
310 // stuff, which requires unlocking the CodeCache_lock, so that the Compile_lock
311 // can be locked, and then re-locking the CodeCache_lock. That is not safe in
312 // this context as we hold the CompiledICLocker. So we just don't handle code
313 // cache exhaustion here; we leave that for a later allocation that does not
314 // hold the CompiledICLocker.
315 return CodeCache::allocate(size, CodeBlobType::NonNMethod, false /* handle_alloc_failure */);
316 }
317
358 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
359
360 MethodHandlesAdapterBlob* blob = nullptr;
361 unsigned int size = sizeof(MethodHandlesAdapterBlob);
362 // align the size to CodeEntryAlignment
363 size = CodeBlob::align_code_offset(size);
364 size += align_up(buffer_size, oopSize);
365 {
366 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
367 blob = new (size) MethodHandlesAdapterBlob(size);
368 if (blob == nullptr) {
369 vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "CodeCache: no room for method handle adapter blob");
370 }
371 }
372 // Track memory usage statistic after releasing CodeCache_lock
373 MemoryService::track_code_cache_memory_usage();
374
375 return blob;
376 }
377
378 //----------------------------------------------------------------------------------------------------
379 // Implementation of RuntimeStub
380
381 RuntimeStub::RuntimeStub(
382 const char* name,
383 CodeBuffer* cb,
384 int size,
385 int16_t frame_complete,
386 int frame_size,
387 OopMapSet* oop_maps,
388 bool caller_must_gc_arguments
389 )
390 : RuntimeBlob(name, CodeBlobKind::Runtime_Stub, cb, size, sizeof(RuntimeStub),
391 frame_complete, frame_size, oop_maps, caller_must_gc_arguments)
392 {
393 }
394
395 RuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name,
396 CodeBuffer* cb,
397 int16_t frame_complete,
|
230 BufferBlob* BufferBlob::create(const char* name, uint buffer_size) {
231 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
232
233 BufferBlob* blob = nullptr;
234 unsigned int size = sizeof(BufferBlob);
235 // align the size to CodeEntryAlignment
236 size = CodeBlob::align_code_offset(size);
237 size += align_up(buffer_size, oopSize);
238 assert(name != nullptr, "must provide a name");
239 {
240 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
241 blob = new (size) BufferBlob(name, CodeBlobKind::Buffer, size);
242 }
243 // Track memory usage statistic after releasing CodeCache_lock
244 MemoryService::track_code_cache_memory_usage();
245
246 return blob;
247 }
248
249
250 BufferBlob::BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, int header_size)
251 : RuntimeBlob(name, kind, cb, size, header_size, CodeOffsets::frame_never_safe, 0, nullptr)
252 {}
253
254 // Used by gtest
255 BufferBlob* BufferBlob::create(const char* name, CodeBuffer* cb) {
256 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
257
258 BufferBlob* blob = nullptr;
259 unsigned int size = CodeBlob::allocation_size(cb, sizeof(BufferBlob));
260 assert(name != nullptr, "must provide a name");
261 {
262 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
263 blob = new (size) BufferBlob(name, CodeBlobKind::Buffer, cb, size, sizeof(BufferBlob));
264 }
265 // Track memory usage statistic after releasing CodeCache_lock
266 MemoryService::track_code_cache_memory_usage();
267
268 return blob;
269 }
270
271 void* BufferBlob::operator new(size_t s, unsigned size) throw() {
272 return CodeCache::allocate(size, CodeBlobType::NonNMethod);
273 }
274
275 void BufferBlob::free(BufferBlob *blob) {
276 RuntimeBlob::free(blob);
277 }
278
279 BufferBlob::BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, int frame_complete, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments)
280 : RuntimeBlob(name, kind, cb, size, sizeof(BufferBlob), frame_complete, frame_size, oop_maps, caller_must_gc_arguments)
281 {}
282
283
284 //----------------------------------------------------------------------------------------------------
285 // Implementation of AdapterBlob
286
287 AdapterBlob::AdapterBlob(int size, CodeBuffer* cb, int frame_complete, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments) :
288 BufferBlob("I2C/C2I adapters", CodeBlobKind::Adapter, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments) {
289 CodeCache::commit(this);
290 }
291
292 AdapterBlob* AdapterBlob::create(CodeBuffer* cb, int frame_complete, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments) {
293 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
294
295 CodeCache::gc_on_allocation();
296
297 AdapterBlob* blob = nullptr;
298 unsigned int size = CodeBlob::allocation_size(cb, sizeof(AdapterBlob));
299 {
300 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
301 blob = new (size) AdapterBlob(size, cb, frame_complete, frame_size, oop_maps, caller_must_gc_arguments);
302 }
303 // Track memory usage statistic after releasing CodeCache_lock
304 MemoryService::track_code_cache_memory_usage();
305
306 return blob;
307 }
308
309 //----------------------------------------------------------------------------------------------------
310 // Implementation of VtableBlob
311
312 void* VtableBlob::operator new(size_t s, unsigned size) throw() {
313 // Handling of allocation failure stops compilation and prints a bunch of
314 // stuff, which requires unlocking the CodeCache_lock, so that the Compile_lock
315 // can be locked, and then re-locking the CodeCache_lock. That is not safe in
316 // this context as we hold the CompiledICLocker. So we just don't handle code
317 // cache exhaustion here; we leave that for a later allocation that does not
318 // hold the CompiledICLocker.
319 return CodeCache::allocate(size, CodeBlobType::NonNMethod, false /* handle_alloc_failure */);
320 }
321
362 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
363
364 MethodHandlesAdapterBlob* blob = nullptr;
365 unsigned int size = sizeof(MethodHandlesAdapterBlob);
366 // align the size to CodeEntryAlignment
367 size = CodeBlob::align_code_offset(size);
368 size += align_up(buffer_size, oopSize);
369 {
370 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
371 blob = new (size) MethodHandlesAdapterBlob(size);
372 if (blob == nullptr) {
373 vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "CodeCache: no room for method handle adapter blob");
374 }
375 }
376 // Track memory usage statistic after releasing CodeCache_lock
377 MemoryService::track_code_cache_memory_usage();
378
379 return blob;
380 }
381
382 //----------------------------------------------------------------------------------------------------
383 // Implementation of BufferedInlineTypeBlob
384 BufferedInlineTypeBlob::BufferedInlineTypeBlob(int size, CodeBuffer* cb, int pack_fields_off, int pack_fields_jobject_off, int unpack_fields_off) :
385 BufferBlob("buffered inline type", CodeBlobKind::BufferedInlineType, cb, size, sizeof(BufferedInlineTypeBlob)),
386 _pack_fields_off(pack_fields_off),
387 _pack_fields_jobject_off(pack_fields_jobject_off),
388 _unpack_fields_off(unpack_fields_off) {
389 CodeCache::commit(this);
390 }
391
392 BufferedInlineTypeBlob* BufferedInlineTypeBlob::create(CodeBuffer* cb, int pack_fields_off, int pack_fields_jobject_off, int unpack_fields_off) {
393 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
394
395 BufferedInlineTypeBlob* blob = nullptr;
396 unsigned int size = CodeBlob::allocation_size(cb, sizeof(BufferedInlineTypeBlob));
397 {
398 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
399 blob = new (size) BufferedInlineTypeBlob(size, cb, pack_fields_off, pack_fields_jobject_off, unpack_fields_off);
400 }
401 // Track memory usage statistic after releasing CodeCache_lock
402 MemoryService::track_code_cache_memory_usage();
403
404 return blob;
405 }
406
407 //----------------------------------------------------------------------------------------------------
408 // Implementation of RuntimeStub
409
410 RuntimeStub::RuntimeStub(
411 const char* name,
412 CodeBuffer* cb,
413 int size,
414 int16_t frame_complete,
415 int frame_size,
416 OopMapSet* oop_maps,
417 bool caller_must_gc_arguments
418 )
419 : RuntimeBlob(name, CodeBlobKind::Runtime_Stub, cb, size, sizeof(RuntimeStub),
420 frame_complete, frame_size, oop_maps, caller_must_gc_arguments)
421 {
422 }
423
424 RuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name,
425 CodeBuffer* cb,
426 int16_t frame_complete,
|