Fri, 15 Apr 2011 09:36:28 -0400
7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
Summary: Make CDS reorder vtables so that dump time vtables match run time order, so when redefine classes reinitializes them, they aren't in the wrong order.
Reviewed-by: dcubed, acorn
duke@435 | 1 | /* |
trims@2708 | 2 | * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/symbolTable.hpp" |
stefank@2314 | 27 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 28 | #include "code/codeCache.hpp" |
stefank@2314 | 29 | #include "gc_interface/collectedHeap.inline.hpp" |
stefank@2314 | 30 | #include "memory/sharedHeap.hpp" |
stefank@2314 | 31 | #include "oops/oop.inline.hpp" |
stefank@2314 | 32 | #include "runtime/fprofiler.hpp" |
stefank@2314 | 33 | #include "runtime/java.hpp" |
stefank@2314 | 34 | #include "services/management.hpp" |
stefank@2314 | 35 | #include "utilities/copy.hpp" |
stefank@2314 | 36 | #include "utilities/workgroup.hpp" |
duke@435 | 37 | |
duke@435 | 38 | SharedHeap* SharedHeap::_sh; |
duke@435 | 39 | |
duke@435 | 40 | // The set of potentially parallel tasks in strong root scanning. |
duke@435 | 41 | enum SH_process_strong_roots_tasks { |
duke@435 | 42 | SH_PS_Universe_oops_do, |
duke@435 | 43 | SH_PS_JNIHandles_oops_do, |
duke@435 | 44 | SH_PS_ObjectSynchronizer_oops_do, |
duke@435 | 45 | SH_PS_FlatProfiler_oops_do, |
duke@435 | 46 | SH_PS_Management_oops_do, |
duke@435 | 47 | SH_PS_SystemDictionary_oops_do, |
duke@435 | 48 | SH_PS_jvmti_oops_do, |
duke@435 | 49 | SH_PS_SymbolTable_oops_do, |
duke@435 | 50 | SH_PS_StringTable_oops_do, |
duke@435 | 51 | SH_PS_CodeCache_oops_do, |
duke@435 | 52 | // Leave this one last. |
duke@435 | 53 | SH_PS_NumElements |
duke@435 | 54 | }; |
duke@435 | 55 | |
duke@435 | 56 | SharedHeap::SharedHeap(CollectorPolicy* policy_) : |
duke@435 | 57 | CollectedHeap(), |
duke@435 | 58 | _collector_policy(policy_), |
duke@435 | 59 | _perm_gen(NULL), _rem_set(NULL), |
duke@435 | 60 | _strong_roots_parity(0), |
duke@435 | 61 | _process_strong_tasks(new SubTasksDone(SH_PS_NumElements)), |
jmasa@2188 | 62 | _n_par_threads(0), |
jmasa@2188 | 63 | _workers(NULL) |
duke@435 | 64 | { |
duke@435 | 65 | if (_process_strong_tasks == NULL || !_process_strong_tasks->valid()) { |
duke@435 | 66 | vm_exit_during_initialization("Failed necessary allocation."); |
duke@435 | 67 | } |
duke@435 | 68 | _sh = this; // ch is static, should be set only once. |
duke@435 | 69 | if ((UseParNewGC || |
ysr@777 | 70 | (UseConcMarkSweepGC && CMSParallelRemarkEnabled) || |
ysr@777 | 71 | UseG1GC) && |
duke@435 | 72 | ParallelGCThreads > 0) { |
jmasa@2188 | 73 | _workers = new FlexibleWorkGang("Parallel GC Threads", ParallelGCThreads, |
ysr@777 | 74 | /* are_GC_task_threads */true, |
ysr@777 | 75 | /* are_ConcurrentGC_threads */false); |
duke@435 | 76 | if (_workers == NULL) { |
duke@435 | 77 | vm_exit_during_initialization("Failed necessary allocation."); |
jmasa@2188 | 78 | } else { |
jmasa@2188 | 79 | _workers->initialize_workers(); |
duke@435 | 80 | } |
duke@435 | 81 | } |
duke@435 | 82 | } |
duke@435 | 83 | |
ysr@777 | 84 | bool SharedHeap::heap_lock_held_for_gc() { |
ysr@777 | 85 | Thread* t = Thread::current(); |
ysr@777 | 86 | return Heap_lock->owned_by_self() |
ysr@777 | 87 | || ( (t->is_GC_task_thread() || t->is_VM_thread()) |
ysr@777 | 88 | && _thread_holds_heap_lock_for_gc); |
ysr@777 | 89 | } |
duke@435 | 90 | |
duke@435 | 91 | void SharedHeap::set_par_threads(int t) { |
jmasa@2188 | 92 | assert(t == 0 || !UseSerialGC, "Cannot have parallel threads"); |
duke@435 | 93 | _n_par_threads = t; |
jmasa@2188 | 94 | _process_strong_tasks->set_n_threads(t); |
duke@435 | 95 | } |
duke@435 | 96 | |
duke@435 | 97 | class AssertIsPermClosure: public OopClosure { |
duke@435 | 98 | public: |
coleenp@548 | 99 | virtual void do_oop(oop* p) { |
duke@435 | 100 | assert((*p) == NULL || (*p)->is_perm(), "Referent should be perm."); |
duke@435 | 101 | } |
coleenp@548 | 102 | virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
duke@435 | 103 | }; |
duke@435 | 104 | static AssertIsPermClosure assert_is_perm_closure; |
duke@435 | 105 | |
duke@435 | 106 | void SharedHeap::change_strong_roots_parity() { |
duke@435 | 107 | // Also set the new collection parity. |
duke@435 | 108 | assert(_strong_roots_parity >= 0 && _strong_roots_parity <= 2, |
duke@435 | 109 | "Not in range."); |
duke@435 | 110 | _strong_roots_parity++; |
duke@435 | 111 | if (_strong_roots_parity == 3) _strong_roots_parity = 1; |
duke@435 | 112 | assert(_strong_roots_parity >= 1 && _strong_roots_parity <= 2, |
duke@435 | 113 | "Not in range."); |
duke@435 | 114 | } |
duke@435 | 115 | |
jrose@1424 | 116 | SharedHeap::StrongRootsScope::StrongRootsScope(SharedHeap* outer, bool activate) |
jrose@1424 | 117 | : MarkScope(activate) |
jrose@1424 | 118 | { |
jrose@1424 | 119 | if (_active) { |
jrose@1424 | 120 | outer->change_strong_roots_parity(); |
jrose@1424 | 121 | } |
jrose@1424 | 122 | } |
jrose@1424 | 123 | |
jrose@1424 | 124 | SharedHeap::StrongRootsScope::~StrongRootsScope() { |
jrose@1424 | 125 | // nothing particular |
jrose@1424 | 126 | } |
jrose@1424 | 127 | |
jrose@1424 | 128 | void SharedHeap::process_strong_roots(bool activate_scope, |
jrose@1424 | 129 | bool collecting_perm_gen, |
duke@435 | 130 | ScanningOption so, |
duke@435 | 131 | OopClosure* roots, |
jrose@1424 | 132 | CodeBlobClosure* code_roots, |
duke@435 | 133 | OopsInGenClosure* perm_blk) { |
jrose@1424 | 134 | StrongRootsScope srs(this, activate_scope); |
duke@435 | 135 | // General strong roots. |
jrose@1424 | 136 | assert(_strong_roots_parity != 0, "must have called prologue code"); |
duke@435 | 137 | if (!_process_strong_tasks->is_task_claimed(SH_PS_Universe_oops_do)) { |
duke@435 | 138 | Universe::oops_do(roots); |
duke@435 | 139 | ReferenceProcessor::oops_do(roots); |
duke@435 | 140 | // Consider perm-gen discovered lists to be strong. |
duke@435 | 141 | perm_gen()->ref_processor()->weak_oops_do(roots); |
duke@435 | 142 | } |
duke@435 | 143 | // Global (strong) JNI handles |
duke@435 | 144 | if (!_process_strong_tasks->is_task_claimed(SH_PS_JNIHandles_oops_do)) |
duke@435 | 145 | JNIHandles::oops_do(roots); |
duke@435 | 146 | // All threads execute this; the individual threads are task groups. |
duke@435 | 147 | if (ParallelGCThreads > 0) { |
jrose@1424 | 148 | Threads::possibly_parallel_oops_do(roots, code_roots); |
duke@435 | 149 | } else { |
jrose@1424 | 150 | Threads::oops_do(roots, code_roots); |
duke@435 | 151 | } |
duke@435 | 152 | if (!_process_strong_tasks-> is_task_claimed(SH_PS_ObjectSynchronizer_oops_do)) |
duke@435 | 153 | ObjectSynchronizer::oops_do(roots); |
duke@435 | 154 | if (!_process_strong_tasks->is_task_claimed(SH_PS_FlatProfiler_oops_do)) |
duke@435 | 155 | FlatProfiler::oops_do(roots); |
duke@435 | 156 | if (!_process_strong_tasks->is_task_claimed(SH_PS_Management_oops_do)) |
duke@435 | 157 | Management::oops_do(roots); |
duke@435 | 158 | if (!_process_strong_tasks->is_task_claimed(SH_PS_jvmti_oops_do)) |
duke@435 | 159 | JvmtiExport::oops_do(roots); |
duke@435 | 160 | |
duke@435 | 161 | if (!_process_strong_tasks->is_task_claimed(SH_PS_SystemDictionary_oops_do)) { |
duke@435 | 162 | if (so & SO_AllClasses) { |
duke@435 | 163 | SystemDictionary::oops_do(roots); |
duke@435 | 164 | } else |
duke@435 | 165 | if (so & SO_SystemClasses) { |
duke@435 | 166 | SystemDictionary::always_strong_oops_do(roots); |
duke@435 | 167 | } |
duke@435 | 168 | } |
duke@435 | 169 | |
duke@435 | 170 | if (!_process_strong_tasks->is_task_claimed(SH_PS_SymbolTable_oops_do)) { |
duke@435 | 171 | } |
duke@435 | 172 | |
duke@435 | 173 | if (!_process_strong_tasks->is_task_claimed(SH_PS_StringTable_oops_do)) { |
jcoomes@2661 | 174 | if (so & SO_Strings || (!collecting_perm_gen && !JavaObjectsInPerm)) { |
jcoomes@2661 | 175 | StringTable::oops_do(roots); |
jcoomes@2661 | 176 | } |
jcoomes@2661 | 177 | if (JavaObjectsInPerm) { |
jcoomes@2661 | 178 | // Verify the string table contents are in the perm gen |
jcoomes@2661 | 179 | NOT_PRODUCT(StringTable::oops_do(&assert_is_perm_closure)); |
jcoomes@2661 | 180 | } |
duke@435 | 181 | } |
duke@435 | 182 | |
duke@435 | 183 | if (!_process_strong_tasks->is_task_claimed(SH_PS_CodeCache_oops_do)) { |
jrose@1424 | 184 | if (so & SO_CodeCache) { |
jrose@1424 | 185 | // (Currently, CMSCollector uses this to do intermediate-strength collections.) |
jrose@1424 | 186 | assert(collecting_perm_gen, "scanning all of code cache"); |
jrose@1424 | 187 | assert(code_roots != NULL, "must supply closure for code cache"); |
jrose@1424 | 188 | if (code_roots != NULL) { |
jrose@1424 | 189 | CodeCache::blobs_do(code_roots); |
jrose@1424 | 190 | } |
jrose@1424 | 191 | } else if (so & (SO_SystemClasses|SO_AllClasses)) { |
jrose@1424 | 192 | if (!collecting_perm_gen) { |
jrose@1424 | 193 | // If we are collecting from class statics, but we are not going to |
jrose@1424 | 194 | // visit all of the CodeCache, collect from the non-perm roots if any. |
jrose@1424 | 195 | // This makes the code cache function temporarily as a source of strong |
jrose@1424 | 196 | // roots for oops, until the next major collection. |
jrose@1424 | 197 | // |
jrose@1424 | 198 | // If collecting_perm_gen is true, we require that this phase will call |
jrose@1424 | 199 | // CodeCache::do_unloading. This will kill off nmethods with expired |
jrose@1424 | 200 | // weak references, such as stale invokedynamic targets. |
jrose@1424 | 201 | CodeCache::scavenge_root_nmethods_do(code_roots); |
jrose@1424 | 202 | } |
jrose@1424 | 203 | } |
duke@435 | 204 | // Verify if the code cache contents are in the perm gen |
jrose@1424 | 205 | NOT_PRODUCT(CodeBlobToOopClosure assert_code_is_perm(&assert_is_perm_closure, /*do_marking=*/ false)); |
jrose@1424 | 206 | NOT_PRODUCT(CodeCache::asserted_non_scavengable_nmethods_do(&assert_code_is_perm)); |
duke@435 | 207 | } |
duke@435 | 208 | |
duke@435 | 209 | if (!collecting_perm_gen) { |
duke@435 | 210 | // All threads perform this; coordination is handled internally. |
duke@435 | 211 | |
duke@435 | 212 | rem_set()->younger_refs_iterate(perm_gen(), perm_blk); |
duke@435 | 213 | } |
duke@435 | 214 | _process_strong_tasks->all_tasks_completed(); |
duke@435 | 215 | } |
duke@435 | 216 | |
duke@435 | 217 | class AlwaysTrueClosure: public BoolObjectClosure { |
duke@435 | 218 | public: |
duke@435 | 219 | void do_object(oop p) { ShouldNotReachHere(); } |
duke@435 | 220 | bool do_object_b(oop p) { return true; } |
duke@435 | 221 | }; |
duke@435 | 222 | static AlwaysTrueClosure always_true; |
duke@435 | 223 | |
duke@435 | 224 | class SkipAdjustingSharedStrings: public OopClosure { |
duke@435 | 225 | OopClosure* _clo; |
duke@435 | 226 | public: |
duke@435 | 227 | SkipAdjustingSharedStrings(OopClosure* clo) : _clo(clo) {} |
duke@435 | 228 | |
coleenp@548 | 229 | virtual void do_oop(oop* p) { |
duke@435 | 230 | oop o = (*p); |
duke@435 | 231 | if (!o->is_shared_readwrite()) { |
duke@435 | 232 | _clo->do_oop(p); |
duke@435 | 233 | } |
duke@435 | 234 | } |
coleenp@548 | 235 | virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } |
duke@435 | 236 | }; |
duke@435 | 237 | |
duke@435 | 238 | // Unmarked shared Strings in the StringTable (which got there due to |
duke@435 | 239 | // being in the constant pools of as-yet unloaded shared classes) were |
duke@435 | 240 | // not marked and therefore did not have their mark words preserved. |
duke@435 | 241 | // These entries are also deliberately not purged from the string |
duke@435 | 242 | // table during unloading of unmarked strings. If an identity hash |
duke@435 | 243 | // code was computed for any of these objects, it will not have been |
duke@435 | 244 | // cleared to zero during the forwarding process or by the |
duke@435 | 245 | // RecursiveAdjustSharedObjectClosure, and will be confused by the |
duke@435 | 246 | // adjusting process as a forwarding pointer. We need to skip |
duke@435 | 247 | // forwarding StringTable entries which contain unmarked shared |
duke@435 | 248 | // Strings. Actually, since shared strings won't be moving, we can |
duke@435 | 249 | // just skip adjusting any shared entries in the string table. |
duke@435 | 250 | |
duke@435 | 251 | void SharedHeap::process_weak_roots(OopClosure* root_closure, |
jrose@1424 | 252 | CodeBlobClosure* code_roots, |
duke@435 | 253 | OopClosure* non_root_closure) { |
duke@435 | 254 | // Global (weak) JNI handles |
duke@435 | 255 | JNIHandles::weak_oops_do(&always_true, root_closure); |
duke@435 | 256 | |
jrose@1424 | 257 | CodeCache::blobs_do(code_roots); |
duke@435 | 258 | if (UseSharedSpaces && !DumpSharedSpaces) { |
duke@435 | 259 | SkipAdjustingSharedStrings skip_closure(root_closure); |
duke@435 | 260 | StringTable::oops_do(&skip_closure); |
duke@435 | 261 | } else { |
duke@435 | 262 | StringTable::oops_do(root_closure); |
duke@435 | 263 | } |
duke@435 | 264 | } |
duke@435 | 265 | |
duke@435 | 266 | void SharedHeap::set_barrier_set(BarrierSet* bs) { |
duke@435 | 267 | _barrier_set = bs; |
duke@435 | 268 | // Cached barrier set for fast access in oops |
duke@435 | 269 | oopDesc::set_bs(bs); |
duke@435 | 270 | } |
duke@435 | 271 | |
duke@435 | 272 | void SharedHeap::post_initialize() { |
duke@435 | 273 | ref_processing_init(); |
duke@435 | 274 | } |
duke@435 | 275 | |
duke@435 | 276 | void SharedHeap::ref_processing_init() { |
duke@435 | 277 | perm_gen()->ref_processor_init(); |
duke@435 | 278 | } |
duke@435 | 279 | |
duke@435 | 280 | // Some utilities. |
ysr@777 | 281 | void SharedHeap::print_size_transition(outputStream* out, |
ysr@777 | 282 | size_t bytes_before, |
duke@435 | 283 | size_t bytes_after, |
duke@435 | 284 | size_t capacity) { |
ysr@777 | 285 | out->print(" %d%s->%d%s(%d%s)", |
duke@435 | 286 | byte_size_in_proper_unit(bytes_before), |
duke@435 | 287 | proper_unit_for_byte_size(bytes_before), |
duke@435 | 288 | byte_size_in_proper_unit(bytes_after), |
duke@435 | 289 | proper_unit_for_byte_size(bytes_after), |
duke@435 | 290 | byte_size_in_proper_unit(capacity), |
duke@435 | 291 | proper_unit_for_byte_size(capacity)); |
duke@435 | 292 | } |