Sat, 01 Sep 2012 13:25:18 -0400
6964458: Reimplement class meta-data storage to use native memory
Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
duke@435 | 1 | /* |
coleenp@4037 | 2 | * Copyright (c) 2005, 2012, 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/systemDictionary.hpp" |
stefank@2314 | 27 | #include "code/codeCache.hpp" |
stefank@2314 | 28 | #include "gc_implementation/parallelScavenge/pcTasks.hpp" |
stefank@2314 | 29 | #include "gc_implementation/parallelScavenge/psParallelCompact.hpp" |
stefank@2314 | 30 | #include "gc_interface/collectedHeap.hpp" |
stefank@2314 | 31 | #include "memory/universe.hpp" |
stefank@2314 | 32 | #include "oops/objArrayKlass.inline.hpp" |
stefank@2314 | 33 | #include "oops/oop.inline.hpp" |
stefank@2314 | 34 | #include "oops/oop.pcgc.inline.hpp" |
stefank@2314 | 35 | #include "prims/jvmtiExport.hpp" |
stefank@2314 | 36 | #include "runtime/fprofiler.hpp" |
stefank@2314 | 37 | #include "runtime/jniHandles.hpp" |
stefank@2314 | 38 | #include "runtime/thread.hpp" |
stefank@2314 | 39 | #include "runtime/vmThread.hpp" |
stefank@2314 | 40 | #include "services/management.hpp" |
duke@435 | 41 | |
duke@435 | 42 | // |
duke@435 | 43 | // ThreadRootsMarkingTask |
duke@435 | 44 | // |
duke@435 | 45 | |
duke@435 | 46 | void ThreadRootsMarkingTask::do_it(GCTaskManager* manager, uint which) { |
duke@435 | 47 | assert(Universe::heap()->is_gc_active(), "called outside gc"); |
duke@435 | 48 | |
duke@435 | 49 | ResourceMark rm; |
duke@435 | 50 | |
duke@435 | 51 | NOT_PRODUCT(TraceTime tm("ThreadRootsMarkingTask", |
duke@435 | 52 | PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty)); |
duke@435 | 53 | ParCompactionManager* cm = |
duke@435 | 54 | ParCompactionManager::gc_thread_compaction_manager(which); |
duke@435 | 55 | PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm); |
jrose@1424 | 56 | CodeBlobToOopClosure mark_and_push_in_blobs(&mark_and_push_closure, /*do_marking=*/ true); |
duke@435 | 57 | |
duke@435 | 58 | if (_java_thread != NULL) |
jrose@1424 | 59 | _java_thread->oops_do(&mark_and_push_closure, &mark_and_push_in_blobs); |
duke@435 | 60 | |
duke@435 | 61 | if (_vm_thread != NULL) |
jrose@1424 | 62 | _vm_thread->oops_do(&mark_and_push_closure, &mark_and_push_in_blobs); |
duke@435 | 63 | |
duke@435 | 64 | // Do the real work |
jcoomes@1746 | 65 | cm->follow_marking_stacks(); |
duke@435 | 66 | } |
duke@435 | 67 | |
duke@435 | 68 | |
duke@435 | 69 | void MarkFromRootsTask::do_it(GCTaskManager* manager, uint which) { |
duke@435 | 70 | assert(Universe::heap()->is_gc_active(), "called outside gc"); |
duke@435 | 71 | |
duke@435 | 72 | NOT_PRODUCT(TraceTime tm("MarkFromRootsTask", |
duke@435 | 73 | PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty)); |
duke@435 | 74 | ParCompactionManager* cm = |
duke@435 | 75 | ParCompactionManager::gc_thread_compaction_manager(which); |
duke@435 | 76 | PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm); |
coleenp@4037 | 77 | PSParallelCompact::FollowKlassClosure follow_klass_closure(&mark_and_push_closure); |
duke@435 | 78 | |
duke@435 | 79 | switch (_root_type) { |
duke@435 | 80 | case universe: |
duke@435 | 81 | Universe::oops_do(&mark_and_push_closure); |
duke@435 | 82 | break; |
duke@435 | 83 | |
duke@435 | 84 | case jni_handles: |
duke@435 | 85 | JNIHandles::oops_do(&mark_and_push_closure); |
duke@435 | 86 | break; |
duke@435 | 87 | |
duke@435 | 88 | case threads: |
duke@435 | 89 | { |
duke@435 | 90 | ResourceMark rm; |
jrose@1424 | 91 | CodeBlobToOopClosure each_active_code_blob(&mark_and_push_closure, /*do_marking=*/ true); |
jrose@1424 | 92 | Threads::oops_do(&mark_and_push_closure, &each_active_code_blob); |
duke@435 | 93 | } |
duke@435 | 94 | break; |
duke@435 | 95 | |
duke@435 | 96 | case object_synchronizer: |
duke@435 | 97 | ObjectSynchronizer::oops_do(&mark_and_push_closure); |
duke@435 | 98 | break; |
duke@435 | 99 | |
duke@435 | 100 | case flat_profiler: |
duke@435 | 101 | FlatProfiler::oops_do(&mark_and_push_closure); |
duke@435 | 102 | break; |
duke@435 | 103 | |
duke@435 | 104 | case management: |
duke@435 | 105 | Management::oops_do(&mark_and_push_closure); |
duke@435 | 106 | break; |
duke@435 | 107 | |
duke@435 | 108 | case jvmti: |
duke@435 | 109 | JvmtiExport::oops_do(&mark_and_push_closure); |
duke@435 | 110 | break; |
duke@435 | 111 | |
duke@435 | 112 | case system_dictionary: |
duke@435 | 113 | SystemDictionary::always_strong_oops_do(&mark_and_push_closure); |
coleenp@4037 | 114 | ClassLoaderDataGraph::always_strong_oops_do(&mark_and_push_closure, &follow_klass_closure, true); |
duke@435 | 115 | break; |
duke@435 | 116 | |
jrose@1424 | 117 | case code_cache: |
jrose@1424 | 118 | // Do not treat nmethods as strong roots for mark/sweep, since we can unload them. |
jrose@1424 | 119 | //CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure(&mark_and_push_closure)); |
jrose@1424 | 120 | break; |
jrose@1424 | 121 | |
duke@435 | 122 | default: |
duke@435 | 123 | fatal("Unknown root type"); |
duke@435 | 124 | } |
duke@435 | 125 | |
duke@435 | 126 | // Do the real work |
jcoomes@1746 | 127 | cm->follow_marking_stacks(); |
duke@435 | 128 | } |
duke@435 | 129 | |
duke@435 | 130 | |
duke@435 | 131 | // |
duke@435 | 132 | // RefProcTaskProxy |
duke@435 | 133 | // |
duke@435 | 134 | |
duke@435 | 135 | void RefProcTaskProxy::do_it(GCTaskManager* manager, uint which) |
duke@435 | 136 | { |
duke@435 | 137 | assert(Universe::heap()->is_gc_active(), "called outside gc"); |
duke@435 | 138 | |
duke@435 | 139 | NOT_PRODUCT(TraceTime tm("RefProcTask", |
duke@435 | 140 | PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty)); |
duke@435 | 141 | ParCompactionManager* cm = |
duke@435 | 142 | ParCompactionManager::gc_thread_compaction_manager(which); |
duke@435 | 143 | PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm); |
duke@435 | 144 | PSParallelCompact::FollowStackClosure follow_stack_closure(cm); |
duke@435 | 145 | _rp_task.work(_work_id, *PSParallelCompact::is_alive_closure(), |
duke@435 | 146 | mark_and_push_closure, follow_stack_closure); |
duke@435 | 147 | } |
duke@435 | 148 | |
duke@435 | 149 | // |
duke@435 | 150 | // RefProcTaskExecutor |
duke@435 | 151 | // |
duke@435 | 152 | |
duke@435 | 153 | void RefProcTaskExecutor::execute(ProcessTask& task) |
duke@435 | 154 | { |
duke@435 | 155 | ParallelScavengeHeap* heap = PSParallelCompact::gc_heap(); |
duke@435 | 156 | uint parallel_gc_threads = heap->gc_task_manager()->workers(); |
jmasa@3294 | 157 | uint active_gc_threads = heap->gc_task_manager()->active_workers(); |
jcoomes@810 | 158 | RegionTaskQueueSet* qset = ParCompactionManager::region_array(); |
jmasa@3294 | 159 | ParallelTaskTerminator terminator(active_gc_threads, qset); |
duke@435 | 160 | GCTaskQueue* q = GCTaskQueue::create(); |
duke@435 | 161 | for(uint i=0; i<parallel_gc_threads; i++) { |
duke@435 | 162 | q->enqueue(new RefProcTaskProxy(task, i)); |
duke@435 | 163 | } |
duke@435 | 164 | if (task.marks_oops_alive()) { |
duke@435 | 165 | if (parallel_gc_threads>1) { |
jmasa@3294 | 166 | for (uint j=0; j<active_gc_threads; j++) { |
duke@435 | 167 | q->enqueue(new StealMarkingTask(&terminator)); |
duke@435 | 168 | } |
duke@435 | 169 | } |
duke@435 | 170 | } |
duke@435 | 171 | PSParallelCompact::gc_task_manager()->execute_and_wait(q); |
duke@435 | 172 | } |
duke@435 | 173 | |
duke@435 | 174 | void RefProcTaskExecutor::execute(EnqueueTask& task) |
duke@435 | 175 | { |
duke@435 | 176 | ParallelScavengeHeap* heap = PSParallelCompact::gc_heap(); |
duke@435 | 177 | uint parallel_gc_threads = heap->gc_task_manager()->workers(); |
duke@435 | 178 | GCTaskQueue* q = GCTaskQueue::create(); |
duke@435 | 179 | for(uint i=0; i<parallel_gc_threads; i++) { |
duke@435 | 180 | q->enqueue(new RefEnqueueTaskProxy(task, i)); |
duke@435 | 181 | } |
duke@435 | 182 | PSParallelCompact::gc_task_manager()->execute_and_wait(q); |
duke@435 | 183 | } |
duke@435 | 184 | |
duke@435 | 185 | // |
duke@435 | 186 | // StealMarkingTask |
duke@435 | 187 | // |
duke@435 | 188 | |
duke@435 | 189 | StealMarkingTask::StealMarkingTask(ParallelTaskTerminator* t) : |
duke@435 | 190 | _terminator(t) {} |
duke@435 | 191 | |
duke@435 | 192 | void StealMarkingTask::do_it(GCTaskManager* manager, uint which) { |
duke@435 | 193 | assert(Universe::heap()->is_gc_active(), "called outside gc"); |
duke@435 | 194 | |
duke@435 | 195 | NOT_PRODUCT(TraceTime tm("StealMarkingTask", |
duke@435 | 196 | PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty)); |
duke@435 | 197 | |
duke@435 | 198 | ParCompactionManager* cm = |
duke@435 | 199 | ParCompactionManager::gc_thread_compaction_manager(which); |
duke@435 | 200 | PSParallelCompact::MarkAndPushClosure mark_and_push_closure(cm); |
duke@435 | 201 | |
duke@435 | 202 | oop obj = NULL; |
jcoomes@1746 | 203 | ObjArrayTask task; |
duke@435 | 204 | int random_seed = 17; |
jcoomes@1746 | 205 | do { |
jcoomes@1746 | 206 | while (ParCompactionManager::steal_objarray(which, &random_seed, task)) { |
coleenp@4037 | 207 | objArrayKlass* const k = (objArrayKlass*)task.obj()->klass(); |
jcoomes@1746 | 208 | k->oop_follow_contents(cm, task.obj(), task.index()); |
jcoomes@1746 | 209 | cm->follow_marking_stacks(); |
jcoomes@1746 | 210 | } |
jcoomes@1746 | 211 | while (ParCompactionManager::steal(which, &random_seed, obj)) { |
duke@435 | 212 | obj->follow_contents(cm); |
jcoomes@1746 | 213 | cm->follow_marking_stacks(); |
duke@435 | 214 | } |
jcoomes@1746 | 215 | } while (!terminator()->offer_termination()); |
duke@435 | 216 | } |
duke@435 | 217 | |
duke@435 | 218 | // |
jcoomes@810 | 219 | // StealRegionCompactionTask |
duke@435 | 220 | // |
duke@435 | 221 | |
jcoomes@810 | 222 | StealRegionCompactionTask::StealRegionCompactionTask(ParallelTaskTerminator* t): |
jcoomes@810 | 223 | _terminator(t) {} |
duke@435 | 224 | |
jcoomes@810 | 225 | void StealRegionCompactionTask::do_it(GCTaskManager* manager, uint which) { |
duke@435 | 226 | assert(Universe::heap()->is_gc_active(), "called outside gc"); |
duke@435 | 227 | |
jcoomes@810 | 228 | NOT_PRODUCT(TraceTime tm("StealRegionCompactionTask", |
duke@435 | 229 | PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty)); |
duke@435 | 230 | |
duke@435 | 231 | ParCompactionManager* cm = |
duke@435 | 232 | ParCompactionManager::gc_thread_compaction_manager(which); |
duke@435 | 233 | |
jmasa@3294 | 234 | |
jmasa@3294 | 235 | // If not all threads are active, get a draining stack |
jmasa@3294 | 236 | // from the list. Else, just use this threads draining stack. |
jmasa@3294 | 237 | uint which_stack_index; |
jmasa@3294 | 238 | bool use_all_workers = manager->all_workers_active(); |
jmasa@3294 | 239 | if (use_all_workers) { |
jmasa@3294 | 240 | which_stack_index = which; |
jmasa@3294 | 241 | assert(manager->active_workers() == ParallelGCThreads, |
jmasa@3294 | 242 | err_msg("all_workers_active has been incorrectly set: " |
jmasa@3294 | 243 | " active %d ParallelGCThreads %d", manager->active_workers(), |
jmasa@3294 | 244 | ParallelGCThreads)); |
jmasa@3294 | 245 | } else { |
jmasa@3294 | 246 | which_stack_index = ParCompactionManager::pop_recycled_stack_index(); |
jmasa@3294 | 247 | } |
jmasa@3294 | 248 | |
jmasa@3294 | 249 | cm->set_region_stack_index(which_stack_index); |
jmasa@3294 | 250 | cm->set_region_stack(ParCompactionManager::region_list(which_stack_index)); |
jmasa@3294 | 251 | if (TraceDynamicGCThreads) { |
jmasa@3294 | 252 | gclog_or_tty->print_cr("StealRegionCompactionTask::do_it " |
jmasa@3294 | 253 | "region_stack_index %d region_stack = 0x%x " |
jmasa@3294 | 254 | " empty (%d) use all workers %d", |
jmasa@3294 | 255 | which_stack_index, ParCompactionManager::region_list(which_stack_index), |
jmasa@3294 | 256 | cm->region_stack()->is_empty(), |
jmasa@3294 | 257 | use_all_workers); |
jmasa@3294 | 258 | } |
jmasa@3294 | 259 | |
jcoomes@810 | 260 | // Has to drain stacks first because there may be regions on |
duke@435 | 261 | // preloaded onto the stack and this thread may never have |
duke@435 | 262 | // done a draining task. Are the draining tasks needed? |
duke@435 | 263 | |
jcoomes@810 | 264 | cm->drain_region_stacks(); |
duke@435 | 265 | |
jcoomes@810 | 266 | size_t region_index = 0; |
duke@435 | 267 | int random_seed = 17; |
duke@435 | 268 | |
duke@435 | 269 | // If we're the termination task, try 10 rounds of stealing before |
duke@435 | 270 | // setting the termination flag |
duke@435 | 271 | |
duke@435 | 272 | while(true) { |
jcoomes@810 | 273 | if (ParCompactionManager::steal(which, &random_seed, region_index)) { |
jcoomes@810 | 274 | PSParallelCompact::fill_and_update_region(cm, region_index); |
jcoomes@810 | 275 | cm->drain_region_stacks(); |
duke@435 | 276 | } else { |
duke@435 | 277 | if (terminator()->offer_termination()) { |
duke@435 | 278 | break; |
duke@435 | 279 | } |
duke@435 | 280 | // Go around again. |
duke@435 | 281 | } |
duke@435 | 282 | } |
duke@435 | 283 | return; |
duke@435 | 284 | } |
duke@435 | 285 | |
duke@435 | 286 | UpdateDensePrefixTask::UpdateDensePrefixTask( |
duke@435 | 287 | PSParallelCompact::SpaceId space_id, |
jcoomes@810 | 288 | size_t region_index_start, |
jcoomes@810 | 289 | size_t region_index_end) : |
jcoomes@810 | 290 | _space_id(space_id), _region_index_start(region_index_start), |
jcoomes@810 | 291 | _region_index_end(region_index_end) {} |
duke@435 | 292 | |
duke@435 | 293 | void UpdateDensePrefixTask::do_it(GCTaskManager* manager, uint which) { |
duke@435 | 294 | |
duke@435 | 295 | NOT_PRODUCT(TraceTime tm("UpdateDensePrefixTask", |
duke@435 | 296 | PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty)); |
duke@435 | 297 | |
duke@435 | 298 | ParCompactionManager* cm = |
duke@435 | 299 | ParCompactionManager::gc_thread_compaction_manager(which); |
duke@435 | 300 | |
duke@435 | 301 | PSParallelCompact::update_and_deadwood_in_dense_prefix(cm, |
duke@435 | 302 | _space_id, |
jcoomes@810 | 303 | _region_index_start, |
jcoomes@810 | 304 | _region_index_end); |
duke@435 | 305 | } |
duke@435 | 306 | |
duke@435 | 307 | void DrainStacksCompactionTask::do_it(GCTaskManager* manager, uint which) { |
duke@435 | 308 | assert(Universe::heap()->is_gc_active(), "called outside gc"); |
duke@435 | 309 | |
duke@435 | 310 | NOT_PRODUCT(TraceTime tm("DrainStacksCompactionTask", |
duke@435 | 311 | PrintGCDetails && TraceParallelOldGCTasks, true, gclog_or_tty)); |
duke@435 | 312 | |
duke@435 | 313 | ParCompactionManager* cm = |
duke@435 | 314 | ParCompactionManager::gc_thread_compaction_manager(which); |
duke@435 | 315 | |
jmasa@3294 | 316 | uint which_stack_index; |
jmasa@3294 | 317 | bool use_all_workers = manager->all_workers_active(); |
jmasa@3294 | 318 | if (use_all_workers) { |
jmasa@3294 | 319 | which_stack_index = which; |
jmasa@3294 | 320 | assert(manager->active_workers() == ParallelGCThreads, |
jmasa@3294 | 321 | err_msg("all_workers_active has been incorrectly set: " |
jmasa@3294 | 322 | " active %d ParallelGCThreads %d", manager->active_workers(), |
jmasa@3294 | 323 | ParallelGCThreads)); |
jmasa@3294 | 324 | } else { |
jmasa@3294 | 325 | which_stack_index = stack_index(); |
jmasa@3294 | 326 | } |
jmasa@3294 | 327 | |
jmasa@3294 | 328 | cm->set_region_stack(ParCompactionManager::region_list(which_stack_index)); |
jmasa@3294 | 329 | if (TraceDynamicGCThreads) { |
jmasa@3294 | 330 | gclog_or_tty->print_cr("DrainStacksCompactionTask::do_it which = %d " |
jmasa@3294 | 331 | "which_stack_index = %d/empty(%d) " |
jmasa@3294 | 332 | "use all workers %d", |
jmasa@3294 | 333 | which, which_stack_index, |
jmasa@3294 | 334 | cm->region_stack()->is_empty(), |
jmasa@3294 | 335 | use_all_workers); |
jmasa@3294 | 336 | } |
jmasa@3294 | 337 | |
jmasa@3294 | 338 | cm->set_region_stack_index(which_stack_index); |
jmasa@3294 | 339 | |
jcoomes@810 | 340 | // Process any regions already in the compaction managers stacks. |
jcoomes@810 | 341 | cm->drain_region_stacks(); |
jmasa@3294 | 342 | |
jmasa@3294 | 343 | assert(cm->region_stack()->is_empty(), "Not empty"); |
jmasa@3294 | 344 | |
jmasa@3294 | 345 | if (!use_all_workers) { |
jmasa@3294 | 346 | // Always give up the region stack. |
jmasa@3294 | 347 | assert(cm->region_stack() == |
jmasa@3294 | 348 | ParCompactionManager::region_list(cm->region_stack_index()), |
jmasa@3294 | 349 | "region_stack and region_stack_index are inconsistent"); |
jmasa@3294 | 350 | ParCompactionManager::push_recycled_stack_index(cm->region_stack_index()); |
jmasa@3294 | 351 | |
jmasa@3294 | 352 | if (TraceDynamicGCThreads) { |
jmasa@3294 | 353 | void* old_region_stack = (void*) cm->region_stack(); |
jmasa@3294 | 354 | int old_region_stack_index = cm->region_stack_index(); |
jmasa@3294 | 355 | gclog_or_tty->print_cr("Pushing region stack 0x%x/%d", |
jmasa@3294 | 356 | old_region_stack, old_region_stack_index); |
jmasa@3294 | 357 | } |
jmasa@3294 | 358 | |
jmasa@3294 | 359 | cm->set_region_stack(NULL); |
jmasa@3294 | 360 | cm->set_region_stack_index((uint)max_uintx); |
jmasa@3294 | 361 | } |
duke@435 | 362 | } |