src/hotspot/share/code/codeBlob.cpp
changeset 54623 1126f0607c70
parent 52014 1aa9beac610e
child 54763 2584e5772546
equal deleted inserted replaced
54622:a8dcacf95bff 54623:1126f0607c70
     1 /*
     1 /*
     2  * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   225   // align the size to CodeEntryAlignment
   225   // align the size to CodeEntryAlignment
   226   size = CodeBlob::align_code_offset(size);
   226   size = CodeBlob::align_code_offset(size);
   227   size += align_up(buffer_size, oopSize);
   227   size += align_up(buffer_size, oopSize);
   228   assert(name != NULL, "must provide a name");
   228   assert(name != NULL, "must provide a name");
   229   {
   229   {
   230     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   230     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   231     blob = new (size) BufferBlob(name, size);
   231     blob = new (size) BufferBlob(name, size);
   232   }
   232   }
   233   // Track memory usage statistic after releasing CodeCache_lock
   233   // Track memory usage statistic after releasing CodeCache_lock
   234   MemoryService::track_code_cache_memory_usage();
   234   MemoryService::track_code_cache_memory_usage();
   235 
   235 
   246 
   246 
   247   BufferBlob* blob = NULL;
   247   BufferBlob* blob = NULL;
   248   unsigned int size = CodeBlob::allocation_size(cb, sizeof(BufferBlob));
   248   unsigned int size = CodeBlob::allocation_size(cb, sizeof(BufferBlob));
   249   assert(name != NULL, "must provide a name");
   249   assert(name != NULL, "must provide a name");
   250   {
   250   {
   251     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   251     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   252     blob = new (size) BufferBlob(name, size, cb);
   252     blob = new (size) BufferBlob(name, size, cb);
   253   }
   253   }
   254   // Track memory usage statistic after releasing CodeCache_lock
   254   // Track memory usage statistic after releasing CodeCache_lock
   255   MemoryService::track_code_cache_memory_usage();
   255   MemoryService::track_code_cache_memory_usage();
   256 
   256 
   263 
   263 
   264 void BufferBlob::free(BufferBlob *blob) {
   264 void BufferBlob::free(BufferBlob *blob) {
   265   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
   265   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
   266   blob->flush();
   266   blob->flush();
   267   {
   267   {
   268     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   268     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   269     CodeCache::free((RuntimeBlob*)blob);
   269     CodeCache::free((RuntimeBlob*)blob);
   270   }
   270   }
   271   // Track memory usage statistic after releasing CodeCache_lock
   271   // Track memory usage statistic after releasing CodeCache_lock
   272   MemoryService::track_code_cache_memory_usage();
   272   MemoryService::track_code_cache_memory_usage();
   273 }
   273 }
   285   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
   285   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
   286 
   286 
   287   AdapterBlob* blob = NULL;
   287   AdapterBlob* blob = NULL;
   288   unsigned int size = CodeBlob::allocation_size(cb, sizeof(AdapterBlob));
   288   unsigned int size = CodeBlob::allocation_size(cb, sizeof(AdapterBlob));
   289   {
   289   {
   290     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   290     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   291     blob = new (size) AdapterBlob(size, cb);
   291     blob = new (size) AdapterBlob(size, cb);
   292   }
   292   }
   293   // Track memory usage statistic after releasing CodeCache_lock
   293   // Track memory usage statistic after releasing CodeCache_lock
   294   MemoryService::track_code_cache_memory_usage();
   294   MemoryService::track_code_cache_memory_usage();
   295 
   295 
   308   // align the size to CodeEntryAlignment
   308   // align the size to CodeEntryAlignment
   309   size = align_code_offset(size);
   309   size = align_code_offset(size);
   310   size += align_up(buffer_size, oopSize);
   310   size += align_up(buffer_size, oopSize);
   311   assert(name != NULL, "must provide a name");
   311   assert(name != NULL, "must provide a name");
   312   {
   312   {
   313     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   313     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   314     blob = new (size) VtableBlob(name, size);
   314     blob = new (size) VtableBlob(name, size);
   315   }
   315   }
   316   // Track memory usage statistic after releasing CodeCache_lock
   316   // Track memory usage statistic after releasing CodeCache_lock
   317   MemoryService::track_code_cache_memory_usage();
   317   MemoryService::track_code_cache_memory_usage();
   318 
   318 
   329   unsigned int size = sizeof(MethodHandlesAdapterBlob);
   329   unsigned int size = sizeof(MethodHandlesAdapterBlob);
   330   // align the size to CodeEntryAlignment
   330   // align the size to CodeEntryAlignment
   331   size = CodeBlob::align_code_offset(size);
   331   size = CodeBlob::align_code_offset(size);
   332   size += align_up(buffer_size, oopSize);
   332   size += align_up(buffer_size, oopSize);
   333   {
   333   {
   334     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   334     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   335     blob = new (size) MethodHandlesAdapterBlob(size);
   335     blob = new (size) MethodHandlesAdapterBlob(size);
   336     if (blob == NULL) {
   336     if (blob == NULL) {
   337       vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "CodeCache: no room for method handle adapter blob");
   337       vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "CodeCache: no room for method handle adapter blob");
   338     }
   338     }
   339   }
   339   }
   367                                            bool caller_must_gc_arguments)
   367                                            bool caller_must_gc_arguments)
   368 {
   368 {
   369   RuntimeStub* stub = NULL;
   369   RuntimeStub* stub = NULL;
   370   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
   370   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
   371   {
   371   {
   372     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   372     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   373     unsigned int size = CodeBlob::allocation_size(cb, sizeof(RuntimeStub));
   373     unsigned int size = CodeBlob::allocation_size(cb, sizeof(RuntimeStub));
   374     stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments);
   374     stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments);
   375   }
   375   }
   376 
   376 
   377   trace_new_stub(stub, "RuntimeStub - ", stub_name);
   377   trace_new_stub(stub, "RuntimeStub - ", stub_name);
   426   int        frame_size)
   426   int        frame_size)
   427 {
   427 {
   428   DeoptimizationBlob* blob = NULL;
   428   DeoptimizationBlob* blob = NULL;
   429   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
   429   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
   430   {
   430   {
   431     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   431     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   432     unsigned int size = CodeBlob::allocation_size(cb, sizeof(DeoptimizationBlob));
   432     unsigned int size = CodeBlob::allocation_size(cb, sizeof(DeoptimizationBlob));
   433     blob = new (size) DeoptimizationBlob(cb,
   433     blob = new (size) DeoptimizationBlob(cb,
   434                                          size,
   434                                          size,
   435                                          oop_maps,
   435                                          oop_maps,
   436                                          unpack_offset,
   436                                          unpack_offset,
   465   int        frame_size)
   465   int        frame_size)
   466 {
   466 {
   467   UncommonTrapBlob* blob = NULL;
   467   UncommonTrapBlob* blob = NULL;
   468   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
   468   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
   469   {
   469   {
   470     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   470     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   471     unsigned int size = CodeBlob::allocation_size(cb, sizeof(UncommonTrapBlob));
   471     unsigned int size = CodeBlob::allocation_size(cb, sizeof(UncommonTrapBlob));
   472     blob = new (size) UncommonTrapBlob(cb, size, oop_maps, frame_size);
   472     blob = new (size) UncommonTrapBlob(cb, size, oop_maps, frame_size);
   473   }
   473   }
   474 
   474 
   475   trace_new_stub(blob, "UncommonTrapBlob");
   475   trace_new_stub(blob, "UncommonTrapBlob");
   501   int         frame_size)
   501   int         frame_size)
   502 {
   502 {
   503   ExceptionBlob* blob = NULL;
   503   ExceptionBlob* blob = NULL;
   504   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
   504   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
   505   {
   505   {
   506     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   506     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   507     unsigned int size = CodeBlob::allocation_size(cb, sizeof(ExceptionBlob));
   507     unsigned int size = CodeBlob::allocation_size(cb, sizeof(ExceptionBlob));
   508     blob = new (size) ExceptionBlob(cb, size, oop_maps, frame_size);
   508     blob = new (size) ExceptionBlob(cb, size, oop_maps, frame_size);
   509   }
   509   }
   510 
   510 
   511   trace_new_stub(blob, "ExceptionBlob");
   511   trace_new_stub(blob, "ExceptionBlob");
   536   int         frame_size)
   536   int         frame_size)
   537 {
   537 {
   538   SafepointBlob* blob = NULL;
   538   SafepointBlob* blob = NULL;
   539   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
   539   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
   540   {
   540   {
   541     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   541     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   542     unsigned int size = CodeBlob::allocation_size(cb, sizeof(SafepointBlob));
   542     unsigned int size = CodeBlob::allocation_size(cb, sizeof(SafepointBlob));
   543     blob = new (size) SafepointBlob(cb, size, oop_maps, frame_size);
   543     blob = new (size) SafepointBlob(cb, size, oop_maps, frame_size);
   544   }
   544   }
   545 
   545 
   546   trace_new_stub(blob, "SafepointBlob");
   546   trace_new_stub(blob, "SafepointBlob");