Fri, 22 Mar 2013 10:32:21 +0100
Merge
src/share/vm/memory/metaspace.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp Tue Mar 19 13:44:26 2013 +0100 1.2 +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp Fri Mar 22 10:32:21 2013 +0100 1.3 @@ -6068,6 +6068,10 @@ 1.4 verify_work_stacks_empty(); 1.5 verify_overflow_empty(); 1.6 1.7 + if (should_unload_classes()) { 1.8 + ClassLoaderDataGraph::purge(); 1.9 + } 1.10 + 1.11 _intra_sweep_timer.stop(); 1.12 _intra_sweep_estimate.sample(_intra_sweep_timer.seconds()); 1.13
2.1 --- a/src/share/vm/gc_implementation/g1/concurrentMark.cpp Tue Mar 19 13:44:26 2013 +0100 2.2 +++ b/src/share/vm/gc_implementation/g1/concurrentMark.cpp Fri Mar 22 10:32:21 2013 +0100 2.3 @@ -784,7 +784,7 @@ 2.4 } 2.5 } 2.6 2.7 -void ConcurrentMark::set_phase(uint active_tasks, bool concurrent) { 2.8 +void ConcurrentMark::set_concurrency(uint active_tasks) { 2.9 assert(active_tasks <= _max_worker_id, "we should not have more"); 2.10 2.11 _active_tasks = active_tasks; 2.12 @@ -793,6 +793,10 @@ 2.13 _terminator = ParallelTaskTerminator((int) active_tasks, _task_queues); 2.14 _first_overflow_barrier_sync.set_n_workers((int) active_tasks); 2.15 _second_overflow_barrier_sync.set_n_workers((int) active_tasks); 2.16 +} 2.17 + 2.18 +void ConcurrentMark::set_concurrency_and_phase(uint active_tasks, bool concurrent) { 2.19 + set_concurrency(active_tasks); 2.20 2.21 _concurrent = concurrent; 2.22 // We propagate this to all tasks, not just the active ones. 2.23 @@ -806,7 +810,9 @@ 2.24 // false before we start remark. At this point we should also be 2.25 // in a STW phase. 2.26 assert(!concurrent_marking_in_progress(), "invariant"); 2.27 - assert(_finger == _heap_end, "only way to get here"); 2.28 + assert(_finger == _heap_end, 2.29 + err_msg("only way to get here: _finger: "PTR_FORMAT", _heap_end: "PTR_FORMAT, 2.30 + _finger, _heap_end)); 2.31 update_g1_committed(true); 2.32 } 2.33 } 2.34 @@ -974,20 +980,28 @@ 2.35 gclog_or_tty->print_cr("[%u] leaving first barrier", worker_id); 2.36 } 2.37 2.38 - // let the task associated with with worker 0 do this 2.39 - if (worker_id == 0) { 2.40 - // task 0 is responsible for clearing the global data structures 2.41 - // We should be here because of an overflow. During STW we should 2.42 - // not clear the overflow flag since we rely on it being true when 2.43 - // we exit this method to abort the pause and restart concurent 2.44 - // marking. 2.45 - reset_marking_state(concurrent() /* clear_overflow */); 2.46 - force_overflow()->update(); 2.47 - 2.48 - if (G1Log::fine()) { 2.49 - gclog_or_tty->date_stamp(PrintGCDateStamps); 2.50 - gclog_or_tty->stamp(PrintGCTimeStamps); 2.51 - gclog_or_tty->print_cr("[GC concurrent-mark-reset-for-overflow]"); 2.52 + // If we're executing the concurrent phase of marking, reset the marking 2.53 + // state; otherwise the marking state is reset after reference processing, 2.54 + // during the remark pause. 2.55 + // If we reset here as a result of an overflow during the remark we will 2.56 + // see assertion failures from any subsequent set_concurrency_and_phase() 2.57 + // calls. 2.58 + if (concurrent()) { 2.59 + // let the task associated with with worker 0 do this 2.60 + if (worker_id == 0) { 2.61 + // task 0 is responsible for clearing the global data structures 2.62 + // We should be here because of an overflow. During STW we should 2.63 + // not clear the overflow flag since we rely on it being true when 2.64 + // we exit this method to abort the pause and restart concurent 2.65 + // marking. 2.66 + reset_marking_state(true /* clear_overflow */); 2.67 + force_overflow()->update(); 2.68 + 2.69 + if (G1Log::fine()) { 2.70 + gclog_or_tty->date_stamp(PrintGCDateStamps); 2.71 + gclog_or_tty->stamp(PrintGCTimeStamps); 2.72 + gclog_or_tty->print_cr("[GC concurrent-mark-reset-for-overflow]"); 2.73 + } 2.74 } 2.75 } 2.76 2.77 @@ -1007,7 +1021,7 @@ 2.78 if (concurrent()) { 2.79 ConcurrentGCThread::stsJoin(); 2.80 } 2.81 - // at this point everything should be re-initialised and ready to go 2.82 + // at this point everything should be re-initialized and ready to go 2.83 2.84 if (verbose_low()) { 2.85 gclog_or_tty->print_cr("[%u] leaving second barrier", worker_id); 2.86 @@ -1065,8 +1079,8 @@ 2.87 double mark_step_duration_ms = G1ConcMarkStepDurationMillis; 2.88 2.89 the_task->do_marking_step(mark_step_duration_ms, 2.90 - true /* do_stealing */, 2.91 - true /* do_termination */); 2.92 + true /* do_termination */, 2.93 + false /* is_serial*/); 2.94 2.95 double end_time_sec = os::elapsedTime(); 2.96 double end_vtime_sec = os::elapsedVTime(); 2.97 @@ -1222,8 +1236,8 @@ 2.98 2.99 uint active_workers = MAX2(1U, parallel_marking_threads()); 2.100 2.101 - // Parallel task terminator is set in "set_phase()" 2.102 - set_phase(active_workers, true /* concurrent */); 2.103 + // Parallel task terminator is set in "set_concurrency_and_phase()" 2.104 + set_concurrency_and_phase(active_workers, true /* concurrent */); 2.105 2.106 CMConcurrentMarkingTask markingTask(this, cmThread()); 2.107 if (use_parallel_marking_threads()) { 2.108 @@ -1275,12 +1289,22 @@ 2.109 if (has_overflown()) { 2.110 // Oops. We overflowed. Restart concurrent marking. 2.111 _restart_for_overflow = true; 2.112 + if (G1TraceMarkStackOverflow) { 2.113 + gclog_or_tty->print_cr("\nRemark led to restart for overflow."); 2.114 + } 2.115 + 2.116 + // Verify the heap w.r.t. the previous marking bitmap. 2.117 + if (VerifyDuringGC) { 2.118 + HandleMark hm; // handle scope 2.119 + gclog_or_tty->print(" VerifyDuringGC:(overflow)"); 2.120 + Universe::heap()->prepare_for_verify(); 2.121 + Universe::verify(/* silent */ false, 2.122 + /* option */ VerifyOption_G1UsePrevMarking); 2.123 + } 2.124 + 2.125 // Clear the marking state because we will be restarting 2.126 // marking due to overflowing the global mark stack. 2.127 reset_marking_state(); 2.128 - if (G1TraceMarkStackOverflow) { 2.129 - gclog_or_tty->print_cr("\nRemark led to restart for overflow."); 2.130 - } 2.131 } else { 2.132 // Aggregate the per-task counting data that we have accumulated 2.133 // while marking. 2.134 @@ -2184,14 +2208,17 @@ 2.135 // operating on the global stack. 2.136 2.137 class G1CMKeepAliveAndDrainClosure: public OopClosure { 2.138 - ConcurrentMark* _cm; 2.139 - CMTask* _task; 2.140 - int _ref_counter_limit; 2.141 - int _ref_counter; 2.142 + ConcurrentMark* _cm; 2.143 + CMTask* _task; 2.144 + int _ref_counter_limit; 2.145 + int _ref_counter; 2.146 + bool _is_serial; 2.147 public: 2.148 - G1CMKeepAliveAndDrainClosure(ConcurrentMark* cm, CMTask* task) : 2.149 - _cm(cm), _task(task), _ref_counter_limit(G1RefProcDrainInterval) { 2.150 + G1CMKeepAliveAndDrainClosure(ConcurrentMark* cm, CMTask* task, bool is_serial) : 2.151 + _cm(cm), _task(task), _is_serial(is_serial), 2.152 + _ref_counter_limit(G1RefProcDrainInterval) { 2.153 assert(_ref_counter_limit > 0, "sanity"); 2.154 + assert(!_is_serial || _task->worker_id() == 0, "only task 0 for serial code"); 2.155 _ref_counter = _ref_counter_limit; 2.156 } 2.157 2.158 @@ -2230,8 +2257,8 @@ 2.159 do { 2.160 double mark_step_duration_ms = G1ConcMarkStepDurationMillis; 2.161 _task->do_marking_step(mark_step_duration_ms, 2.162 - false /* do_stealing */, 2.163 - false /* do_termination */); 2.164 + false /* do_termination */, 2.165 + _is_serial); 2.166 } while (_task->has_aborted() && !_cm->has_overflown()); 2.167 _ref_counter = _ref_counter_limit; 2.168 } 2.169 @@ -2253,27 +2280,18 @@ 2.170 class G1CMDrainMarkingStackClosure: public VoidClosure { 2.171 ConcurrentMark* _cm; 2.172 CMTask* _task; 2.173 - bool _do_stealing; 2.174 - bool _do_termination; 2.175 + bool _is_serial; 2.176 public: 2.177 - G1CMDrainMarkingStackClosure(ConcurrentMark* cm, CMTask* task, bool is_par) : 2.178 - _cm(cm), _task(task) { 2.179 - assert(is_par || _task->worker_id() == 0, 2.180 - "Only task for worker 0 should be used if ref processing is single threaded"); 2.181 - // We only allow stealing and only enter the termination protocol 2.182 - // in CMTask::do_marking_step() if this closure is being instantiated 2.183 - // for parallel reference processing. 2.184 - _do_stealing = _do_termination = is_par; 2.185 + G1CMDrainMarkingStackClosure(ConcurrentMark* cm, CMTask* task, bool is_serial) : 2.186 + _cm(cm), _task(task), _is_serial(is_serial) { 2.187 + assert(!_is_serial || _task->worker_id() == 0, "only task 0 for serial code"); 2.188 } 2.189 2.190 void do_void() { 2.191 do { 2.192 if (_cm->verbose_high()) { 2.193 - gclog_or_tty->print_cr("\t[%u] Drain: Calling do_marking_step - " 2.194 - "stealing: %s, termination: %s", 2.195 - _task->worker_id(), 2.196 - BOOL_TO_STR(_do_stealing), 2.197 - BOOL_TO_STR(_do_termination)); 2.198 + gclog_or_tty->print_cr("\t[%u] Drain: Calling do_marking_step - serial: %s", 2.199 + _task->worker_id(), BOOL_TO_STR(_is_serial)); 2.200 } 2.201 2.202 // We call CMTask::do_marking_step() to completely drain the local 2.203 @@ -2294,8 +2312,8 @@ 2.204 // has_aborted() flag that the marking step has completed. 2.205 2.206 _task->do_marking_step(1000000000.0 /* something very large */, 2.207 - _do_stealing, 2.208 - _do_termination); 2.209 + true /* do_termination */, 2.210 + _is_serial); 2.211 } while (_task->has_aborted() && !_cm->has_overflown()); 2.212 } 2.213 }; 2.214 @@ -2328,7 +2346,6 @@ 2.215 ProcessTask& _proc_task; 2.216 G1CollectedHeap* _g1h; 2.217 ConcurrentMark* _cm; 2.218 - bool _processing_is_mt; 2.219 2.220 public: 2.221 G1CMRefProcTaskProxy(ProcessTask& proc_task, 2.222 @@ -2336,15 +2353,15 @@ 2.223 ConcurrentMark* cm) : 2.224 AbstractGangTask("Process reference objects in parallel"), 2.225 _proc_task(proc_task), _g1h(g1h), _cm(cm) { 2.226 - ReferenceProcessor* rp = _g1h->ref_processor_cm(); 2.227 - _processing_is_mt = rp->processing_is_mt(); 2.228 - } 2.229 + ReferenceProcessor* rp = _g1h->ref_processor_cm(); 2.230 + assert(rp->processing_is_mt(), "shouldn't be here otherwise"); 2.231 + } 2.232 2.233 virtual void work(uint worker_id) { 2.234 - CMTask* marking_task = _cm->task(worker_id); 2.235 + CMTask* task = _cm->task(worker_id); 2.236 G1CMIsAliveClosure g1_is_alive(_g1h); 2.237 - G1CMKeepAliveAndDrainClosure g1_par_keep_alive(_cm, marking_task); 2.238 - G1CMDrainMarkingStackClosure g1_par_drain(_cm, marking_task, _processing_is_mt); 2.239 + G1CMKeepAliveAndDrainClosure g1_par_keep_alive(_cm, task, false /* is_serial */); 2.240 + G1CMDrainMarkingStackClosure g1_par_drain(_cm, task, false /* is_serial */); 2.241 2.242 _proc_task.work(worker_id, g1_is_alive, g1_par_keep_alive, g1_par_drain); 2.243 } 2.244 @@ -2356,9 +2373,11 @@ 2.245 2.246 G1CMRefProcTaskProxy proc_task_proxy(proc_task, _g1h, _cm); 2.247 2.248 - // We need to reset the phase for each task execution so that 2.249 - // the termination protocol of CMTask::do_marking_step works. 2.250 - _cm->set_phase(_active_workers, false /* concurrent */); 2.251 + // We need to reset the concurrency level before each 2.252 + // proxy task execution, so that the termination protocol 2.253 + // and overflow handling in CMTask::do_marking_step() knows 2.254 + // how many workers to wait for. 2.255 + _cm->set_concurrency(_active_workers); 2.256 _g1h->set_par_threads(_active_workers); 2.257 _workers->run_task(&proc_task_proxy); 2.258 _g1h->set_par_threads(0); 2.259 @@ -2384,12 +2403,29 @@ 2.260 2.261 G1CMRefEnqueueTaskProxy enq_task_proxy(enq_task); 2.262 2.263 + // Not strictly necessary but... 2.264 + // 2.265 + // We need to reset the concurrency level before each 2.266 + // proxy task execution, so that the termination protocol 2.267 + // and overflow handling in CMTask::do_marking_step() knows 2.268 + // how many workers to wait for. 2.269 + _cm->set_concurrency(_active_workers); 2.270 _g1h->set_par_threads(_active_workers); 2.271 _workers->run_task(&enq_task_proxy); 2.272 _g1h->set_par_threads(0); 2.273 } 2.274 2.275 void ConcurrentMark::weakRefsWork(bool clear_all_soft_refs) { 2.276 + if (has_overflown()) { 2.277 + // Skip processing the discovered references if we have 2.278 + // overflown the global marking stack. Reference objects 2.279 + // only get discovered once so it is OK to not 2.280 + // de-populate the discovered reference lists. We could have, 2.281 + // but the only benefit would be that, when marking restarts, 2.282 + // less reference objects are discovered. 2.283 + return; 2.284 + } 2.285 + 2.286 ResourceMark rm; 2.287 HandleMark hm; 2.288 2.289 @@ -2415,26 +2451,39 @@ 2.290 rp->setup_policy(clear_all_soft_refs); 2.291 assert(_markStack.isEmpty(), "mark stack should be empty"); 2.292 2.293 - // Non-MT instances 'Keep Alive' and 'Complete GC' oop closures. 2.294 - G1CMKeepAliveAndDrainClosure g1_keep_alive(this, task(0)); 2.295 - G1CMDrainMarkingStackClosure g1_drain_mark_stack(this, task(0), false); 2.296 - 2.297 - // We need at least one active thread. If reference processing is 2.298 - // not multi-threaded we use the current (ConcurrentMarkThread) thread, 2.299 - // otherwise we use the work gang from the G1CollectedHeap and we 2.300 - // utilize all the worker threads we can. 2.301 - uint active_workers = (rp->processing_is_mt() && g1h->workers() != NULL 2.302 - ? g1h->workers()->active_workers() 2.303 - : 1U); 2.304 - 2.305 + // Instances of the 'Keep Alive' and 'Complete GC' closures used 2.306 + // in serial reference processing. Note these closures are also 2.307 + // used for serially processing (by the the current thread) the 2.308 + // JNI references during parallel reference processing. 2.309 + // 2.310 + // These closures do not need to synchronize with the worker 2.311 + // threads involved in parallel reference processing as these 2.312 + // instances are executed serially by the current thread (e.g. 2.313 + // reference processing is not multi-threaded and is thus 2.314 + // performed by the current thread instead of a gang worker). 2.315 + // 2.316 + // The gang tasks involved in parallel reference procssing create 2.317 + // their own instances of these closures, which do their own 2.318 + // synchronization among themselves. 2.319 + G1CMKeepAliveAndDrainClosure g1_keep_alive(this, task(0), true /* is_serial */); 2.320 + G1CMDrainMarkingStackClosure g1_drain_mark_stack(this, task(0), true /* is_serial */); 2.321 + 2.322 + // We need at least one active thread. If reference processing 2.323 + // is not multi-threaded we use the current (VMThread) thread, 2.324 + // otherwise we use the work gang from the G1CollectedHeap and 2.325 + // we utilize all the worker threads we can. 2.326 + bool processing_is_mt = rp->processing_is_mt() && g1h->workers() != NULL; 2.327 + uint active_workers = (processing_is_mt ? g1h->workers()->active_workers() : 1U); 2.328 active_workers = MAX2(MIN2(active_workers, _max_worker_id), 1U); 2.329 2.330 + // Parallel processing task executor. 2.331 G1CMRefProcTaskExecutor par_task_executor(g1h, this, 2.332 g1h->workers(), active_workers); 2.333 - 2.334 - AbstractRefProcTaskExecutor* executor = (rp->processing_is_mt() 2.335 - ? &par_task_executor 2.336 - : NULL); 2.337 + AbstractRefProcTaskExecutor* executor = (processing_is_mt ? &par_task_executor : NULL); 2.338 + 2.339 + // Set the concurrency level. The phase was already set prior to 2.340 + // executing the remark task. 2.341 + set_concurrency(active_workers); 2.342 2.343 // Set the degree of MT processing here. If the discovery was done MT, 2.344 // the number of threads involved during discovery could differ from 2.345 @@ -2454,6 +2503,7 @@ 2.346 2.347 assert(_markStack.overflow() || _markStack.isEmpty(), 2.348 "mark stack should be empty (unless it overflowed)"); 2.349 + 2.350 if (_markStack.overflow()) { 2.351 // This should have been done already when we tried to push an 2.352 // entry on to the global mark stack. But let's do it again. 2.353 @@ -2482,8 +2532,8 @@ 2.354 2.355 class CMRemarkTask: public AbstractGangTask { 2.356 private: 2.357 - ConcurrentMark *_cm; 2.358 - 2.359 + ConcurrentMark* _cm; 2.360 + bool _is_serial; 2.361 public: 2.362 void work(uint worker_id) { 2.363 // Since all available tasks are actually started, we should 2.364 @@ -2493,8 +2543,8 @@ 2.365 task->record_start_time(); 2.366 do { 2.367 task->do_marking_step(1000000000.0 /* something very large */, 2.368 - true /* do_stealing */, 2.369 - true /* do_termination */); 2.370 + true /* do_termination */, 2.371 + _is_serial); 2.372 } while (task->has_aborted() && !_cm->has_overflown()); 2.373 // If we overflow, then we do not want to restart. We instead 2.374 // want to abort remark and do concurrent marking again. 2.375 @@ -2502,8 +2552,8 @@ 2.376 } 2.377 } 2.378 2.379 - CMRemarkTask(ConcurrentMark* cm, int active_workers) : 2.380 - AbstractGangTask("Par Remark"), _cm(cm) { 2.381 + CMRemarkTask(ConcurrentMark* cm, int active_workers, bool is_serial) : 2.382 + AbstractGangTask("Par Remark"), _cm(cm), _is_serial(is_serial) { 2.383 _cm->terminator()->reset_for_reuse(active_workers); 2.384 } 2.385 }; 2.386 @@ -2524,30 +2574,40 @@ 2.387 active_workers = (uint) ParallelGCThreads; 2.388 g1h->workers()->set_active_workers(active_workers); 2.389 } 2.390 - set_phase(active_workers, false /* concurrent */); 2.391 + set_concurrency_and_phase(active_workers, false /* concurrent */); 2.392 // Leave _parallel_marking_threads at it's 2.393 // value originally calculated in the ConcurrentMark 2.394 // constructor and pass values of the active workers 2.395 // through the gang in the task. 2.396 2.397 - CMRemarkTask remarkTask(this, active_workers); 2.398 + CMRemarkTask remarkTask(this, active_workers, false /* is_serial */); 2.399 + // We will start all available threads, even if we decide that the 2.400 + // active_workers will be fewer. The extra ones will just bail out 2.401 + // immediately. 2.402 g1h->set_par_threads(active_workers); 2.403 g1h->workers()->run_task(&remarkTask); 2.404 g1h->set_par_threads(0); 2.405 } else { 2.406 G1CollectedHeap::StrongRootsScope srs(g1h); 2.407 - // this is remark, so we'll use up all available threads 2.408 uint active_workers = 1; 2.409 - set_phase(active_workers, false /* concurrent */); 2.410 - 2.411 - CMRemarkTask remarkTask(this, active_workers); 2.412 - // We will start all available threads, even if we decide that the 2.413 - // active_workers will be fewer. The extra ones will just bail out 2.414 - // immediately. 2.415 + set_concurrency_and_phase(active_workers, false /* concurrent */); 2.416 + 2.417 + // Note - if there's no work gang then the VMThread will be 2.418 + // the thread to execute the remark - serially. We have 2.419 + // to pass true for the is_serial parameter so that 2.420 + // CMTask::do_marking_step() doesn't enter the sync 2.421 + // barriers in the event of an overflow. Doing so will 2.422 + // cause an assert that the current thread is not a 2.423 + // concurrent GC thread. 2.424 + CMRemarkTask remarkTask(this, active_workers, true /* is_serial*/); 2.425 remarkTask.work(0); 2.426 } 2.427 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); 2.428 - guarantee(satb_mq_set.completed_buffers_num() == 0, "invariant"); 2.429 + guarantee(has_overflown() || 2.430 + satb_mq_set.completed_buffers_num() == 0, 2.431 + err_msg("Invariant: has_overflown = %s, num buffers = %d", 2.432 + BOOL_TO_STR(has_overflown()), 2.433 + satb_mq_set.completed_buffers_num())); 2.434 2.435 print_stats(); 2.436 } 2.437 @@ -3854,8 +3914,8 @@ 2.438 2.439 /***************************************************************************** 2.440 2.441 - The do_marking_step(time_target_ms) method is the building block 2.442 - of the parallel marking framework. It can be called in parallel 2.443 + The do_marking_step(time_target_ms, ...) method is the building 2.444 + block of the parallel marking framework. It can be called in parallel 2.445 with other invocations of do_marking_step() on different tasks 2.446 (but only one per task, obviously) and concurrently with the 2.447 mutator threads, or during remark, hence it eliminates the need 2.448 @@ -3865,7 +3925,7 @@ 2.449 pauses too, since do_marking_step() ensures that it aborts before 2.450 it needs to yield. 2.451 2.452 - The data structures that is uses to do marking work are the 2.453 + The data structures that it uses to do marking work are the 2.454 following: 2.455 2.456 (1) Marking Bitmap. If there are gray objects that appear only 2.457 @@ -3914,7 +3974,7 @@ 2.458 (2) When a global overflow (on the global stack) has been 2.459 triggered. Before the task aborts, it will actually sync up with 2.460 the other tasks to ensure that all the marking data structures 2.461 - (local queues, stacks, fingers etc.) are re-initialised so that 2.462 + (local queues, stacks, fingers etc.) are re-initialized so that 2.463 when do_marking_step() completes, the marking phase can 2.464 immediately restart. 2.465 2.466 @@ -3951,11 +4011,25 @@ 2.467 place, it was natural to piggy-back all the other conditions on it 2.468 too and not constantly check them throughout the code. 2.469 2.470 + If do_termination is true then do_marking_step will enter its 2.471 + termination protocol. 2.472 + 2.473 + The value of is_serial must be true when do_marking_step is being 2.474 + called serially (i.e. by the VMThread) and do_marking_step should 2.475 + skip any synchronization in the termination and overflow code. 2.476 + Examples include the serial remark code and the serial reference 2.477 + processing closures. 2.478 + 2.479 + The value of is_serial must be false when do_marking_step is 2.480 + being called by any of the worker threads in a work gang. 2.481 + Examples include the concurrent marking code (CMMarkingTask), 2.482 + the MT remark code, and the MT reference processing closures. 2.483 + 2.484 *****************************************************************************/ 2.485 2.486 void CMTask::do_marking_step(double time_target_ms, 2.487 - bool do_stealing, 2.488 - bool do_termination) { 2.489 + bool do_termination, 2.490 + bool is_serial) { 2.491 assert(time_target_ms >= 1.0, "minimum granularity is 1ms"); 2.492 assert(concurrent() == _cm->concurrent(), "they should be the same"); 2.493 2.494 @@ -3976,6 +4050,12 @@ 2.495 _start_time_ms = os::elapsedVTime() * 1000.0; 2.496 statsOnly( _interval_start_time_ms = _start_time_ms ); 2.497 2.498 + // If do_stealing is true then do_marking_step will attempt to 2.499 + // steal work from the other CMTasks. It only makes sense to 2.500 + // enable stealing when the termination protocol is enabled 2.501 + // and do_marking_step() is not being called serially. 2.502 + bool do_stealing = do_termination && !is_serial; 2.503 + 2.504 double diff_prediction_ms = 2.505 g1_policy->get_new_prediction(&_marking_step_diffs_ms); 2.506 _time_target_ms = time_target_ms - diff_prediction_ms; 2.507 @@ -4237,10 +4317,12 @@ 2.508 } 2.509 2.510 _termination_start_time_ms = os::elapsedVTime() * 1000.0; 2.511 + 2.512 // The CMTask class also extends the TerminatorTerminator class, 2.513 // hence its should_exit_termination() method will also decide 2.514 // whether to exit the termination protocol or not. 2.515 - bool finished = _cm->terminator()->offer_termination(this); 2.516 + bool finished = (is_serial || 2.517 + _cm->terminator()->offer_termination(this)); 2.518 double termination_end_time_ms = os::elapsedVTime() * 1000.0; 2.519 _termination_time_ms += 2.520 termination_end_time_ms - _termination_start_time_ms; 2.521 @@ -4320,20 +4402,28 @@ 2.522 gclog_or_tty->print_cr("[%u] detected overflow", _worker_id); 2.523 } 2.524 2.525 - _cm->enter_first_sync_barrier(_worker_id); 2.526 - // When we exit this sync barrier we know that all tasks have 2.527 - // stopped doing marking work. So, it's now safe to 2.528 - // re-initialise our data structures. At the end of this method, 2.529 - // task 0 will clear the global data structures. 2.530 + if (!is_serial) { 2.531 + // We only need to enter the sync barrier if being called 2.532 + // from a parallel context 2.533 + _cm->enter_first_sync_barrier(_worker_id); 2.534 + 2.535 + // When we exit this sync barrier we know that all tasks have 2.536 + // stopped doing marking work. So, it's now safe to 2.537 + // re-initialise our data structures. At the end of this method, 2.538 + // task 0 will clear the global data structures. 2.539 + } 2.540 2.541 statsOnly( ++_aborted_overflow ); 2.542 2.543 // We clear the local state of this task... 2.544 clear_region_fields(); 2.545 2.546 - // ...and enter the second barrier. 2.547 - _cm->enter_second_sync_barrier(_worker_id); 2.548 - // At this point everything has bee re-initialised and we're 2.549 + if (!is_serial) { 2.550 + // ...and enter the second barrier. 2.551 + _cm->enter_second_sync_barrier(_worker_id); 2.552 + } 2.553 + // At this point, if we're during the concurrent phase of 2.554 + // marking, everything has been re-initialized and we're 2.555 // ready to restart. 2.556 } 2.557
3.1 --- a/src/share/vm/gc_implementation/g1/concurrentMark.hpp Tue Mar 19 13:44:26 2013 +0100 3.2 +++ b/src/share/vm/gc_implementation/g1/concurrentMark.hpp Fri Mar 22 10:32:21 2013 +0100 3.3 @@ -166,7 +166,7 @@ 3.4 class CMMarkStack VALUE_OBJ_CLASS_SPEC { 3.5 VirtualSpace _virtual_space; // Underlying backing store for actual stack 3.6 ConcurrentMark* _cm; 3.7 - oop* _base; // bottom of stack 3.8 + oop* _base; // bottom of stack 3.9 jint _index; // one more than last occupied index 3.10 jint _capacity; // max #elements 3.11 jint _saved_index; // value of _index saved at start of GC 3.12 @@ -491,9 +491,12 @@ 3.13 // structures are initialised to a sensible and predictable state. 3.14 void set_non_marking_state(); 3.15 3.16 + // Called to indicate how many threads are currently active. 3.17 + void set_concurrency(uint active_tasks); 3.18 + 3.19 // It should be called to indicate which phase we're in (concurrent 3.20 // mark or remark) and how many threads are currently active. 3.21 - void set_phase(uint active_tasks, bool concurrent); 3.22 + void set_concurrency_and_phase(uint active_tasks, bool concurrent); 3.23 3.24 // prints all gathered CM-related statistics 3.25 void print_stats(); 3.26 @@ -1146,7 +1149,9 @@ 3.27 // trying not to exceed the given duration. However, it might exit 3.28 // prematurely, according to some conditions (i.e. SATB buffers are 3.29 // available for processing). 3.30 - void do_marking_step(double target_ms, bool do_stealing, bool do_termination); 3.31 + void do_marking_step(double target_ms, 3.32 + bool do_termination, 3.33 + bool is_serial); 3.34 3.35 // These two calls start and stop the timer 3.36 void record_start_time() {
4.1 --- a/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.cpp Tue Mar 19 13:44:26 2013 +0100 4.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/parallelScavengeHeap.cpp Fri Mar 22 10:32:21 2013 +0100 4.3 @@ -656,7 +656,7 @@ 4.4 tty->print_cr("[Accumulated GC generation 0 time %3.7f secs]", time); 4.5 } 4.6 if (TraceGen1Time) { 4.7 - double time = PSMarkSweep::accumulated_time()->seconds(); 4.8 + double time = UseParallelOldGC ? PSParallelCompact::accumulated_time()->seconds() : PSMarkSweep::accumulated_time()->seconds(); 4.9 tty->print_cr("[Accumulated GC generation 1 time %3.7f secs]", time); 4.10 } 4.11 }
5.1 --- a/src/share/vm/memory/genCollectedHeap.cpp Tue Mar 19 13:44:26 2013 +0100 5.2 +++ b/src/share/vm/memory/genCollectedHeap.cpp Fri Mar 22 10:32:21 2013 +0100 5.3 @@ -554,6 +554,8 @@ 5.4 } 5.5 5.6 if (complete) { 5.7 + // Delete metaspaces for unloaded class loaders and clean up loader_data graph 5.8 + ClassLoaderDataGraph::purge(); 5.9 // Resize the metaspace capacity after full collections 5.10 MetaspaceGC::compute_new_size(); 5.11 update_full_collections_completed(); 5.12 @@ -564,11 +566,6 @@ 5.13 5.14 gc_epilogue(complete); 5.15 5.16 - // Delete metaspaces for unloaded class loaders and clean up loader_data graph 5.17 - if (complete) { 5.18 - ClassLoaderDataGraph::purge(); 5.19 - } 5.20 - 5.21 if (must_restore_marks_for_biased_locking) { 5.22 BiasedLocking::restore_marks(); 5.23 }
6.1 --- a/src/share/vm/memory/metaspace.cpp Tue Mar 19 13:44:26 2013 +0100 6.2 +++ b/src/share/vm/memory/metaspace.cpp Fri Mar 22 10:32:21 2013 +0100 6.3 @@ -1103,25 +1103,24 @@ 6.4 } 6.5 6.6 bool MetaspaceGC::should_expand(VirtualSpaceList* vsl, size_t word_size) { 6.7 + // If the user wants a limit, impose one. 6.8 + if (!FLAG_IS_DEFAULT(MaxMetaspaceSize) && 6.9 + MetaspaceAux::reserved_in_bytes() >= MaxMetaspaceSize) { 6.10 + return false; 6.11 + } 6.12 6.13 // Class virtual space should always be expanded. Call GC for the other 6.14 // metadata virtual space. 6.15 if (vsl == Metaspace::class_space_list()) return true; 6.16 6.17 - // If the user wants a limit, impose one. 6.18 - size_t max_metaspace_size_words = MaxMetaspaceSize / BytesPerWord; 6.19 - size_t metaspace_size_words = MetaspaceSize / BytesPerWord; 6.20 - if (!FLAG_IS_DEFAULT(MaxMetaspaceSize) && 6.21 - vsl->capacity_words_sum() >= max_metaspace_size_words) { 6.22 - return false; 6.23 - } 6.24 - 6.25 // If this is part of an allocation after a GC, expand 6.26 // unconditionally. 6.27 if(MetaspaceGC::expand_after_GC()) { 6.28 return true; 6.29 } 6.30 6.31 + size_t metaspace_size_words = MetaspaceSize / BytesPerWord; 6.32 + 6.33 // If the capacity is below the minimum capacity, allow the 6.34 // expansion. Also set the high-water-mark (capacity_until_GC) 6.35 // to that minimum capacity so that a GC will not be induced 6.36 @@ -1311,8 +1310,7 @@ 6.37 gclog_or_tty->print_cr(" metaspace HWM: %.1fK", new_capacity_until_GC / (double) K); 6.38 } 6.39 } 6.40 - assert(vsl->used_bytes_sum() == used_after_gc && 6.41 - used_after_gc <= vsl->capacity_bytes_sum(), 6.42 + assert(used_after_gc <= vsl->capacity_bytes_sum(), 6.43 "sanity check"); 6.44 6.45 } 6.46 @@ -1972,6 +1970,9 @@ 6.47 } 6.48 6.49 SpaceManager::~SpaceManager() { 6.50 + // This call this->_lock which can't be done while holding expand_lock() 6.51 + const size_t in_use_before = sum_capacity_in_chunks_in_use(); 6.52 + 6.53 MutexLockerEx fcl(SpaceManager::expand_lock(), 6.54 Mutex::_no_safepoint_check_flag); 6.55 6.56 @@ -1989,7 +1990,7 @@ 6.57 6.58 // Have to update before the chunks_in_use lists are emptied 6.59 // below. 6.60 - chunk_manager->inc_free_chunks_total(sum_capacity_in_chunks_in_use(), 6.61 + chunk_manager->inc_free_chunks_total(in_use_before, 6.62 sum_count_in_chunks_in_use()); 6.63 6.64 // Add all the chunks in use by this space manager