1 /* |
1 /* |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2013, 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. |
91 #define DTRACE_METHOD_UNLOAD_PROBE(method) |
91 #define DTRACE_METHOD_UNLOAD_PROBE(method) |
92 |
92 |
93 #endif |
93 #endif |
94 |
94 |
95 bool nmethod::is_compiled_by_c1() const { |
95 bool nmethod::is_compiled_by_c1() const { |
96 if (compiler() == NULL || method() == NULL) return false; // can happen during debug printing |
96 if (compiler() == NULL) { |
97 if (is_native_method()) return false; |
97 return false; |
|
98 } |
98 return compiler()->is_c1(); |
99 return compiler()->is_c1(); |
99 } |
100 } |
100 bool nmethod::is_compiled_by_c2() const { |
101 bool nmethod::is_compiled_by_c2() const { |
101 if (compiler() == NULL || method() == NULL) return false; // can happen during debug printing |
102 if (compiler() == NULL) { |
102 if (is_native_method()) return false; |
103 return false; |
|
104 } |
103 return compiler()->is_c2(); |
105 return compiler()->is_c2(); |
104 } |
106 } |
105 bool nmethod::is_compiled_by_shark() const { |
107 bool nmethod::is_compiled_by_shark() const { |
106 if (is_native_method()) return false; |
108 if (compiler() == NULL) { |
107 assert(compiler() != NULL, "must be"); |
109 return false; |
|
110 } |
108 return compiler()->is_shark(); |
111 return compiler()->is_shark(); |
109 } |
112 } |
110 |
113 |
111 |
114 |
112 |
115 |
457 // Fill in default values for various flag fields |
460 // Fill in default values for various flag fields |
458 void nmethod::init_defaults() { |
461 void nmethod::init_defaults() { |
459 _state = alive; |
462 _state = alive; |
460 _marked_for_reclamation = 0; |
463 _marked_for_reclamation = 0; |
461 _has_flushed_dependencies = 0; |
464 _has_flushed_dependencies = 0; |
462 _speculatively_disconnected = 0; |
|
463 _has_unsafe_access = 0; |
465 _has_unsafe_access = 0; |
464 _has_method_handle_invokes = 0; |
466 _has_method_handle_invokes = 0; |
465 _lazy_critical_native = 0; |
467 _lazy_critical_native = 0; |
466 _has_wide_vectors = 0; |
468 _has_wide_vectors = 0; |
467 _marked_for_deoptimization = 0; |
469 _marked_for_deoptimization = 0; |
681 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); |
682 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); |
682 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); |
683 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); |
683 _osr_entry_point = NULL; |
684 _osr_entry_point = NULL; |
684 _exception_cache = NULL; |
685 _exception_cache = NULL; |
685 _pc_desc_cache.reset_to(NULL); |
686 _pc_desc_cache.reset_to(NULL); |
|
687 _hotness_counter = NMethodSweeper::hotness_counter_reset_val(); |
686 |
688 |
687 code_buffer->copy_values_to(this); |
689 code_buffer->copy_values_to(this); |
688 if (ScavengeRootsInCode && detect_scavenge_root_oops()) { |
690 if (ScavengeRootsInCode && detect_scavenge_root_oops()) { |
689 CodeCache::add_scavenge_root_nmethod(this); |
691 CodeCache::add_scavenge_root_nmethod(this); |
690 Universe::heap()->register_nmethod(this); |
692 Universe::heap()->register_nmethod(this); |
765 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); |
767 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); |
766 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); |
768 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); |
767 _osr_entry_point = NULL; |
769 _osr_entry_point = NULL; |
768 _exception_cache = NULL; |
770 _exception_cache = NULL; |
769 _pc_desc_cache.reset_to(NULL); |
771 _pc_desc_cache.reset_to(NULL); |
|
772 _hotness_counter = NMethodSweeper::hotness_counter_reset_val(); |
770 |
773 |
771 code_buffer->copy_values_to(this); |
774 code_buffer->copy_values_to(this); |
772 debug_only(verify_scavenge_root_oops()); |
775 debug_only(verify_scavenge_root_oops()); |
773 CodeCache::commit(this); |
776 CodeCache::commit(this); |
774 } |
777 } |
798 } |
801 } |
799 } |
802 } |
800 } |
803 } |
801 #endif // def HAVE_DTRACE_H |
804 #endif // def HAVE_DTRACE_H |
802 |
805 |
803 void* nmethod::operator new(size_t size, int nmethod_size) { |
806 void* nmethod::operator new(size_t size, int nmethod_size) throw() { |
804 // Not critical, may return null if there is too little continuous memory |
807 // Not critical, may return null if there is too little continuous memory |
805 return CodeCache::allocate(nmethod_size); |
808 return CodeCache::allocate(nmethod_size); |
806 } |
809 } |
807 |
810 |
808 nmethod::nmethod( |
811 nmethod::nmethod( |
837 _entry_bci = entry_bci; |
840 _entry_bci = entry_bci; |
838 _compile_id = compile_id; |
841 _compile_id = compile_id; |
839 _comp_level = comp_level; |
842 _comp_level = comp_level; |
840 _compiler = compiler; |
843 _compiler = compiler; |
841 _orig_pc_offset = orig_pc_offset; |
844 _orig_pc_offset = orig_pc_offset; |
|
845 _hotness_counter = NMethodSweeper::hotness_counter_reset_val(); |
842 |
846 |
843 // Section offsets |
847 // Section offsets |
844 _consts_offset = content_offset() + code_buffer->total_offset_of(code_buffer->consts()); |
848 _consts_offset = content_offset() + code_buffer->total_offset_of(code_buffer->consts()); |
845 _stub_offset = content_offset() + code_buffer->total_offset_of(code_buffer->stubs()); |
849 _stub_offset = content_offset() + code_buffer->total_offset_of(code_buffer->stubs()); |
846 |
850 |
1171 } |
1175 } |
1172 } |
1176 } |
1173 |
1177 |
1174 // This is a private interface with the sweeper. |
1178 // This is a private interface with the sweeper. |
1175 void nmethod::mark_as_seen_on_stack() { |
1179 void nmethod::mark_as_seen_on_stack() { |
1176 assert(is_not_entrant(), "must be a non-entrant method"); |
1180 assert(is_alive(), "Must be an alive method"); |
1177 // Set the traversal mark to ensure that the sweeper does 2 |
1181 // Set the traversal mark to ensure that the sweeper does 2 |
1178 // cleaning passes before moving to zombie. |
1182 // cleaning passes before moving to zombie. |
1179 set_stack_traversal_mark(NMethodSweeper::traversal_count()); |
1183 set_stack_traversal_mark(NMethodSweeper::traversal_count()); |
1180 } |
1184 } |
1181 |
1185 |
1256 // The Method* is gone at this point |
1260 // The Method* is gone at this point |
1257 assert(_method == NULL, "Tautology"); |
1261 assert(_method == NULL, "Tautology"); |
1258 |
1262 |
1259 set_osr_link(NULL); |
1263 set_osr_link(NULL); |
1260 //set_scavenge_root_link(NULL); // done by prune_scavenge_root_nmethods |
1264 //set_scavenge_root_link(NULL); // done by prune_scavenge_root_nmethods |
1261 NMethodSweeper::notify(this); |
1265 NMethodSweeper::notify(); |
1262 } |
1266 } |
1263 |
1267 |
1264 void nmethod::invalidate_osr_method() { |
1268 void nmethod::invalidate_osr_method() { |
1265 assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); |
1269 assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); |
1266 // Remove from list of active nmethods |
1270 // Remove from list of active nmethods |
1346 // This nmethod may have already been unloaded during a full GC. |
1350 // This nmethod may have already been unloaded during a full GC. |
1347 if ((state == zombie) && !is_unloaded()) { |
1351 if ((state == zombie) && !is_unloaded()) { |
1348 nmethod_needs_unregister = true; |
1352 nmethod_needs_unregister = true; |
1349 } |
1353 } |
1350 |
1354 |
|
1355 // Must happen before state change. Otherwise we have a race condition in |
|
1356 // nmethod::can_not_entrant_be_converted(). I.e., a method can immediately |
|
1357 // transition its state from 'not_entrant' to 'zombie' without having to wait |
|
1358 // for stack scanning. |
|
1359 if (state == not_entrant) { |
|
1360 mark_as_seen_on_stack(); |
|
1361 OrderAccess::storestore(); |
|
1362 } |
|
1363 |
1351 // Change state |
1364 // Change state |
1352 _state = state; |
1365 _state = state; |
1353 |
1366 |
1354 // Log the transition once |
1367 // Log the transition once |
1355 log_state_change(); |
1368 log_state_change(); |
1364 if (method() != NULL && (method()->code() == this || |
1377 if (method() != NULL && (method()->code() == this || |
1365 method()->from_compiled_entry() == verified_entry_point())) { |
1378 method()->from_compiled_entry() == verified_entry_point())) { |
1366 HandleMark hm; |
1379 HandleMark hm; |
1367 method()->clear_code(); |
1380 method()->clear_code(); |
1368 } |
1381 } |
1369 |
|
1370 if (state == not_entrant) { |
|
1371 mark_as_seen_on_stack(); |
|
1372 } |
|
1373 |
|
1374 } // leave critical region under Patching_lock |
1382 } // leave critical region under Patching_lock |
1375 |
1383 |
1376 // When the nmethod becomes zombie it is no longer alive so the |
1384 // When the nmethod becomes zombie it is no longer alive so the |
1377 // dependencies must be flushed. nmethods in the not_entrant |
1385 // dependencies must be flushed. nmethods in the not_entrant |
1378 // state will be flushed later when the transition to zombie |
1386 // state will be flushed later when the transition to zombie |
1399 #ifdef ASSERT |
1407 #ifdef ASSERT |
1400 // It's no longer safe to access the oops section since zombie |
1408 // It's no longer safe to access the oops section since zombie |
1401 // nmethods aren't scanned for GC. |
1409 // nmethods aren't scanned for GC. |
1402 _oops_are_stale = true; |
1410 _oops_are_stale = true; |
1403 #endif |
1411 #endif |
|
1412 // the Method may be reclaimed by class unloading now that the |
|
1413 // nmethod is in zombie state |
|
1414 set_method(NULL); |
1404 } else { |
1415 } else { |
1405 assert(state == not_entrant, "other cases may need to be handled differently"); |
1416 assert(state == not_entrant, "other cases may need to be handled differently"); |
1406 } |
1417 } |
1407 |
1418 |
1408 if (TraceCreateZombies) { |
1419 if (TraceCreateZombies) { |
1409 tty->print_cr("nmethod <" INTPTR_FORMAT "> code made %s", this, (state == not_entrant) ? "not entrant" : "zombie"); |
1420 tty->print_cr("nmethod <" INTPTR_FORMAT "> code made %s", this, (state == not_entrant) ? "not entrant" : "zombie"); |
1410 } |
1421 } |
1411 |
1422 |
1412 // Make sweeper aware that there is a zombie method that needs to be removed |
1423 // Make sweeper aware that there is a zombie method that needs to be removed |
1413 NMethodSweeper::notify(this); |
1424 NMethodSweeper::notify(); |
1414 |
1425 |
1415 return true; |
1426 return true; |
1416 } |
1427 } |
1417 |
1428 |
1418 void nmethod::flush() { |
1429 void nmethod::flush() { |
1957 void maybe_print(oop* p) { |
1964 void maybe_print(oop* p) { |
1958 if (_print_nm == NULL) return; |
1965 if (_print_nm == NULL) return; |
1959 if (!_detected_scavenge_root) _print_nm->print_on(tty, "new scavenge root"); |
1966 if (!_detected_scavenge_root) _print_nm->print_on(tty, "new scavenge root"); |
1960 tty->print_cr(""PTR_FORMAT"[offset=%d] detected scavengable oop "PTR_FORMAT" (found at "PTR_FORMAT")", |
1967 tty->print_cr(""PTR_FORMAT"[offset=%d] detected scavengable oop "PTR_FORMAT" (found at "PTR_FORMAT")", |
1961 _print_nm, (int)((intptr_t)p - (intptr_t)_print_nm), |
1968 _print_nm, (int)((intptr_t)p - (intptr_t)_print_nm), |
1962 (intptr_t)(*p), (intptr_t)p); |
1969 (void *)(*p), (intptr_t)p); |
1963 (*p)->print(); |
1970 (*p)->print(); |
1964 } |
1971 } |
1965 #endif //PRODUCT |
1972 #endif //PRODUCT |
1966 }; |
1973 }; |
1967 |
1974 |
2337 if (_ok) { |
2344 if (_ok) { |
2338 _nm->print_nmethod(true); |
2345 _nm->print_nmethod(true); |
2339 _ok = false; |
2346 _ok = false; |
2340 } |
2347 } |
2341 tty->print_cr("*** non-oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)", |
2348 tty->print_cr("*** non-oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)", |
2342 (intptr_t)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm)); |
2349 (void *)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm)); |
2343 } |
2350 } |
2344 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
2351 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
2345 }; |
2352 }; |
2346 |
2353 |
2347 void nmethod::verify() { |
2354 void nmethod::verify() { |
2458 if (_ok) { |
2465 if (_ok) { |
2459 _nm->print_nmethod(true); |
2466 _nm->print_nmethod(true); |
2460 _ok = false; |
2467 _ok = false; |
2461 } |
2468 } |
2462 tty->print_cr("*** scavengable oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)", |
2469 tty->print_cr("*** scavengable oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)", |
2463 (intptr_t)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm)); |
2470 (void *)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm)); |
2464 (*p)->print(); |
2471 (*p)->print(); |
2465 } |
2472 } |
2466 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
2473 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
2467 }; |
2474 }; |
2468 |
2475 |