1.1 --- a/src/share/vm/code/nmethod.cpp Wed Oct 16 10:52:41 2013 +0200 1.2 +++ b/src/share/vm/code/nmethod.cpp Tue Nov 05 17:38:04 2013 -0800 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -93,18 +93,21 @@ 1.11 #endif 1.12 1.13 bool nmethod::is_compiled_by_c1() const { 1.14 - if (compiler() == NULL || method() == NULL) return false; // can happen during debug printing 1.15 - if (is_native_method()) return false; 1.16 + if (compiler() == NULL) { 1.17 + return false; 1.18 + } 1.19 return compiler()->is_c1(); 1.20 } 1.21 bool nmethod::is_compiled_by_c2() const { 1.22 - if (compiler() == NULL || method() == NULL) return false; // can happen during debug printing 1.23 - if (is_native_method()) return false; 1.24 + if (compiler() == NULL) { 1.25 + return false; 1.26 + } 1.27 return compiler()->is_c2(); 1.28 } 1.29 bool nmethod::is_compiled_by_shark() const { 1.30 - if (is_native_method()) return false; 1.31 - assert(compiler() != NULL, "must be"); 1.32 + if (compiler() == NULL) { 1.33 + return false; 1.34 + } 1.35 return compiler()->is_shark(); 1.36 } 1.37 1.38 @@ -459,7 +462,6 @@ 1.39 _state = alive; 1.40 _marked_for_reclamation = 0; 1.41 _has_flushed_dependencies = 0; 1.42 - _speculatively_disconnected = 0; 1.43 _has_unsafe_access = 0; 1.44 _has_method_handle_invokes = 0; 1.45 _lazy_critical_native = 0; 1.46 @@ -478,7 +480,6 @@ 1.47 _osr_link = NULL; 1.48 _scavenge_root_link = NULL; 1.49 _scavenge_root_state = 0; 1.50 - _saved_nmethod_link = NULL; 1.51 _compiler = NULL; 1.52 1.53 #ifdef HAVE_DTRACE_H 1.54 @@ -683,6 +684,7 @@ 1.55 _osr_entry_point = NULL; 1.56 _exception_cache = NULL; 1.57 _pc_desc_cache.reset_to(NULL); 1.58 + _hotness_counter = NMethodSweeper::hotness_counter_reset_val(); 1.59 1.60 code_buffer->copy_values_to(this); 1.61 if (ScavengeRootsInCode && detect_scavenge_root_oops()) { 1.62 @@ -767,6 +769,7 @@ 1.63 _osr_entry_point = NULL; 1.64 _exception_cache = NULL; 1.65 _pc_desc_cache.reset_to(NULL); 1.66 + _hotness_counter = NMethodSweeper::hotness_counter_reset_val(); 1.67 1.68 code_buffer->copy_values_to(this); 1.69 debug_only(verify_scavenge_root_oops()); 1.70 @@ -800,7 +803,7 @@ 1.71 } 1.72 #endif // def HAVE_DTRACE_H 1.73 1.74 -void* nmethod::operator new(size_t size, int nmethod_size) { 1.75 +void* nmethod::operator new(size_t size, int nmethod_size) throw() { 1.76 // Not critical, may return null if there is too little continuous memory 1.77 return CodeCache::allocate(nmethod_size); 1.78 } 1.79 @@ -839,6 +842,7 @@ 1.80 _comp_level = comp_level; 1.81 _compiler = compiler; 1.82 _orig_pc_offset = orig_pc_offset; 1.83 + _hotness_counter = NMethodSweeper::hotness_counter_reset_val(); 1.84 1.85 // Section offsets 1.86 _consts_offset = content_offset() + code_buffer->total_offset_of(code_buffer->consts()); 1.87 @@ -1173,7 +1177,7 @@ 1.88 1.89 // This is a private interface with the sweeper. 1.90 void nmethod::mark_as_seen_on_stack() { 1.91 - assert(is_not_entrant(), "must be a non-entrant method"); 1.92 + assert(is_alive(), "Must be an alive method"); 1.93 // Set the traversal mark to ensure that the sweeper does 2 1.94 // cleaning passes before moving to zombie. 1.95 set_stack_traversal_mark(NMethodSweeper::traversal_count()); 1.96 @@ -1258,7 +1262,7 @@ 1.97 1.98 set_osr_link(NULL); 1.99 //set_scavenge_root_link(NULL); // done by prune_scavenge_root_nmethods 1.100 - NMethodSweeper::notify(this); 1.101 + NMethodSweeper::notify(); 1.102 } 1.103 1.104 void nmethod::invalidate_osr_method() { 1.105 @@ -1348,6 +1352,15 @@ 1.106 nmethod_needs_unregister = true; 1.107 } 1.108 1.109 + // Must happen before state change. Otherwise we have a race condition in 1.110 + // nmethod::can_not_entrant_be_converted(). I.e., a method can immediately 1.111 + // transition its state from 'not_entrant' to 'zombie' without having to wait 1.112 + // for stack scanning. 1.113 + if (state == not_entrant) { 1.114 + mark_as_seen_on_stack(); 1.115 + OrderAccess::storestore(); 1.116 + } 1.117 + 1.118 // Change state 1.119 _state = state; 1.120 1.121 @@ -1366,11 +1379,6 @@ 1.122 HandleMark hm; 1.123 method()->clear_code(); 1.124 } 1.125 - 1.126 - if (state == not_entrant) { 1.127 - mark_as_seen_on_stack(); 1.128 - } 1.129 - 1.130 } // leave critical region under Patching_lock 1.131 1.132 // When the nmethod becomes zombie it is no longer alive so the 1.133 @@ -1401,6 +1409,9 @@ 1.134 // nmethods aren't scanned for GC. 1.135 _oops_are_stale = true; 1.136 #endif 1.137 + // the Method may be reclaimed by class unloading now that the 1.138 + // nmethod is in zombie state 1.139 + set_method(NULL); 1.140 } else { 1.141 assert(state == not_entrant, "other cases may need to be handled differently"); 1.142 } 1.143 @@ -1410,7 +1421,7 @@ 1.144 } 1.145 1.146 // Make sweeper aware that there is a zombie method that needs to be removed 1.147 - NMethodSweeper::notify(this); 1.148 + NMethodSweeper::notify(); 1.149 1.150 return true; 1.151 } 1.152 @@ -1445,10 +1456,6 @@ 1.153 CodeCache::drop_scavenge_root_nmethod(this); 1.154 } 1.155 1.156 - if (is_speculatively_disconnected()) { 1.157 - CodeCache::remove_saved_code(this); 1.158 - } 1.159 - 1.160 #ifdef SHARK 1.161 ((SharkCompiler *) compiler())->free_compiled_method(insts_begin()); 1.162 #endif // SHARK 1.163 @@ -1959,7 +1966,7 @@ 1.164 if (!_detected_scavenge_root) _print_nm->print_on(tty, "new scavenge root"); 1.165 tty->print_cr(""PTR_FORMAT"[offset=%d] detected scavengable oop "PTR_FORMAT" (found at "PTR_FORMAT")", 1.166 _print_nm, (int)((intptr_t)p - (intptr_t)_print_nm), 1.167 - (intptr_t)(*p), (intptr_t)p); 1.168 + (void *)(*p), (intptr_t)p); 1.169 (*p)->print(); 1.170 } 1.171 #endif //PRODUCT 1.172 @@ -2339,7 +2346,7 @@ 1.173 _ok = false; 1.174 } 1.175 tty->print_cr("*** non-oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)", 1.176 - (intptr_t)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm)); 1.177 + (void *)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm)); 1.178 } 1.179 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } 1.180 }; 1.181 @@ -2460,7 +2467,7 @@ 1.182 _ok = false; 1.183 } 1.184 tty->print_cr("*** scavengable oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)", 1.185 - (intptr_t)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm)); 1.186 + (void *)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm)); 1.187 (*p)->print(); 1.188 } 1.189 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }