src/share/vm/code/nmethod.cpp

Print this page
rev 4338 : imported patch JDK-8009026

@@ -500,10 +500,12 @@
   // create nmethod
   nmethod* nm = NULL;
   {
     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
     int native_nmethod_size = allocation_size(code_buffer, sizeof(nmethod));
+    guarantee(CodeCache::largest_free_block() > (CodeCacheMinimumFreeSpace + native_nmethod_size),
+              "insufficient space for native method");
     CodeOffsets offsets;
     offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
     offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
     nm = new (native_nmethod_size)
       nmethod(method(), native_nmethod_size, compile_id, &offsets,

@@ -535,10 +537,12 @@
   // create nmethod
   nmethod* nm = NULL;
   {
     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
     int nmethod_size = allocation_size(code_buffer, sizeof(nmethod));
+    guarantee(CodeCache::largest_free_block() > (CodeCacheMinimumFreeSpace + nmethod_size),
+              "insufficient space for dtrace method");
     CodeOffsets offsets;
     offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
     offsets.set_value(CodeOffsets::Dtrace_trap, trap_offset);
     offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
 

@@ -585,10 +589,12 @@
       + adjust_pcs_size(debug_info->pcs_size())
       + round_to(dependencies->size_in_bytes() , oopSize)
       + round_to(handler_table->size_in_bytes(), oopSize)
       + round_to(nul_chk_table->size_in_bytes(), oopSize)
       + round_to(debug_info->data_size()       , oopSize);
+    guarantee(CodeCache::largest_free_block() > (CodeCacheMinimumFreeSpace + nmethod_size),
+              "insufficient space for nmethod");
     nm = new (nmethod_size)
       nmethod(method(), nmethod_size, compile_id, entry_bci, offsets,
               orig_pc_offset, debug_info, dependencies, code_buffer, frame_size,
               oop_maps,
               handler_table,

@@ -791,13 +797,13 @@
   }
 }
 #endif // def HAVE_DTRACE_H
 
 void* nmethod::operator new(size_t size, int nmethod_size) {
-  // Always leave some room in the CodeCache for I2C/C2I adapters
-  if (CodeCache::largest_free_block() < CodeCacheMinimumFreeSpace) return NULL;
-  return CodeCache::allocate(nmethod_size);
+  void*  alloc = CodeCache::allocate(nmethod_size);
+  guarantee(alloc != NULL, "CodeCache should have enough space");
+  return alloc;
 }
 
 
 nmethod::nmethod(
   Method* method,