hotspot/src/share/vm/code/nmethod.cpp

Print this page




  48         signature->bytes(), signature->utf8_length());                    \
  49     }                                                                     \
  50   }
  51 
  52 #else //  ndef DTRACE_ENABLED
  53 
  54 #define DTRACE_METHOD_UNLOAD_PROBE(method)
  55 
  56 #endif
  57 
  58 bool nmethod::is_compiled_by_c1() const {
  59   if (compiler() == NULL || method() == NULL)  return false;  // can happen during debug printing
  60   if (is_native_method()) return false;
  61   return compiler()->is_c1();
  62 }
  63 bool nmethod::is_compiled_by_c2() const {
  64   if (compiler() == NULL || method() == NULL)  return false;  // can happen during debug printing
  65   if (is_native_method()) return false;
  66   return compiler()->is_c2();
  67 }





  68 
  69 
  70 
  71 //---------------------------------------------------------------------------------
  72 // NMethod statistics
  73 // They are printed under various flags, including:
  74 //   PrintC1Statistics, PrintOptoStatistics, LogVMOutput, and LogCompilation.
  75 // (In the latter two cases, they like other stats are printed to the log only.)
  76 
  77 #ifndef PRODUCT
  78 // These variables are put into one block to reduce relocations
  79 // and make it simpler to print from the debugger.
  80 static
  81 struct nmethod_stats_struct {
  82   int nmethod_count;
  83   int total_size;
  84   int relocation_size;
  85   int code_size;
  86   int stub_size;
  87   int consts_size;


1388 
1389   // We need to deallocate any ExceptionCache data.
1390   // Note that we do not need to grab the nmethod lock for this, it
1391   // better be thread safe if we're disposing of it!
1392   ExceptionCache* ec = exception_cache();
1393   set_exception_cache(NULL);
1394   while(ec != NULL) {
1395     ExceptionCache* next = ec->next();
1396     delete ec;
1397     ec = next;
1398   }
1399 
1400   if (on_scavenge_root_list()) {
1401     CodeCache::drop_scavenge_root_nmethod(this);
1402   }
1403 
1404   if (is_speculatively_disconnected()) {
1405     CodeCache::remove_saved_code(this);
1406   }
1407 




1408   ((CodeBlob*)(this))->flush();
1409 
1410   CodeCache::free(this);
1411 }
1412 
1413 
1414 //
1415 // Notify all classes this nmethod is dependent on that it is no
1416 // longer dependent. This should only be called in two situations.
1417 // First, when a nmethod transitions to a zombie all dependents need
1418 // to be clear.  Since zombification happens at a safepoint there's no
1419 // synchronization issues.  The second place is a little more tricky.
1420 // During phase 1 of mark sweep class unloading may happen and as a
1421 // result some nmethods may get unloaded.  In this case the flushing
1422 // of dependencies must happen during phase 1 since after GC any
1423 // dependencies in the unloaded nmethod won't be updated, so
1424 // traversing the dependency information in unsafe.  In that case this
1425 // function is called with a non-NULL argument and this function only
1426 // notifies instanceKlasses that are reachable
1427 


1785     if (_print_nm == NULL)  return;
1786     if (!_detected_scavenge_root)  _print_nm->print_on(tty, "new scavenge root");
1787     tty->print_cr(""PTR_FORMAT"[offset=%d] detected non-perm oop "PTR_FORMAT" (found at "PTR_FORMAT")",
1788                   _print_nm, (int)((intptr_t)p - (intptr_t)_print_nm),
1789                   (intptr_t)(*p), (intptr_t)p);
1790     (*p)->print();
1791   }
1792 #endif //PRODUCT
1793 };
1794 
1795 bool nmethod::detect_scavenge_root_oops() {
1796   DetectScavengeRoot detect_scavenge_root;
1797   NOT_PRODUCT(if (TraceScavenge)  detect_scavenge_root._print_nm = this);
1798   oops_do(&detect_scavenge_root);
1799   return detect_scavenge_root.detected_scavenge_root();
1800 }
1801 
1802 // Method that knows how to preserve outgoing arguments at call. This method must be
1803 // called with a frame corresponding to a Java invoke
1804 void nmethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) {

1805   if (!method()->is_native()) {
1806     SimpleScopeDesc ssd(this, fr.pc());
1807     Bytecode_invoke* call = Bytecode_invoke_at(ssd.method(), ssd.bci());
1808     bool has_receiver = call->has_receiver();
1809     symbolOop signature = call->signature();
1810     fr.oops_compiled_arguments_do(signature, has_receiver, reg_map, f);
1811   }

1812 }
1813 
1814 
1815 oop nmethod::embeddedOop_at(u_char* p) {
1816   RelocIterator iter(this, p, p + oopSize);
1817   while (iter.next())
1818     if (iter.type() == relocInfo::oop_type) {
1819       return iter.oop_reloc()->oop_value();
1820     }
1821   return NULL;
1822 }
1823 
1824 
1825 inline bool includes(void* p, void* from, void* to) {
1826   return from <= p && p < to;
1827 }
1828 
1829 
1830 void nmethod::copy_scopes_pcs(PcDesc* pcs, int count) {
1831   assert(count >= 2, "must be sentinel values, at least");


2296     if (!debug_scavenge_root.ok())
2297       fatal("found an unadvertised bad non-perm oop in the code cache");
2298   }
2299   assert(scavenge_root_not_marked(), "");
2300 }
2301 
2302 #endif // PRODUCT
2303 
2304 // Printing operations
2305 
2306 void nmethod::print() const {
2307   ResourceMark rm;
2308   ttyLocker ttyl;   // keep the following output all in one block
2309 
2310   tty->print("Compiled ");
2311 
2312   if (is_compiled_by_c1()) {
2313     tty->print("(c1) ");
2314   } else if (is_compiled_by_c2()) {
2315     tty->print("(c2) ");


2316   } else {
2317     tty->print("(nm) ");
2318   }
2319 
2320   print_on(tty, "nmethod");
2321   tty->cr();
2322   if (WizardMode) {
2323     tty->print("((nmethod*) "INTPTR_FORMAT ") ", this);
2324     tty->print(" for method " INTPTR_FORMAT , (address)method());
2325     tty->print(" { ");
2326     if (version())        tty->print("v%d ", version());
2327     if (is_in_use())      tty->print("in_use ");
2328     if (is_not_entrant()) tty->print("not_entrant ");
2329     if (is_zombie())      tty->print("zombie ");
2330     if (is_unloaded())    tty->print("unloaded ");
2331     if (on_scavenge_root_list())  tty->print("scavenge_root ");
2332     tty->print_cr("}:");
2333   }
2334   if (size              () > 0) tty->print_cr(" total in heap  [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2335                                               (address)this,




  48         signature->bytes(), signature->utf8_length());                    \
  49     }                                                                     \
  50   }
  51 
  52 #else //  ndef DTRACE_ENABLED
  53 
  54 #define DTRACE_METHOD_UNLOAD_PROBE(method)
  55 
  56 #endif
  57 
  58 bool nmethod::is_compiled_by_c1() const {
  59   if (compiler() == NULL || method() == NULL)  return false;  // can happen during debug printing
  60   if (is_native_method()) return false;
  61   return compiler()->is_c1();
  62 }
  63 bool nmethod::is_compiled_by_c2() const {
  64   if (compiler() == NULL || method() == NULL)  return false;  // can happen during debug printing
  65   if (is_native_method()) return false;
  66   return compiler()->is_c2();
  67 }
  68 bool nmethod::is_compiled_by_shark() const {
  69   if (is_native_method()) return false;
  70   assert(compiler() != NULL, "must be");
  71   return compiler()->is_shark();
  72 }
  73 
  74 
  75 
  76 //---------------------------------------------------------------------------------
  77 // NMethod statistics
  78 // They are printed under various flags, including:
  79 //   PrintC1Statistics, PrintOptoStatistics, LogVMOutput, and LogCompilation.
  80 // (In the latter two cases, they like other stats are printed to the log only.)
  81 
  82 #ifndef PRODUCT
  83 // These variables are put into one block to reduce relocations
  84 // and make it simpler to print from the debugger.
  85 static
  86 struct nmethod_stats_struct {
  87   int nmethod_count;
  88   int total_size;
  89   int relocation_size;
  90   int code_size;
  91   int stub_size;
  92   int consts_size;


1393 
1394   // We need to deallocate any ExceptionCache data.
1395   // Note that we do not need to grab the nmethod lock for this, it
1396   // better be thread safe if we're disposing of it!
1397   ExceptionCache* ec = exception_cache();
1398   set_exception_cache(NULL);
1399   while(ec != NULL) {
1400     ExceptionCache* next = ec->next();
1401     delete ec;
1402     ec = next;
1403   }
1404 
1405   if (on_scavenge_root_list()) {
1406     CodeCache::drop_scavenge_root_nmethod(this);
1407   }
1408 
1409   if (is_speculatively_disconnected()) {
1410     CodeCache::remove_saved_code(this);
1411   }
1412 
1413 #ifdef SHARK
1414   ((SharkCompiler *) compiler())->free_compiled_method(instructions_begin());
1415 #endif // SHARK
1416   
1417   ((CodeBlob*)(this))->flush();
1418 
1419   CodeCache::free(this);
1420 }
1421 
1422 
1423 //
1424 // Notify all classes this nmethod is dependent on that it is no
1425 // longer dependent. This should only be called in two situations.
1426 // First, when a nmethod transitions to a zombie all dependents need
1427 // to be clear.  Since zombification happens at a safepoint there's no
1428 // synchronization issues.  The second place is a little more tricky.
1429 // During phase 1 of mark sweep class unloading may happen and as a
1430 // result some nmethods may get unloaded.  In this case the flushing
1431 // of dependencies must happen during phase 1 since after GC any
1432 // dependencies in the unloaded nmethod won't be updated, so
1433 // traversing the dependency information in unsafe.  In that case this
1434 // function is called with a non-NULL argument and this function only
1435 // notifies instanceKlasses that are reachable
1436 


1794     if (_print_nm == NULL)  return;
1795     if (!_detected_scavenge_root)  _print_nm->print_on(tty, "new scavenge root");
1796     tty->print_cr(""PTR_FORMAT"[offset=%d] detected non-perm oop "PTR_FORMAT" (found at "PTR_FORMAT")",
1797                   _print_nm, (int)((intptr_t)p - (intptr_t)_print_nm),
1798                   (intptr_t)(*p), (intptr_t)p);
1799     (*p)->print();
1800   }
1801 #endif //PRODUCT
1802 };
1803 
1804 bool nmethod::detect_scavenge_root_oops() {
1805   DetectScavengeRoot detect_scavenge_root;
1806   NOT_PRODUCT(if (TraceScavenge)  detect_scavenge_root._print_nm = this);
1807   oops_do(&detect_scavenge_root);
1808   return detect_scavenge_root.detected_scavenge_root();
1809 }
1810 
1811 // Method that knows how to preserve outgoing arguments at call. This method must be
1812 // called with a frame corresponding to a Java invoke
1813 void nmethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) {
1814 #ifndef SHARK
1815   if (!method()->is_native()) {
1816     SimpleScopeDesc ssd(this, fr.pc());
1817     Bytecode_invoke* call = Bytecode_invoke_at(ssd.method(), ssd.bci());
1818     bool has_receiver = call->has_receiver();
1819     symbolOop signature = call->signature();
1820     fr.oops_compiled_arguments_do(signature, has_receiver, reg_map, f);
1821   }
1822 #endif // !SHARK
1823 }
1824 
1825 
1826 oop nmethod::embeddedOop_at(u_char* p) {
1827   RelocIterator iter(this, p, p + oopSize);
1828   while (iter.next())
1829     if (iter.type() == relocInfo::oop_type) {
1830       return iter.oop_reloc()->oop_value();
1831     }
1832   return NULL;
1833 }
1834 
1835 
1836 inline bool includes(void* p, void* from, void* to) {
1837   return from <= p && p < to;
1838 }
1839 
1840 
1841 void nmethod::copy_scopes_pcs(PcDesc* pcs, int count) {
1842   assert(count >= 2, "must be sentinel values, at least");


2307     if (!debug_scavenge_root.ok())
2308       fatal("found an unadvertised bad non-perm oop in the code cache");
2309   }
2310   assert(scavenge_root_not_marked(), "");
2311 }
2312 
2313 #endif // PRODUCT
2314 
2315 // Printing operations
2316 
2317 void nmethod::print() const {
2318   ResourceMark rm;
2319   ttyLocker ttyl;   // keep the following output all in one block
2320 
2321   tty->print("Compiled ");
2322 
2323   if (is_compiled_by_c1()) {
2324     tty->print("(c1) ");
2325   } else if (is_compiled_by_c2()) {
2326     tty->print("(c2) ");
2327   } else if (is_compiled_by_shark()) {
2328     tty->print("(shark) ");
2329   } else {
2330     tty->print("(nm) ");
2331   }
2332 
2333   print_on(tty, "nmethod");
2334   tty->cr();
2335   if (WizardMode) {
2336     tty->print("((nmethod*) "INTPTR_FORMAT ") ", this);
2337     tty->print(" for method " INTPTR_FORMAT , (address)method());
2338     tty->print(" { ");
2339     if (version())        tty->print("v%d ", version());
2340     if (is_in_use())      tty->print("in_use ");
2341     if (is_not_entrant()) tty->print("not_entrant ");
2342     if (is_zombie())      tty->print("zombie ");
2343     if (is_unloaded())    tty->print("unloaded ");
2344     if (on_scavenge_root_list())  tty->print("scavenge_root ");
2345     tty->print_cr("}:");
2346   }
2347   if (size              () > 0) tty->print_cr(" total in heap  [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2348                                               (address)this,