< prev index next >

src/hotspot/share/code/nmethod.cpp


1348                   is_osr_method() ? "osr" : "",_compile_id, p2i(this), CodeCache::blob_count(),                                      
1349                   CodeCache::unallocated_capacity(CodeCache::get_code_blob_type(this))/1024);                                        
1350   }                                                                                                                                  
1351 
1352   // We need to deallocate any ExceptionCache data.                                                                                  
1353   // Note that we do not need to grab the nmethod lock for this, it                                                                  
1354   // better be thread safe if we're disposing of it!                                                                                 
1355   ExceptionCache* ec = exception_cache();                                                                                            
1356   set_exception_cache(NULL);                                                                                                         
1357   while(ec != NULL) {                                                                                                                
1358     ExceptionCache* next = ec->next();                                                                                               
1359     delete ec;                                                                                                                       
1360     ec = next;                                                                                                                       
1361   }                                                                                                                                  
1362 
1363   if (on_scavenge_root_list()) {                                                                                                     
1364     CodeCache::drop_scavenge_root_nmethod(this);                                                                                     
1365   }                                                                                                                                  
1366 
1367 #if INCLUDE_JVMCI                                                                                                                    
1368   assert(_jvmci_installed_code == NULL, "should have been nulled out when transitioned to zombie");                                  
1369   assert(_speculation_log == NULL, "should have been nulled out when transitioned to zombie");                                       
1370 #endif                                                                                                                               
1371 
1372   CodeBlob::flush();                                                                                                                 
1373   CodeCache::free(this);                                                                                                             
1374 }                                                                                                                                    
1375 
1376 oop nmethod::oop_at(int index) const {                                                                                               
1377   if (index == 0) {                                                                                                                  
1378     return NULL;                                                                                                                     
1379   }                                                                                                                                  
1380   return NativeAccess<AS_NO_KEEPALIVE>::oop_load(oop_addr_at(index));                                                                
1381 }                                                                                                                                    
1382 
1383 //                                                                                                                                   
1384 // Notify all classes this nmethod is dependent on that it is no                                                                     
1385 // longer dependent. This should only be called in two situations.                                                                   
1386 // First, when a nmethod transitions to a zombie all dependents need                                                                 
1387 // to be clear.  Since zombification happens at a safepoint there's no                                                               
1388 // synchronization issues.  The second place is a little more tricky.                                                                

1348                   is_osr_method() ? "osr" : "",_compile_id, p2i(this), CodeCache::blob_count(),
1349                   CodeCache::unallocated_capacity(CodeCache::get_code_blob_type(this))/1024);
1350   }
1351 
1352   // We need to deallocate any ExceptionCache data.
1353   // Note that we do not need to grab the nmethod lock for this, it
1354   // better be thread safe if we're disposing of it!
1355   ExceptionCache* ec = exception_cache();
1356   set_exception_cache(NULL);
1357   while(ec != NULL) {
1358     ExceptionCache* next = ec->next();
1359     delete ec;
1360     ec = next;
1361   }
1362 
1363   if (on_scavenge_root_list()) {
1364     CodeCache::drop_scavenge_root_nmethod(this);
1365   }
1366 
1367 #if INCLUDE_JVMCI
1368   clear_jvmci_installed_code();
1369   clear_speculation_log();
1370 #endif
1371 
1372   CodeBlob::flush();
1373   CodeCache::free(this);
1374 }
1375 
1376 oop nmethod::oop_at(int index) const {
1377   if (index == 0) {
1378     return NULL;
1379   }
1380   return NativeAccess<AS_NO_KEEPALIVE>::oop_load(oop_addr_at(index));
1381 }
1382 
1383 //
1384 // Notify all classes this nmethod is dependent on that it is no
1385 // longer dependent. This should only be called in two situations.
1386 // First, when a nmethod transitions to a zombie all dependents need
1387 // to be clear.  Since zombification happens at a safepoint there's no
1388 // synchronization issues.  The second place is a little more tricky.

1644 
1645 void nmethod::clear_unloading_state() {                                                                                              
1646   uint8_t state = IsUnloadingState::create(false, CodeCache::unloading_cycle());                                                     
1647   RawAccess<MO_RELAXED>::store(&_is_unloading_state, state);                                                                         
1648 }                                                                                                                                    
1649 
1650 
1651 // This is called at the end of the strong tracing/marking phase of a                                                                
1652 // GC to unload an nmethod if it contains otherwise unreachable                                                                      
1653 // oops.                                                                                                                             
1654 
1655 void nmethod::do_unloading(bool unloading_occurred) {                                                                                
1656   // Make sure the oop's ready to receive visitors                                                                                   
1657   assert(!is_zombie() && !is_unloaded(),                                                                                             
1658          "should not call follow on zombie or unloaded nmethod");                                                                    
1659 
1660   if (is_unloading()) {                                                                                                              
1661     make_unloaded();                                                                                                                 
1662   } else {                                                                                                                           
1663 #if INCLUDE_JVMCI                                                                                                                    
1664     if (_jvmci_installed_code != NULL) {                                                                                             
1665       if (JNIHandles::is_global_weak_cleared(_jvmci_installed_code)) {                                                               
1666         if (_jvmci_installed_code_triggers_invalidation) {                                                                           
1667           make_not_entrant();                                                                                                        
1668         }                                                                                                                            
1669         clear_jvmci_installed_code();                                                                                                
1670       }                                                                                                                              
1671     }                                                                                                                                
1672 #endif                                                                                                                               
1673 
1674     guarantee(unload_nmethod_caches(unloading_occurred),                                                                             
1675               "Should not need transition stubs");                                                                                   
1676   }                                                                                                                                  
1677 }                                                                                                                                    
1678 
1679 void nmethod::oops_do(OopClosure* f, bool allow_zombie) {                                                                            
1680   // make sure the oops ready to receive visitors                                                                                    
1681   assert(allow_zombie || !is_zombie(), "should not call follow on zombie nmethod");                                                  
1682   assert(!is_unloaded(), "should not call follow on unloaded nmethod");                                                              
1683 
1684   // Prevent extra code cache walk for platforms that don't have immediate oops.                                                     
1685   if (relocInfo::mustIterateImmediateOopsInCode()) {                                                                                 
1686     RelocIterator iter(this, oops_reloc_begin());                                                                                    
1687 
1688     while (iter.next()) {                                                                                                            
1689       if (iter.type() == relocInfo::oop_type ) {                                                                                     

1644 
1645 void nmethod::clear_unloading_state() {
1646   uint8_t state = IsUnloadingState::create(false, CodeCache::unloading_cycle());
1647   RawAccess<MO_RELAXED>::store(&_is_unloading_state, state);
1648 }
1649 
1650 
1651 // This is called at the end of the strong tracing/marking phase of a
1652 // GC to unload an nmethod if it contains otherwise unreachable
1653 // oops.
1654 
1655 void nmethod::do_unloading(bool unloading_occurred) {
1656   // Make sure the oop's ready to receive visitors
1657   assert(!is_zombie() && !is_unloaded(),
1658          "should not call follow on zombie or unloaded nmethod");
1659 
1660   if (is_unloading()) {
1661     make_unloaded();
1662   } else {
1663 #if INCLUDE_JVMCI
1664     if (_jvmci_installed_code != NULL &&
1665         JNIHandles::is_global_weak_cleared(_jvmci_installed_code) &&
1666         _jvmci_installed_code_triggers_invalidation) {
1667       make_not_entrant();



1668     }
1669 #endif
1670 
1671     guarantee(unload_nmethod_caches(unloading_occurred),
1672               "Should not need transition stubs");
1673   }
1674 }
1675 
1676 void nmethod::oops_do(OopClosure* f, bool allow_zombie) {
1677   // make sure the oops ready to receive visitors
1678   assert(allow_zombie || !is_zombie(), "should not call follow on zombie nmethod");
1679   assert(!is_unloaded(), "should not call follow on unloaded nmethod");
1680 
1681   // Prevent extra code cache walk for platforms that don't have immediate oops.
1682   if (relocInfo::mustIterateImmediateOopsInCode()) {
1683     RelocIterator iter(this, oops_reloc_begin());
1684 
1685     while (iter.next()) {
1686       if (iter.type() == relocInfo::oop_type ) {

2941 #endif                                                                                                                               
2942 #ifdef COMPILER2                                                                                                                     
2943   c2_java_nmethod_stats.print_nmethod_stats("C2");                                                                                   
2944 #endif                                                                                                                               
2945 #if INCLUDE_JVMCI                                                                                                                    
2946   jvmci_java_nmethod_stats.print_nmethod_stats("JVMCI");                                                                             
2947 #endif                                                                                                                               
2948   unknown_java_nmethod_stats.print_nmethod_stats("Unknown");                                                                         
2949   DebugInformationRecorder::print_statistics();                                                                                      
2950 #ifndef PRODUCT                                                                                                                      
2951   pc_nmethod_stats.print_pc_stats();                                                                                                 
2952 #endif                                                                                                                               
2953   Dependencies::print_statistics();                                                                                                  
2954   if (xtty != NULL)  xtty->tail("statistics");                                                                                       
2955 }                                                                                                                                    
2956 
2957 #endif // !PRODUCT                                                                                                                   
2958 
2959 #if INCLUDE_JVMCI                                                                                                                    
2960 void nmethod::clear_jvmci_installed_code() {                                                                                         
2961   assert_locked_or_safepoint(Patching_lock);                                                                                         
2962   if (_jvmci_installed_code != NULL) {                                                                                               
2963     JNIHandles::destroy_weak_global(_jvmci_installed_code);                                                                          
2964     _jvmci_installed_code = NULL;                                                                                                    
2965   }                                                                                                                                  
2966 }                                                                                                                                    
2967 
2968 void nmethod::clear_speculation_log() {                                                                                              
2969   assert_locked_or_safepoint(Patching_lock);                                                                                         
2970   if (_speculation_log != NULL) {                                                                                                    
2971     JNIHandles::destroy_weak_global(_speculation_log);                                                                               
2972     _speculation_log = NULL;                                                                                                         
2973   }                                                                                                                                  
2974 }                                                                                                                                    
2975 
2976 void nmethod::maybe_invalidate_installed_code() {                                                                                    
2977   if (!is_compiled_by_jvmci()) {                                                                                                     
2978     return;                                                                                                                          
2979   }                                                                                                                                  
2980 
2981   assert(Patching_lock->is_locked() ||                                                                                               
2982          SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency");                               
2983   oop installed_code = JNIHandles::resolve(_jvmci_installed_code);                                                                   
2984   if (installed_code != NULL) {                                                                                                      
2985     // Update the values in the InstalledCode instance if it still refers to this nmethod                                            
2986     nmethod* nm = (nmethod*)InstalledCode::address(installed_code);                                                                  
2987     if (nm == this) {                                                                                                                
2988       if (!is_alive() || is_unloading()) {                                                                                           
2989         // Break the link between nmethod and InstalledCode such that the nmethod                                                    
2990         // can subsequently be flushed safely.  The link must be maintained while                                                    
2991         // the method could have live activations since invalidateInstalledCode                                                      
2992         // might want to invalidate all existing activations.                                                                        
2993         InstalledCode::set_address(installed_code, 0);                                                                               
2994         InstalledCode::set_entryPoint(installed_code, 0);                                                                            
2995       } else if (is_not_entrant()) {                                                                                                 
2996         // Remove the entry point so any invocation will fail but keep                                                               
2997         // the address link around that so that existing activations can                                                             
2998         // be invalidated.                                                                                                           
2999         InstalledCode::set_entryPoint(installed_code, 0);                                                                            
3000       }                                                                                                                              
3001     }                                                                                                                                
3002   }                                                                                                                                  
3003   if (!is_alive() || is_unloading()) {                                                                                               
3004     // Clear these out after the nmethod has been unregistered and any                                                               
3005     // updates to the InstalledCode instance have been performed.                                                                    
3006     clear_jvmci_installed_code();                                                                                                    
3007     clear_speculation_log();                                                                                                         
3008   }                                                                                                                                  
3009 }                                                                                                                                    
3010 
3011 void nmethod::invalidate_installed_code(Handle installedCode, TRAPS) {                                                               
3012   if (installedCode() == NULL) {                                                                                                     
3013     THROW(vmSymbols::java_lang_NullPointerException());                                                                              
3014   }                                                                                                                                  
3015   jlong nativeMethod = InstalledCode::address(installedCode);                                                                        
3016   nmethod* nm = (nmethod*)nativeMethod;                                                                                              
3017   if (nm == NULL) {                                                                                                                  
3018     // Nothing to do                                                                                                                 
3019     return;                                                                                                                          
3020   }                                                                                                                                  
3021 
3022   nmethodLocker nml(nm);                                                                                                             
3023 #ifdef ASSERT                                                                                                                        
3024   {                                                                                                                                  
3025     MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);                                                                
3026     // This relationship can only be checked safely under a lock                                                                     

2938 #endif
2939 #ifdef COMPILER2
2940   c2_java_nmethod_stats.print_nmethod_stats("C2");
2941 #endif
2942 #if INCLUDE_JVMCI
2943   jvmci_java_nmethod_stats.print_nmethod_stats("JVMCI");
2944 #endif
2945   unknown_java_nmethod_stats.print_nmethod_stats("Unknown");
2946   DebugInformationRecorder::print_statistics();
2947 #ifndef PRODUCT
2948   pc_nmethod_stats.print_pc_stats();
2949 #endif
2950   Dependencies::print_statistics();
2951   if (xtty != NULL)  xtty->tail("statistics");
2952 }
2953 
2954 #endif // !PRODUCT
2955 
2956 #if INCLUDE_JVMCI
2957 void nmethod::clear_jvmci_installed_code() {

2958   if (_jvmci_installed_code != NULL) {
2959     JNIHandles::destroy_weak_global(_jvmci_installed_code);
2960     _jvmci_installed_code = NULL;
2961   }
2962 }
2963 
2964 void nmethod::clear_speculation_log() {

2965   if (_speculation_log != NULL) {
2966     JNIHandles::destroy_weak_global(_speculation_log);
2967     _speculation_log = NULL;
2968   }
2969 }
2970 
2971 void nmethod::maybe_invalidate_installed_code() {
2972   if (!is_compiled_by_jvmci()) {
2973     return;
2974   }
2975 
2976   assert(Patching_lock->is_locked() ||
2977          SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency");
2978   oop installed_code = JNIHandles::resolve(_jvmci_installed_code);
2979   if (installed_code != NULL) {
2980     // Update the values in the InstalledCode instance if it still refers to this nmethod
2981     nmethod* nm = (nmethod*)InstalledCode::address(installed_code);
2982     if (nm == this) {
2983       if (!is_alive() || is_unloading()) {
2984         // Break the link between nmethod and InstalledCode such that the nmethod
2985         // can subsequently be flushed safely.  The link must be maintained while
2986         // the method could have live activations since invalidateInstalledCode
2987         // might want to invalidate all existing activations.
2988         InstalledCode::set_address(installed_code, 0);
2989         InstalledCode::set_entryPoint(installed_code, 0);
2990       } else if (is_not_entrant()) {
2991         // Remove the entry point so any invocation will fail but keep
2992         // the address link around that so that existing activations can
2993         // be invalidated.
2994         InstalledCode::set_entryPoint(installed_code, 0);
2995       }
2996     }






2997   }
2998 }
2999 
3000 void nmethod::invalidate_installed_code(Handle installedCode, TRAPS) {
3001   if (installedCode() == NULL) {
3002     THROW(vmSymbols::java_lang_NullPointerException());
3003   }
3004   jlong nativeMethod = InstalledCode::address(installedCode);
3005   nmethod* nm = (nmethod*)nativeMethod;
3006   if (nm == NULL) {
3007     // Nothing to do
3008     return;
3009   }
3010 
3011   nmethodLocker nml(nm);
3012 #ifdef ASSERT
3013   {
3014     MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
3015     // This relationship can only be checked safely under a lock
< prev index next >