src/share/vm/gc_implementation/parNew/parNewGeneration.hpp

Sun, 30 Dec 2012 08:47:52 +0100

author
brutisso
date
Sun, 30 Dec 2012 08:47:52 +0100
changeset 4387
ca0a78017dc7
parent 3982
aaf61e68b255
child 4452
a30e7b564541
permissions
-rw-r--r--

8005396: Use ParNew with only one thread instead of DefNew as default for CMS on single CPU machines
Reviewed-by: jmasa, jcoomes

duke@435 1 /*
johnc@3982 2 * Copyright (c) 2001, 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 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARNEWGENERATION_HPP
stefank@2314 26 #define SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARNEWGENERATION_HPP
stefank@2314 27
johnc@3982 28 #include "gc_implementation/shared/parGCAllocBuffer.hpp"
stefank@2314 29 #include "memory/defNewGeneration.hpp"
stefank@2314 30 #include "utilities/taskqueue.hpp"
stefank@2314 31
duke@435 32 class ChunkArray;
duke@435 33 class ParScanWithoutBarrierClosure;
duke@435 34 class ParScanWithBarrierClosure;
duke@435 35 class ParRootScanWithoutBarrierClosure;
duke@435 36 class ParRootScanWithBarrierTwoGensClosure;
duke@435 37 class ParEvacuateFollowersClosure;
duke@435 38
duke@435 39 // It would be better if these types could be kept local to the .cpp file,
duke@435 40 // but they must be here to allow ParScanClosure::do_oop_work to be defined
duke@435 41 // in genOopClosures.inline.hpp.
duke@435 42
jcoomes@2020 43 typedef Padded<OopTaskQueue> ObjToScanQueue;
zgu@3900 44 typedef GenericTaskQueueSet<ObjToScanQueue, mtGC> ObjToScanQueueSet;
duke@435 45
duke@435 46 class ParKeepAliveClosure: public DefNewGeneration::KeepAliveClosure {
coleenp@548 47 private:
duke@435 48 ParScanWeakRefClosure* _par_cl;
coleenp@548 49 protected:
coleenp@548 50 template <class T> void do_oop_work(T* p);
duke@435 51 public:
duke@435 52 ParKeepAliveClosure(ParScanWeakRefClosure* cl);
coleenp@548 53 virtual void do_oop(oop* p);
coleenp@548 54 virtual void do_oop(narrowOop* p);
duke@435 55 };
duke@435 56
duke@435 57 // The state needed by thread performing parallel young-gen collection.
duke@435 58 class ParScanThreadState {
duke@435 59 friend class ParScanThreadStateSet;
coleenp@548 60 private:
duke@435 61 ObjToScanQueue *_work_queue;
zgu@3900 62 Stack<oop, mtGC>* const _overflow_stack;
duke@435 63
duke@435 64 ParGCAllocBuffer _to_space_alloc_buffer;
duke@435 65
duke@435 66 ParScanWithoutBarrierClosure _to_space_closure; // scan_without_gc_barrier
duke@435 67 ParScanWithBarrierClosure _old_gen_closure; // scan_with_gc_barrier
duke@435 68 ParRootScanWithoutBarrierClosure _to_space_root_closure; // scan_root_without_gc_barrier
duke@435 69 // One of these two will be passed to process_strong_roots, which will
duke@435 70 // set its generation. The first is for two-gen configs where the
duke@435 71 // old gen collects the perm gen; the second is for arbitrary configs.
duke@435 72 // The second isn't used right now (it used to be used for the train, an
duke@435 73 // incremental collector) but the declaration has been left as a reminder.
duke@435 74 ParRootScanWithBarrierTwoGensClosure _older_gen_closure;
duke@435 75 // This closure will always be bound to the old gen; it will be used
duke@435 76 // in evacuate_followers.
duke@435 77 ParRootScanWithBarrierTwoGensClosure _old_gen_root_closure; // scan_old_root_with_gc_barrier
duke@435 78 ParEvacuateFollowersClosure _evacuate_followers;
duke@435 79 DefNewGeneration::IsAliveClosure _is_alive_closure;
duke@435 80 ParScanWeakRefClosure _scan_weak_ref_closure;
duke@435 81 ParKeepAliveClosure _keep_alive_closure;
duke@435 82
duke@435 83
duke@435 84 Space* _to_space;
duke@435 85 Space* to_space() { return _to_space; }
duke@435 86
ysr@1114 87 ParNewGeneration* _young_gen;
ysr@1114 88 ParNewGeneration* young_gen() const { return _young_gen; }
ysr@1114 89
duke@435 90 Generation* _old_gen;
duke@435 91 Generation* old_gen() { return _old_gen; }
duke@435 92
duke@435 93 HeapWord *_young_old_boundary;
duke@435 94
duke@435 95 int _hash_seed;
duke@435 96 int _thread_num;
duke@435 97 ageTable _ageTable;
duke@435 98
duke@435 99 bool _to_space_full;
duke@435 100
jcoomes@2065 101 #if TASKQUEUE_STATS
jcoomes@2065 102 size_t _term_attempts;
jcoomes@2065 103 size_t _overflow_refills;
jcoomes@2065 104 size_t _overflow_refill_objs;
jcoomes@2065 105 #endif // TASKQUEUE_STATS
duke@435 106
ysr@1580 107 // Stats for promotion failure
ysr@1580 108 size_t _promotion_failure_size;
ysr@1580 109
duke@435 110 // Timing numbers.
duke@435 111 double _start;
duke@435 112 double _start_strong_roots;
duke@435 113 double _strong_roots_time;
duke@435 114 double _start_term;
duke@435 115 double _term_time;
duke@435 116
duke@435 117 // Helper for trim_queues. Scans subset of an array and makes
duke@435 118 // remainder available for work stealing.
duke@435 119 void scan_partial_array_and_push_remainder(oop obj);
duke@435 120
duke@435 121 // In support of CMS' parallel rescan of survivor space.
duke@435 122 ChunkArray* _survivor_chunk_array;
duke@435 123 ChunkArray* survivor_chunk_array() { return _survivor_chunk_array; }
duke@435 124
duke@435 125 void record_survivor_plab(HeapWord* plab_start, size_t plab_word_size);
duke@435 126
duke@435 127 ParScanThreadState(Space* to_space_, ParNewGeneration* gen_,
duke@435 128 Generation* old_gen_, int thread_num_,
ysr@1130 129 ObjToScanQueueSet* work_queue_set_,
zgu@3900 130 Stack<oop, mtGC>* overflow_stacks_,
ysr@1130 131 size_t desired_plab_sz_,
duke@435 132 ParallelTaskTerminator& term_);
duke@435 133
coleenp@548 134 public:
duke@435 135 ageTable* age_table() {return &_ageTable;}
duke@435 136
duke@435 137 ObjToScanQueue* work_queue() { return _work_queue; }
duke@435 138
duke@435 139 ParGCAllocBuffer* to_space_alloc_buffer() {
duke@435 140 return &_to_space_alloc_buffer;
duke@435 141 }
duke@435 142
duke@435 143 ParEvacuateFollowersClosure& evacuate_followers_closure() { return _evacuate_followers; }
duke@435 144 DefNewGeneration::IsAliveClosure& is_alive_closure() { return _is_alive_closure; }
duke@435 145 ParScanWeakRefClosure& scan_weak_ref_closure() { return _scan_weak_ref_closure; }
duke@435 146 ParKeepAliveClosure& keep_alive_closure() { return _keep_alive_closure; }
duke@435 147 ParScanClosure& older_gen_closure() { return _older_gen_closure; }
duke@435 148 ParRootScanWithoutBarrierClosure& to_space_root_closure() { return _to_space_root_closure; };
duke@435 149
duke@435 150 // Decrease queue size below "max_size".
duke@435 151 void trim_queues(int max_size);
duke@435 152
ysr@1114 153 // Private overflow stack usage
zgu@3900 154 Stack<oop, mtGC>* overflow_stack() { return _overflow_stack; }
ysr@1114 155 bool take_from_overflow_stack();
ysr@1114 156 void push_on_overflow_stack(oop p);
ysr@1114 157
duke@435 158 // Is new_obj a candidate for scan_partial_array_and_push_remainder method.
duke@435 159 inline bool should_be_partially_scanned(oop new_obj, oop old_obj) const;
duke@435 160
duke@435 161 int* hash_seed() { return &_hash_seed; }
duke@435 162 int thread_num() { return _thread_num; }
duke@435 163
duke@435 164 // Allocate a to-space block of size "sz", or else return NULL.
duke@435 165 HeapWord* alloc_in_to_space_slow(size_t word_sz);
duke@435 166
duke@435 167 HeapWord* alloc_in_to_space(size_t word_sz) {
duke@435 168 HeapWord* obj = to_space_alloc_buffer()->allocate(word_sz);
duke@435 169 if (obj != NULL) return obj;
duke@435 170 else return alloc_in_to_space_slow(word_sz);
duke@435 171 }
duke@435 172
duke@435 173 HeapWord* young_old_boundary() { return _young_old_boundary; }
duke@435 174
duke@435 175 void set_young_old_boundary(HeapWord *boundary) {
duke@435 176 _young_old_boundary = boundary;
duke@435 177 }
duke@435 178
duke@435 179 // Undo the most recent allocation ("obj", of "word_sz").
duke@435 180 void undo_alloc_in_to_space(HeapWord* obj, size_t word_sz);
duke@435 181
ysr@1580 182 // Promotion failure stats
ysr@1580 183 size_t promotion_failure_size() { return promotion_failure_size(); }
ysr@1580 184 void log_promotion_failure(size_t sz) {
ysr@1580 185 if (_promotion_failure_size == 0) {
ysr@1580 186 _promotion_failure_size = sz;
ysr@1580 187 }
ysr@1580 188 }
ysr@1580 189 void print_and_clear_promotion_failure_size();
ysr@1580 190
jcoomes@2065 191 #if TASKQUEUE_STATS
jcoomes@2065 192 TaskQueueStats & taskqueue_stats() const { return _work_queue->stats; }
duke@435 193
jcoomes@2065 194 size_t term_attempts() const { return _term_attempts; }
jcoomes@2065 195 size_t overflow_refills() const { return _overflow_refills; }
jcoomes@2065 196 size_t overflow_refill_objs() const { return _overflow_refill_objs; }
jcoomes@2065 197
jcoomes@2065 198 void note_term_attempt() { ++_term_attempts; }
jcoomes@2065 199 void note_overflow_refill(size_t objs) {
jcoomes@2065 200 ++_overflow_refills; _overflow_refill_objs += objs;
duke@435 201 }
duke@435 202
jcoomes@2065 203 void reset_stats();
jcoomes@2065 204 #endif // TASKQUEUE_STATS
jcoomes@2065 205
duke@435 206 void start_strong_roots() {
duke@435 207 _start_strong_roots = os::elapsedTime();
duke@435 208 }
duke@435 209 void end_strong_roots() {
duke@435 210 _strong_roots_time += (os::elapsedTime() - _start_strong_roots);
duke@435 211 }
jcoomes@2065 212 double strong_roots_time() const { return _strong_roots_time; }
duke@435 213 void start_term_time() {
jcoomes@2065 214 TASKQUEUE_STATS_ONLY(note_term_attempt());
duke@435 215 _start_term = os::elapsedTime();
duke@435 216 }
duke@435 217 void end_term_time() {
duke@435 218 _term_time += (os::elapsedTime() - _start_term);
duke@435 219 }
jcoomes@2065 220 double term_time() const { return _term_time; }
duke@435 221
jcoomes@2065 222 double elapsed_time() const {
duke@435 223 return os::elapsedTime() - _start;
duke@435 224 }
duke@435 225 };
duke@435 226
duke@435 227 class ParNewGenTask: public AbstractGangTask {
coleenp@548 228 private:
coleenp@548 229 ParNewGeneration* _gen;
coleenp@548 230 Generation* _next_gen;
coleenp@548 231 HeapWord* _young_old_boundary;
duke@435 232 class ParScanThreadStateSet* _state_set;
duke@435 233
duke@435 234 public:
duke@435 235 ParNewGenTask(ParNewGeneration* gen,
duke@435 236 Generation* next_gen,
duke@435 237 HeapWord* young_old_boundary,
duke@435 238 ParScanThreadStateSet* state_set);
duke@435 239
duke@435 240 HeapWord* young_old_boundary() { return _young_old_boundary; }
duke@435 241
jmasa@3357 242 void work(uint worker_id);
jmasa@3294 243
jmasa@3294 244 // Reset the terminator in ParScanThreadStateSet for
jmasa@3294 245 // "active_workers" threads.
jmasa@3294 246 virtual void set_for_termination(int active_workers);
duke@435 247 };
duke@435 248
duke@435 249 class KeepAliveClosure: public DefNewGeneration::KeepAliveClosure {
coleenp@548 250 protected:
coleenp@548 251 template <class T> void do_oop_work(T* p);
duke@435 252 public:
duke@435 253 KeepAliveClosure(ScanWeakRefClosure* cl);
coleenp@548 254 virtual void do_oop(oop* p);
coleenp@548 255 virtual void do_oop(narrowOop* p);
duke@435 256 };
duke@435 257
duke@435 258 class EvacuateFollowersClosureGeneral: public VoidClosure {
coleenp@548 259 private:
coleenp@548 260 GenCollectedHeap* _gch;
coleenp@548 261 int _level;
coleenp@548 262 OopsInGenClosure* _scan_cur_or_nonheap;
coleenp@548 263 OopsInGenClosure* _scan_older;
coleenp@548 264 public:
coleenp@548 265 EvacuateFollowersClosureGeneral(GenCollectedHeap* gch, int level,
coleenp@548 266 OopsInGenClosure* cur,
coleenp@548 267 OopsInGenClosure* older);
coleenp@548 268 virtual void do_void();
duke@435 269 };
duke@435 270
duke@435 271 // Closure for scanning ParNewGeneration.
duke@435 272 // Same as ScanClosure, except does parallel GC barrier.
duke@435 273 class ScanClosureWithParBarrier: public ScanClosure {
coleenp@548 274 protected:
coleenp@548 275 template <class T> void do_oop_work(T* p);
coleenp@548 276 public:
duke@435 277 ScanClosureWithParBarrier(ParNewGeneration* g, bool gc_barrier);
coleenp@548 278 virtual void do_oop(oop* p);
coleenp@548 279 virtual void do_oop(narrowOop* p);
duke@435 280 };
duke@435 281
duke@435 282 // Implements AbstractRefProcTaskExecutor for ParNew.
duke@435 283 class ParNewRefProcTaskExecutor: public AbstractRefProcTaskExecutor {
coleenp@548 284 private:
coleenp@548 285 ParNewGeneration& _generation;
coleenp@548 286 ParScanThreadStateSet& _state_set;
coleenp@548 287 public:
duke@435 288 ParNewRefProcTaskExecutor(ParNewGeneration& generation,
duke@435 289 ParScanThreadStateSet& state_set)
duke@435 290 : _generation(generation), _state_set(state_set)
duke@435 291 { }
duke@435 292
duke@435 293 // Executes a task using worker threads.
duke@435 294 virtual void execute(ProcessTask& task);
duke@435 295 virtual void execute(EnqueueTask& task);
duke@435 296 // Switch to single threaded mode.
duke@435 297 virtual void set_single_threaded_mode();
duke@435 298 };
duke@435 299
duke@435 300
duke@435 301 // A Generation that does parallel young-gen collection.
duke@435 302
duke@435 303 class ParNewGeneration: public DefNewGeneration {
duke@435 304 friend class ParNewGenTask;
duke@435 305 friend class ParNewRefProcTask;
duke@435 306 friend class ParNewRefProcTaskExecutor;
duke@435 307 friend class ParScanThreadStateSet;
ysr@969 308 friend class ParEvacuateFollowersClosure;
duke@435 309
coleenp@548 310 private:
ysr@1130 311 // The per-worker-thread work queues
duke@435 312 ObjToScanQueueSet* _task_queues;
duke@435 313
ysr@1130 314 // Per-worker-thread local overflow stacks
zgu@3900 315 Stack<oop, mtGC>* _overflow_stacks;
ysr@1130 316
duke@435 317 // Desired size of survivor space plab's
duke@435 318 PLABStats _plab_stats;
duke@435 319
duke@435 320 // A list of from-space images of to-be-scanned objects, threaded through
duke@435 321 // klass-pointers (klass information already copied to the forwarded
duke@435 322 // image.) Manipulated with CAS.
duke@435 323 oop _overflow_list;
ysr@969 324 NOT_PRODUCT(ssize_t _num_par_pushes;)
duke@435 325
duke@435 326 // If true, older generation does not support promotion undo, so avoid.
duke@435 327 static bool _avoid_promotion_undo;
duke@435 328
duke@435 329 // This closure is used by the reference processor to filter out
duke@435 330 // references to live referent.
duke@435 331 DefNewGeneration::IsAliveClosure _is_alive_closure;
duke@435 332
duke@435 333 static oop real_forwardee_slow(oop obj);
duke@435 334 static void waste_some_time();
duke@435 335
duke@435 336 // Preserve the mark of "obj", if necessary, in preparation for its mark
duke@435 337 // word being overwritten with a self-forwarding-pointer.
duke@435 338 void preserve_mark_if_necessary(oop obj, markOop m);
duke@435 339
duke@435 340 protected:
duke@435 341
duke@435 342 bool _survivor_overflow;
duke@435 343
duke@435 344 bool avoid_promotion_undo() { return _avoid_promotion_undo; }
duke@435 345 void set_avoid_promotion_undo(bool v) { _avoid_promotion_undo = v; }
duke@435 346
duke@435 347 bool survivor_overflow() { return _survivor_overflow; }
duke@435 348 void set_survivor_overflow(bool v) { _survivor_overflow = v; }
duke@435 349
duke@435 350 // Adjust the tenuring threshold. See the implementation for
duke@435 351 // the details of the policy.
duke@435 352 virtual void adjust_desired_tenuring_threshold();
duke@435 353
coleenp@548 354 public:
duke@435 355 ParNewGeneration(ReservedSpace rs, size_t initial_byte_size, int level);
duke@435 356
duke@435 357 ~ParNewGeneration() {
duke@435 358 for (uint i = 0; i < ParallelGCThreads; i++)
duke@435 359 delete _task_queues->queue(i);
duke@435 360
duke@435 361 delete _task_queues;
duke@435 362 }
duke@435 363
duke@435 364 virtual void ref_processor_init();
duke@435 365 virtual Generation::Name kind() { return Generation::ParNew; }
duke@435 366 virtual const char* name() const;
duke@435 367 virtual const char* short_name() const { return "ParNew"; }
duke@435 368
duke@435 369 // override
duke@435 370 virtual bool refs_discovery_is_mt() const {
duke@435 371 assert(UseParNewGC, "ParNewGeneration only when UseParNewGC");
duke@435 372 return ParallelGCThreads > 1;
duke@435 373 }
duke@435 374
duke@435 375 // Make the collection virtual.
duke@435 376 virtual void collect(bool full,
duke@435 377 bool clear_all_soft_refs,
duke@435 378 size_t size,
duke@435 379 bool is_tlab);
duke@435 380
duke@435 381 // This needs to be visible to the closure function.
duke@435 382 // "obj" is the object to be copied, "m" is a recent value of its mark
duke@435 383 // that must not contain a forwarding pointer (though one might be
duke@435 384 // inserted in "obj"s mark word by a parallel thread).
duke@435 385 inline oop copy_to_survivor_space(ParScanThreadState* par_scan_state,
duke@435 386 oop obj, size_t obj_sz, markOop m) {
duke@435 387 if (_avoid_promotion_undo) {
duke@435 388 return copy_to_survivor_space_avoiding_promotion_undo(par_scan_state,
duke@435 389 obj, obj_sz, m);
duke@435 390 }
duke@435 391
duke@435 392 return copy_to_survivor_space_with_undo(par_scan_state, obj, obj_sz, m);
duke@435 393 }
duke@435 394
duke@435 395 oop copy_to_survivor_space_avoiding_promotion_undo(ParScanThreadState* par_scan_state,
duke@435 396 oop obj, size_t obj_sz, markOop m);
duke@435 397
duke@435 398 oop copy_to_survivor_space_with_undo(ParScanThreadState* par_scan_state,
duke@435 399 oop obj, size_t obj_sz, markOop m);
duke@435 400
ysr@969 401 // in support of testing overflow code
ysr@969 402 NOT_PRODUCT(int _overflow_counter;)
ysr@969 403 NOT_PRODUCT(bool should_simulate_overflow();)
ysr@969 404
ysr@1114 405 // Accessor for overflow list
ysr@1114 406 oop overflow_list() { return _overflow_list; }
ysr@1114 407
duke@435 408 // Push the given (from-space) object on the global overflow list.
ysr@969 409 void push_on_overflow_list(oop from_space_obj, ParScanThreadState* par_scan_state);
duke@435 410
duke@435 411 // If the global overflow list is non-empty, move some tasks from it
ysr@1114 412 // onto "work_q" (which need not be empty). No more than 1/4 of the
ysr@1114 413 // available space on "work_q" is used.
duke@435 414 bool take_from_overflow_list(ParScanThreadState* par_scan_state);
ysr@1114 415 bool take_from_overflow_list_work(ParScanThreadState* par_scan_state);
duke@435 416
duke@435 417 // The task queues to be used by parallel GC threads.
duke@435 418 ObjToScanQueueSet* task_queues() {
duke@435 419 return _task_queues;
duke@435 420 }
duke@435 421
duke@435 422 PLABStats* plab_stats() {
duke@435 423 return &_plab_stats;
duke@435 424 }
duke@435 425
duke@435 426 size_t desired_plab_sz() {
duke@435 427 return _plab_stats.desired_plab_sz();
duke@435 428 }
duke@435 429
duke@435 430 static oop real_forwardee(oop obj);
duke@435 431
duke@435 432 DEBUG_ONLY(static bool is_legal_forward_ptr(oop p);)
duke@435 433 };
stefank@2314 434
stefank@2314 435 #endif // SHARE_VM_GC_IMPLEMENTATION_PARNEW_PARNEWGENERATION_HPP

mercurial