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

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 548
ba764ed4b6f2
permissions
-rw-r--r--

Initial load

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

mercurial