< prev index next >

src/share/vm/gc/g1/g1ConcurrentMark.hpp

Print this page
rev 10546 : [mq]: 8077144-concurrent-mark-thread-init-fix
rev 10547 : imported patch 8077144-mikael-review


 249   // all have been claimed.
 250   HeapRegion* claim_next();
 251 
 252   void cancel_scan();
 253 
 254   // Flag that we're done with root region scanning and notify anyone
 255   // who's waiting on it. If aborted is false, assume that all regions
 256   // have been claimed.
 257   void scan_finished();
 258 
 259   // If CM threads are still scanning root regions, wait until they
 260   // are done. Return true if we had to wait, false otherwise.
 261   bool wait_until_scan_finished();
 262 };
 263 
 264 class ConcurrentMarkThread;
 265 
 266 class G1ConcurrentMark: public CHeapObj<mtGC> {
 267   friend class ConcurrentMarkThread;
 268   friend class G1ParNoteEndTask;
 269   friend class CalcLiveObjectsClosure;
 270   friend class G1CMRefProcTaskProxy;
 271   friend class G1CMRefProcTaskExecutor;
 272   friend class G1CMKeepAliveAndDrainClosure;
 273   friend class G1CMDrainMarkingStackClosure;
 274   friend class G1CMBitMapClosure;
 275   friend class G1CMConcurrentMarkingTask;
 276   friend class G1CMMarkStack;
 277   friend class G1CMRemarkTask;
 278   friend class G1CMTask;
 279 
 280 protected:
 281   ConcurrentMarkThread* _cmThread;   // The thread doing the work
 282   G1CollectedHeap*      _g1h;        // The heap
 283   uint                  _parallel_marking_threads; // The number of marking
 284                                                    // threads we're using
 285   uint                  _max_parallel_marking_threads; // Max number of marking
 286                                                        // threads we'll ever use
 287   double                _sleep_factor; // How much we have to sleep, with
 288                                        // respect to the work we just did, to
 289                                        // meet the marking overhead goal
 290   double                _marking_task_overhead; // Marking target overhead for
 291                                                 // a single task
 292 
 293   FreeRegionList        _cleanup_list;
 294 
 295   // Concurrent marking support structures
 296   G1CMBitMap              _markBitMap1;
 297   G1CMBitMap              _markBitMap2;
 298   G1CMBitMapRO*           _prevMarkBitMap; // Completed mark bitmap
 299   G1CMBitMap*             _nextMarkBitMap; // Under-construction mark bitmap
 300 
 301   BitMap                  _region_bm;
 302   BitMap                  _card_bm;






 303 
 304   // Heap bounds
 305   HeapWord*               _heap_start;
 306   HeapWord*               _heap_end;
 307 
 308   // Root region tracking and claiming
 309   G1CMRootRegions         _root_regions;
 310 
 311   // For gray objects
 312   G1CMMarkStack           _markStack; // Grey objects behind global finger
 313   HeapWord* volatile      _finger;  // The global finger, region aligned,
 314                                     // always points to the end of the
 315                                     // last claimed region
 316 
 317   // Marking tasks
 318   uint                    _max_worker_id;// Maximum worker id
 319   uint                    _active_tasks; // Task num currently active
 320   G1CMTask**              _tasks;        // Task queue array (max_worker_id len)
 321   G1CMTaskQueueSet*       _task_queues;  // Task queue set
 322   ParallelTaskTerminator  _terminator;   // For termination


 356   G1OldTracer*            _gc_tracer_cm;
 357 
 358   // All of these times are in ms
 359   NumberSeq _init_times;
 360   NumberSeq _remark_times;
 361   NumberSeq _remark_mark_times;
 362   NumberSeq _remark_weak_ref_times;
 363   NumberSeq _cleanup_times;
 364   double    _total_counting_time;
 365   double    _total_rs_scrub_time;
 366 
 367   double*   _accum_task_vtime;   // Accumulated task vtime
 368 
 369   WorkGang* _parallel_workers;
 370 
 371   void weakRefsWorkParallelPart(BoolObjectClosure* is_alive, bool purged_classes);
 372   void weakRefsWork(bool clear_all_soft_refs);
 373 
 374   void swapMarkBitMaps();
 375 








 376   // It resets the global marking data structures, as well as the
 377   // task local ones; should be called during initial mark.
 378   void reset();
 379 
 380   // Resets all the marking data structures. Called when we have to restart
 381   // marking or when marking completes (via set_non_marking_state below).
 382   void reset_marking_state(bool clear_overflow = true);
 383 
 384   // We do this after we're done with marking so that the marking data
 385   // structures are initialized to a sensible and predictable state.
 386   void set_non_marking_state();
 387 
 388   // Called to indicate how many threads are currently active.
 389   void set_concurrency(uint active_tasks);
 390 
 391   // It should be called to indicate which phase we're in (concurrent
 392   // mark or remark) and how many threads are currently active.
 393   void set_concurrency_and_phase(uint active_tasks, bool concurrent);
 394 
 395   // Prints all gathered CM-related statistics


 444   G1CMTaskQueue* task_queue(int id) {
 445     assert(0 <= id && id < (int) _active_tasks,
 446            "task queue id not within active bounds");
 447     return (G1CMTaskQueue*) _task_queues->queue(id);
 448   }
 449 
 450   // Returns the task queue set
 451   G1CMTaskQueueSet* task_queues()  { return _task_queues; }
 452 
 453   // Access / manipulation of the overflow flag which is set to
 454   // indicate that the global stack has overflown
 455   bool has_overflown()           { return _has_overflown; }
 456   void set_has_overflown()       { _has_overflown = true; }
 457   void clear_has_overflown()     { _has_overflown = false; }
 458   bool restart_for_overflow()    { return _restart_for_overflow; }
 459 
 460   // Methods to enter the two overflow sync barriers
 461   void enter_first_sync_barrier(uint worker_id);
 462   void enter_second_sync_barrier(uint worker_id);
 463 
 464   // Live Data Counting data structures...
 465   // These data structures are initialized at the start of
 466   // marking. They are written to while marking is active.
 467   // They are aggregated during remark; the aggregated values
 468   // are then used to populate the _region_bm, _card_bm, and
 469   // the total live bytes, which are then subsequently updated
 470   // during cleanup.
 471 
 472   // An array of bitmaps (one bit map per task). Each bitmap
 473   // is used to record the cards spanned by the live objects
 474   // marked by that task/worker.
 475   BitMap*  _count_card_bitmaps;
 476 
 477   // Used to record the number of marked live bytes
 478   // (for each region, by worker thread).
 479   size_t** _count_marked_bytes;
 480 
 481   // Card index of the bottom of the G1 heap. Used for biasing indices into
 482   // the card bitmaps.
 483   intptr_t _heap_bottom_card_num;
 484 
 485   // Set to true when initialization is complete
 486   bool _completed_initialization;
 487 
 488   // end_timer, true to end gc timer after ending concurrent phase.
 489   void register_concurrent_phase_end_common(bool end_timer);
 490 
 491   // Clear the given bitmap in parallel using the given WorkGang. If may_yield is
 492   // true, periodically insert checks to see if this method should exit prematurely.
 493   void clear_bitmap(G1CMBitMap* bitmap, WorkGang* workers, bool may_yield);
 494 public:
 495   // Manipulation of the global mark stack.
 496   // The push and pop operations are used by tasks for transfers
 497   // between task-local queues and the global mark stack, and use
 498   // locking for concurrency safety.
 499   bool mark_stack_push(oop* arr, int n) {
 500     _markStack.par_push_arr(arr, n);


 546                    G1RegionToSpaceMapper* next_bitmap_storage);
 547   ~G1ConcurrentMark();
 548 
 549   ConcurrentMarkThread* cmThread() { return _cmThread; }
 550 
 551   G1CMBitMapRO* prevMarkBitMap() const { return _prevMarkBitMap; }
 552   G1CMBitMap*   nextMarkBitMap() const { return _nextMarkBitMap; }
 553 
 554   // Returns the number of GC threads to be used in a concurrent
 555   // phase based on the number of GC threads being used in a STW
 556   // phase.
 557   uint scale_parallel_threads(uint n_par_threads);
 558 
 559   // Calculates the number of GC threads to be used in a concurrent phase.
 560   uint calc_parallel_marking_threads();
 561 
 562   // The following three are interaction between CM and
 563   // G1CollectedHeap
 564 
 565   // This notifies CM that a root during initial-mark needs to be
 566   // grayed. It is MT-safe. word_size is the size of the object in
 567   // words. It is passed explicitly as sometimes we cannot calculate
 568   // it from the given object because it might be in an inconsistent
 569   // state (e.g., in to-space and being copied). So the caller is
 570   // responsible for dealing with this issue (e.g., get the size from
 571   // the from-space image when the to-space image might be
 572   // inconsistent) and always passing the size. hr is the region that
 573   // contains the object and it's passed optionally from callers who
 574   // might already have it (no point in recalculating it).
 575   inline void grayRoot(oop obj,
 576                        size_t word_size,
 577                        uint worker_id,
 578                        HeapRegion* hr = NULL);
 579 
 580   // Prepare internal data structures for the next mark cycle. This includes clearing
 581   // the next mark bitmap and some internal data structures. This method is intended
 582   // to be called concurrently to the mutator. It will yield to safepoint requests.
 583   void cleanup_for_next_mark();
 584 
 585   // Clear the previous marking bitmap during safepoint.
 586   void clear_prev_bitmap(WorkGang* workers);
 587 
 588   // Return whether the next mark bitmap has no marks set. To be used for assertions
 589   // only. Will not yield to pause requests.
 590   bool nextMarkBitmapIsClear();
 591 
 592   // These two do the work that needs to be done before and after the
 593   // initial root checkpoint. Since this checkpoint can be done at two
 594   // different points (i.e. an explicit pause or piggy-backed on a
 595   // young collection), then it's nice to be able to easily share the
 596   // pre/post code. It might be the case that we can put everything in
 597   // the post method. TP


 624 
 625   // Notify data structures that a GC has started.
 626   void note_start_of_gc() {
 627     _markStack.note_start_of_gc();
 628   }
 629 
 630   // Notify data structures that a GC is finished.
 631   void note_end_of_gc() {
 632     _markStack.note_end_of_gc();
 633   }
 634 
 635   // Verify that there are no CSet oops on the stacks (taskqueues /
 636   // global mark stack) and fingers (global / per-task).
 637   // If marking is not in progress, it's a no-op.
 638   void verify_no_cset_oops() PRODUCT_RETURN;
 639 
 640   inline bool isPrevMarked(oop p) const;
 641 
 642   inline bool do_yield_check(uint worker_i = 0);
 643 
 644   // Called to abort the marking cycle after a Full GC takes place.
 645   void abort();
 646 
 647   bool has_aborted()      { return _has_aborted; }
 648 
 649   void print_summary_info();
 650 
 651   void print_worker_threads_on(outputStream* st) const;
 652 
 653   void print_on_error(outputStream* st) const;
 654 
 655   // Liveness counting
 656 
 657   // Utility routine to set an exclusive range of cards on the given
 658   // card liveness bitmap
 659   inline void set_card_bitmap_range(BitMap* card_bm,
 660                                     BitMap::idx_t start_idx,
 661                                     BitMap::idx_t end_idx,
 662                                     bool is_par);
 663 
 664   // Returns the card number of the bottom of the G1 heap.
 665   // Used in biasing indices into accounting card bitmaps.
 666   intptr_t heap_bottom_card_num() const {
 667     return _heap_bottom_card_num;
 668   }
 669 
 670   // Returns the card bitmap for a given task or worker id.
 671   BitMap* count_card_bitmap_for(uint worker_id) {
 672     assert(worker_id < _max_worker_id, "oob");
 673     assert(_count_card_bitmaps != NULL, "uninitialized");
 674     BitMap* task_card_bm = &_count_card_bitmaps[worker_id];
 675     assert(task_card_bm->size() == _card_bm.size(), "size mismatch");
 676     return task_card_bm;
 677   }
 678 
 679   // Returns the array containing the marked bytes for each region,
 680   // for the given worker or task id.
 681   size_t* count_marked_bytes_array_for(uint worker_id) {
 682     assert(worker_id < _max_worker_id, "oob");
 683     assert(_count_marked_bytes != NULL, "uninitialized");
 684     size_t* marked_bytes_array = _count_marked_bytes[worker_id];
 685     assert(marked_bytes_array != NULL, "uninitialized");
 686     return marked_bytes_array;
 687   }
 688 
 689   // Returns the index in the liveness accounting card table bitmap
 690   // for the given address
 691   inline BitMap::idx_t card_bitmap_index_for(HeapWord* addr);
 692 
 693   // Counts the size of the given memory region in the the given
 694   // marked_bytes array slot for the given HeapRegion.
 695   // Sets the bits in the given card bitmap that are associated with the
 696   // cards that are spanned by the memory region.
 697   inline void count_region(MemRegion mr,
 698                            HeapRegion* hr,
 699                            size_t* marked_bytes_array,
 700                            BitMap* task_card_bm);
 701 
 702   // Counts the given object in the given task/worker counting
 703   // data structures.
 704   inline void count_object(oop obj,
 705                            HeapRegion* hr,
 706                            size_t* marked_bytes_array,
 707                            BitMap* task_card_bm,
 708                            size_t word_size);
 709 
 710   // Attempts to mark the given object and, if successful, counts
 711   // the object in the given task/worker counting structures.
 712   inline bool par_mark_and_count(oop obj,
 713                                  HeapRegion* hr,
 714                                  size_t* marked_bytes_array,
 715                                  BitMap* task_card_bm);
 716 
 717   // Attempts to mark the given object and, if successful, counts
 718   // the object in the task/worker counting structures for the
 719   // given worker id.
 720   inline bool par_mark_and_count(oop obj,
 721                                  size_t word_size,
 722                                  HeapRegion* hr,
 723                                  uint worker_id);
 724 
 725   // Returns true if initialization was successfully completed.
 726   bool completed_initialization() const {
 727     return _completed_initialization;
 728   }
 729 
 730   ConcurrentGCTimer* gc_timer_cm() const { return _gc_timer_cm; }
 731   G1OldTracer* gc_tracer_cm() const { return _gc_tracer_cm; }
 732 
 733 protected:
 734   // Clear all the per-task bitmaps and arrays used to store the
 735   // counting data.
 736   void clear_all_count_data();
 737 
 738   // Aggregates the counting data for each worker/task
 739   // that was constructed while marking. Also sets
 740   // the amount of marked bytes for each region and
 741   // the top at concurrent mark count.
 742   void aggregate_count_data();
 743 
 744   // Verification routine
 745   void verify_count_data();
 746 };
 747 
 748 // A class representing a marking task.
 749 class G1CMTask : public TerminatorTerminator {
 750 private:
 751   enum PrivateConstants {
 752     // the regular clock call is called once the scanned words reaches
 753     // this limit
 754     words_scanned_period          = 12*1024,
 755     // the regular clock call is called once the number of visited
 756     // references reaches this limit
 757     refs_reached_period           = 384,
 758     // initial value for the hash seed, used in the work stealing code
 759     init_hash_seed                = 17,
 760     // how many entries will be transferred between global stack and
 761     // local queues
 762     global_stack_transfer_size    = 16
 763   };
 764 
 765   uint                        _worker_id;


 827   // dealing with them)
 828   bool                        _draining_satb_buffers;
 829 
 830   // number sequence of past step times
 831   NumberSeq                   _step_times_ms;
 832   // elapsed time of this task
 833   double                      _elapsed_time_ms;
 834   // termination time of this task
 835   double                      _termination_time_ms;
 836   // when this task got into the termination protocol
 837   double                      _termination_start_time_ms;
 838 
 839   // true when the task is during a concurrent phase, false when it is
 840   // in the remark phase (so, in the latter case, we do not have to
 841   // check all the things that we have to check during the concurrent
 842   // phase, i.e. SATB buffer availability...)
 843   bool                        _concurrent;
 844 
 845   TruncatedSeq                _marking_step_diffs_ms;
 846 
 847   // Counting data structures. Embedding the task's marked_bytes_array
 848   // and card bitmap into the actual task saves having to go through
 849   // the ConcurrentMark object.
 850   size_t*                     _marked_bytes_array;
 851   BitMap*                     _card_bm;
 852 
 853   // it updates the local fields after this task has claimed
 854   // a new region to scan
 855   void setup_for_region(HeapRegion* hr);
 856   // it brings up-to-date the limit of the region
 857   void update_region_limit();
 858 
 859   // called when either the words scanned or the refs visited limit
 860   // has been reached
 861   void reached_limit();
 862   // recalculates the words scanned and refs visited limits
 863   void recalculate_limits();
 864   // decreases the words scanned and refs visited limits when we reach
 865   // an expensive operation
 866   void decrease_limits();
 867   // it checks whether the words scanned or refs visited reached their
 868   // respective limit and calls reached_limit() if they have
 869   void check_limits() {
 870     if (_words_scanned >= _words_scanned_limit ||
 871         _refs_reached >= _refs_reached_limit) {
 872       reached_limit();


 919   // Resets the local region fields after a task has finished scanning a
 920   // region; or when they have become stale as a result of the region
 921   // being evacuated.
 922   void giveup_current_region();
 923 
 924   HeapWord* finger()            { return _finger; }
 925 
 926   bool has_aborted()            { return _has_aborted; }
 927   void set_has_aborted()        { _has_aborted = true; }
 928   void clear_has_aborted()      { _has_aborted = false; }
 929   bool has_timed_out()          { return _has_timed_out; }
 930   bool claimed()                { return _claimed; }
 931 
 932   void set_cm_oop_closure(G1CMOopClosure* cm_oop_closure);
 933 
 934   // Increment the number of references this task has visited.
 935   void increment_refs_reached() { ++_refs_reached; }
 936 
 937   // Grey the object by marking it.  If not already marked, push it on
 938   // the local queue if below the finger.
 939   // Precondition: obj is in region.
 940   // Precondition: obj is below region's NTAMS.
 941   inline void make_reference_grey(oop obj, HeapRegion* region);
 942 
 943   // Grey the object (by calling make_grey_reference) if required,
 944   // e.g. obj is below its containing region's NTAMS.
 945   // Precondition: obj is a valid heap object.
 946   inline void deal_with_reference(oop obj);
 947 
 948   // It scans an object and visits its children.
 949   inline void scan_object(oop obj);
 950 
 951   // It pushes an object on the local queue.
 952   inline void push(oop obj);
 953 
 954   // These two move entries to/from the global stack.
 955   void move_entries_to_global_stack();
 956   void get_entries_from_global_stack();
 957 
 958   // It pops and scans objects from the local queue. If partially is
 959   // true, then it stops when the queue size is of a given limit. If
 960   // partially is false, then it stops when the queue is empty.
 961   void drain_local_queue(bool partially);
 962   // It moves entries from the global stack to the local queue and
 963   // drains the local queue. If partially is true, then it stops when
 964   // both the global stack and the local queue reach a given size. If
 965   // partially if false, it tries to empty them totally.
 966   void drain_global_stack(bool partially);
 967   // It keeps picking SATB buffers and processing them until no SATB
 968   // buffers are available.
 969   void drain_satb_buffers();
 970 
 971   // moves the local finger to a new location
 972   inline void move_finger_to(HeapWord* new_finger) {
 973     assert(new_finger >= _finger && new_finger < _region_limit, "invariant");
 974     _finger = new_finger;
 975   }
 976 
 977   G1CMTask(uint worker_id,
 978            G1ConcurrentMark *cm,
 979            size_t* marked_bytes,
 980            BitMap* card_bm,
 981            G1CMTaskQueue* task_queue,
 982            G1CMTaskQueueSet* task_queues);
 983 
 984   // it prints statistics associated with this task
 985   void print_stats();
 986 };
 987 
 988 // Class that's used to to print out per-region liveness
 989 // information. It's currently used at the end of marking and also
 990 // after we sort the old regions at the end of the cleanup operation.
 991 class G1PrintRegionLivenessInfoClosure: public HeapRegionClosure {
 992 private:
 993   // Accumulators for these values.
 994   size_t _total_used_bytes;
 995   size_t _total_capacity_bytes;
 996   size_t _total_prev_live_bytes;
 997   size_t _total_next_live_bytes;
 998 
 999   // Accumulator for the remembered set size
1000   size_t _total_remset_bytes;




 249   // all have been claimed.
 250   HeapRegion* claim_next();
 251 
 252   void cancel_scan();
 253 
 254   // Flag that we're done with root region scanning and notify anyone
 255   // who's waiting on it. If aborted is false, assume that all regions
 256   // have been claimed.
 257   void scan_finished();
 258 
 259   // If CM threads are still scanning root regions, wait until they
 260   // are done. Return true if we had to wait, false otherwise.
 261   bool wait_until_scan_finished();
 262 };
 263 
 264 class ConcurrentMarkThread;
 265 
 266 class G1ConcurrentMark: public CHeapObj<mtGC> {
 267   friend class ConcurrentMarkThread;
 268   friend class G1ParNoteEndTask;
 269   friend class G1VerifyLiveDataClosure;
 270   friend class G1CMRefProcTaskProxy;
 271   friend class G1CMRefProcTaskExecutor;
 272   friend class G1CMKeepAliveAndDrainClosure;
 273   friend class G1CMDrainMarkingStackClosure;
 274   friend class G1CMBitMapClosure;
 275   friend class G1CMConcurrentMarkingTask;
 276   friend class G1CMMarkStack;
 277   friend class G1CMRemarkTask;
 278   friend class G1CMTask;
 279 
 280 protected:
 281   ConcurrentMarkThread* _cmThread;   // The thread doing the work
 282   G1CollectedHeap*      _g1h;        // The heap
 283   uint                  _parallel_marking_threads; // The number of marking
 284                                                    // threads we're using
 285   uint                  _max_parallel_marking_threads; // Max number of marking
 286                                                        // threads we'll ever use
 287   double                _sleep_factor; // How much we have to sleep, with
 288                                        // respect to the work we just did, to
 289                                        // meet the marking overhead goal
 290   double                _marking_task_overhead; // Marking target overhead for
 291                                                 // a single task
 292 
 293   FreeRegionList        _cleanup_list;
 294 
 295   // Concurrent marking support structures
 296   G1CMBitMap              _markBitMap1;
 297   G1CMBitMap              _markBitMap2;
 298   G1CMBitMapRO*           _prevMarkBitMap; // Completed mark bitmap
 299   G1CMBitMap*             _nextMarkBitMap; // Under-construction mark bitmap
 300 
 301   // Liveness count data. After marking G1 iterates over the recently gathered mark
 302   // bitmap and records rough information about liveness on card and region basis.
 303   // This information can be used for e.g. remembered set scrubbing.
 304 
 305   // A set bit indicates whether the given region contains any live object.
 306   BitMap                  _region_live_bm;
 307   // A set bit indicates that the given card contains a live object. 
 308   BitMap                  _card_live_bm;
 309 
 310   // Heap bounds
 311   HeapWord*               _heap_start;
 312   HeapWord*               _heap_end;
 313 
 314   // Root region tracking and claiming
 315   G1CMRootRegions         _root_regions;
 316 
 317   // For gray objects
 318   G1CMMarkStack           _markStack; // Grey objects behind global finger
 319   HeapWord* volatile      _finger;  // The global finger, region aligned,
 320                                     // always points to the end of the
 321                                     // last claimed region
 322 
 323   // Marking tasks
 324   uint                    _max_worker_id;// Maximum worker id
 325   uint                    _active_tasks; // Task num currently active
 326   G1CMTask**              _tasks;        // Task queue array (max_worker_id len)
 327   G1CMTaskQueueSet*       _task_queues;  // Task queue set
 328   ParallelTaskTerminator  _terminator;   // For termination


 362   G1OldTracer*            _gc_tracer_cm;
 363 
 364   // All of these times are in ms
 365   NumberSeq _init_times;
 366   NumberSeq _remark_times;
 367   NumberSeq _remark_mark_times;
 368   NumberSeq _remark_weak_ref_times;
 369   NumberSeq _cleanup_times;
 370   double    _total_counting_time;
 371   double    _total_rs_scrub_time;
 372 
 373   double*   _accum_task_vtime;   // Accumulated task vtime
 374 
 375   WorkGang* _parallel_workers;
 376 
 377   void weakRefsWorkParallelPart(BoolObjectClosure* is_alive, bool purged_classes);
 378   void weakRefsWork(bool clear_all_soft_refs);
 379 
 380   void swapMarkBitMaps();
 381 
 382   // Allocates and returns a zero-ed out "large" bitmap of the given size in bits.
 383   // It is always allocated using virtual memory.
 384   BitMap allocate_large_bitmap(BitMap::idx_t size_in_bits);
 385   // Allocates the memory for all bitmaps used by the concurrent marking.
 386   void allocate_internal_bitmaps();
 387   // Pre-touches the internal bitmaps.
 388   void pretouch_internal_bitmaps();
 389 
 390   // It resets the global marking data structures, as well as the
 391   // task local ones; should be called during initial mark.
 392   void reset();
 393 
 394   // Resets all the marking data structures. Called when we have to restart
 395   // marking or when marking completes (via set_non_marking_state below).
 396   void reset_marking_state(bool clear_overflow = true);
 397 
 398   // We do this after we're done with marking so that the marking data
 399   // structures are initialized to a sensible and predictable state.
 400   void set_non_marking_state();
 401 
 402   // Called to indicate how many threads are currently active.
 403   void set_concurrency(uint active_tasks);
 404 
 405   // It should be called to indicate which phase we're in (concurrent
 406   // mark or remark) and how many threads are currently active.
 407   void set_concurrency_and_phase(uint active_tasks, bool concurrent);
 408 
 409   // Prints all gathered CM-related statistics


 458   G1CMTaskQueue* task_queue(int id) {
 459     assert(0 <= id && id < (int) _active_tasks,
 460            "task queue id not within active bounds");
 461     return (G1CMTaskQueue*) _task_queues->queue(id);
 462   }
 463 
 464   // Returns the task queue set
 465   G1CMTaskQueueSet* task_queues()  { return _task_queues; }
 466 
 467   // Access / manipulation of the overflow flag which is set to
 468   // indicate that the global stack has overflown
 469   bool has_overflown()           { return _has_overflown; }
 470   void set_has_overflown()       { _has_overflown = true; }
 471   void clear_has_overflown()     { _has_overflown = false; }
 472   bool restart_for_overflow()    { return _restart_for_overflow; }
 473 
 474   // Methods to enter the two overflow sync barriers
 475   void enter_first_sync_barrier(uint worker_id);
 476   void enter_second_sync_barrier(uint worker_id);
 477 

















 478   // Card index of the bottom of the G1 heap. Used for biasing indices into
 479   // the card bitmaps.
 480   intptr_t _heap_bottom_card_num;
 481 
 482   // Set to true when initialization is complete
 483   bool _completed_initialization;
 484 
 485   // end_timer, true to end gc timer after ending concurrent phase.
 486   void register_concurrent_phase_end_common(bool end_timer);
 487 
 488   // Clear the given bitmap in parallel using the given WorkGang. If may_yield is
 489   // true, periodically insert checks to see if this method should exit prematurely.
 490   void clear_bitmap(G1CMBitMap* bitmap, WorkGang* workers, bool may_yield);
 491 public:
 492   // Manipulation of the global mark stack.
 493   // The push and pop operations are used by tasks for transfers
 494   // between task-local queues and the global mark stack, and use
 495   // locking for concurrency safety.
 496   bool mark_stack_push(oop* arr, int n) {
 497     _markStack.par_push_arr(arr, n);


 543                    G1RegionToSpaceMapper* next_bitmap_storage);
 544   ~G1ConcurrentMark();
 545 
 546   ConcurrentMarkThread* cmThread() { return _cmThread; }
 547 
 548   G1CMBitMapRO* prevMarkBitMap() const { return _prevMarkBitMap; }
 549   G1CMBitMap*   nextMarkBitMap() const { return _nextMarkBitMap; }
 550 
 551   // Returns the number of GC threads to be used in a concurrent
 552   // phase based on the number of GC threads being used in a STW
 553   // phase.
 554   uint scale_parallel_threads(uint n_par_threads);
 555 
 556   // Calculates the number of GC threads to be used in a concurrent phase.
 557   uint calc_parallel_marking_threads();
 558 
 559   // The following three are interaction between CM and
 560   // G1CollectedHeap
 561 
 562   // This notifies CM that a root during initial-mark needs to be
 563   // grayed. It is MT-safe. hr is the region that






 564   // contains the object and it's passed optionally from callers who
 565   // might already have it (no point in recalculating it).
 566   inline void grayRoot(oop obj,


 567                        HeapRegion* hr = NULL);
 568 
 569   // Prepare internal data structures for the next mark cycle. This includes clearing
 570   // the next mark bitmap and some internal data structures. This method is intended
 571   // to be called concurrently to the mutator. It will yield to safepoint requests.
 572   void cleanup_for_next_mark();
 573 
 574   // Clear the previous marking bitmap during safepoint.
 575   void clear_prev_bitmap(WorkGang* workers);
 576 
 577   // Return whether the next mark bitmap has no marks set. To be used for assertions
 578   // only. Will not yield to pause requests.
 579   bool nextMarkBitmapIsClear();
 580 
 581   // These two do the work that needs to be done before and after the
 582   // initial root checkpoint. Since this checkpoint can be done at two
 583   // different points (i.e. an explicit pause or piggy-backed on a
 584   // young collection), then it's nice to be able to easily share the
 585   // pre/post code. It might be the case that we can put everything in
 586   // the post method. TP


 613 
 614   // Notify data structures that a GC has started.
 615   void note_start_of_gc() {
 616     _markStack.note_start_of_gc();
 617   }
 618 
 619   // Notify data structures that a GC is finished.
 620   void note_end_of_gc() {
 621     _markStack.note_end_of_gc();
 622   }
 623 
 624   // Verify that there are no CSet oops on the stacks (taskqueues /
 625   // global mark stack) and fingers (global / per-task).
 626   // If marking is not in progress, it's a no-op.
 627   void verify_no_cset_oops() PRODUCT_RETURN;
 628 
 629   inline bool isPrevMarked(oop p) const;
 630 
 631   inline bool do_yield_check(uint worker_i = 0);
 632 
 633   // Abandon current marking iteration due to a Full GC.
 634   void abort();
 635 
 636   bool has_aborted()      { return _has_aborted; }
 637 
 638   void print_summary_info();
 639 
 640   void print_worker_threads_on(outputStream* st) const;
 641 
 642   void print_on_error(outputStream* st) const;
 643 
 644   // Attempts to mark the given object on the next mark bitmap.
 645   inline bool par_mark(oop obj);



































































 646 
 647   // Returns true if initialization was successfully completed.
 648   bool completed_initialization() const {
 649     return _completed_initialization;
 650   }
 651 
 652   ConcurrentGCTimer* gc_timer_cm() const { return _gc_timer_cm; }
 653   G1OldTracer* gc_tracer_cm() const { return _gc_tracer_cm; }
 654 
 655 private:
 656   // Clear (Reset) all liveness count data.
 657   void clear_all_live_data(WorkGang* workers);
 658  
 659   // Verify all of the above data structures that they are in initial state.
 660   void verify_all_live_data();
 661 
 662   // Aggregates the per-card liveness data based on the current marking. Also sets
 663   // the amount of marked bytes for each region.
 664   void create_live_data();
 665  
 666    // Verification routine
 667   void verify_live_data();
 668 };
 669 
 670 // A class representing a marking task.
 671 class G1CMTask : public TerminatorTerminator {
 672 private:
 673   enum PrivateConstants {
 674     // the regular clock call is called once the scanned words reaches
 675     // this limit
 676     words_scanned_period          = 12*1024,
 677     // the regular clock call is called once the number of visited
 678     // references reaches this limit
 679     refs_reached_period           = 384,
 680     // initial value for the hash seed, used in the work stealing code
 681     init_hash_seed                = 17,
 682     // how many entries will be transferred between global stack and
 683     // local queues
 684     global_stack_transfer_size    = 16
 685   };
 686 
 687   uint                        _worker_id;


 749   // dealing with them)
 750   bool                        _draining_satb_buffers;
 751 
 752   // number sequence of past step times
 753   NumberSeq                   _step_times_ms;
 754   // elapsed time of this task
 755   double                      _elapsed_time_ms;
 756   // termination time of this task
 757   double                      _termination_time_ms;
 758   // when this task got into the termination protocol
 759   double                      _termination_start_time_ms;
 760 
 761   // true when the task is during a concurrent phase, false when it is
 762   // in the remark phase (so, in the latter case, we do not have to
 763   // check all the things that we have to check during the concurrent
 764   // phase, i.e. SATB buffer availability...)
 765   bool                        _concurrent;
 766 
 767   TruncatedSeq                _marking_step_diffs_ms;
 768 






 769   // it updates the local fields after this task has claimed
 770   // a new region to scan
 771   void setup_for_region(HeapRegion* hr);
 772   // it brings up-to-date the limit of the region
 773   void update_region_limit();
 774 
 775   // called when either the words scanned or the refs visited limit
 776   // has been reached
 777   void reached_limit();
 778   // recalculates the words scanned and refs visited limits
 779   void recalculate_limits();
 780   // decreases the words scanned and refs visited limits when we reach
 781   // an expensive operation
 782   void decrease_limits();
 783   // it checks whether the words scanned or refs visited reached their
 784   // respective limit and calls reached_limit() if they have
 785   void check_limits() {
 786     if (_words_scanned >= _words_scanned_limit ||
 787         _refs_reached >= _refs_reached_limit) {
 788       reached_limit();


 835   // Resets the local region fields after a task has finished scanning a
 836   // region; or when they have become stale as a result of the region
 837   // being evacuated.
 838   void giveup_current_region();
 839 
 840   HeapWord* finger()            { return _finger; }
 841 
 842   bool has_aborted()            { return _has_aborted; }
 843   void set_has_aborted()        { _has_aborted = true; }
 844   void clear_has_aborted()      { _has_aborted = false; }
 845   bool has_timed_out()          { return _has_timed_out; }
 846   bool claimed()                { return _claimed; }
 847 
 848   void set_cm_oop_closure(G1CMOopClosure* cm_oop_closure);
 849 
 850   // Increment the number of references this task has visited.
 851   void increment_refs_reached() { ++_refs_reached; }
 852 
 853   // Grey the object by marking it.  If not already marked, push it on
 854   // the local queue if below the finger.

 855   // Precondition: obj is below region's NTAMS.
 856   inline void make_reference_grey(oop obj);
 857 
 858   // Grey the object (by calling make_grey_reference) if required,
 859   // e.g. obj is below its containing region's NTAMS.
 860   // Precondition: obj is a valid heap object.
 861   inline void deal_with_reference(oop obj);
 862 
 863   // It scans an object and visits its children.
 864   inline void scan_object(oop obj);
 865 
 866   // It pushes an object on the local queue.
 867   inline void push(oop obj);
 868 
 869   // These two move entries to/from the global stack.
 870   void move_entries_to_global_stack();
 871   void get_entries_from_global_stack();
 872 
 873   // It pops and scans objects from the local queue. If partially is
 874   // true, then it stops when the queue size is of a given limit. If
 875   // partially is false, then it stops when the queue is empty.
 876   void drain_local_queue(bool partially);
 877   // It moves entries from the global stack to the local queue and
 878   // drains the local queue. If partially is true, then it stops when
 879   // both the global stack and the local queue reach a given size. If
 880   // partially if false, it tries to empty them totally.
 881   void drain_global_stack(bool partially);
 882   // It keeps picking SATB buffers and processing them until no SATB
 883   // buffers are available.
 884   void drain_satb_buffers();
 885 
 886   // moves the local finger to a new location
 887   inline void move_finger_to(HeapWord* new_finger) {
 888     assert(new_finger >= _finger && new_finger < _region_limit, "invariant");
 889     _finger = new_finger;
 890   }
 891 
 892   G1CMTask(uint worker_id,
 893            G1ConcurrentMark *cm,


 894            G1CMTaskQueue* task_queue,
 895            G1CMTaskQueueSet* task_queues);
 896 
 897   // it prints statistics associated with this task
 898   void print_stats();
 899 };
 900 
 901 // Class that's used to to print out per-region liveness
 902 // information. It's currently used at the end of marking and also
 903 // after we sort the old regions at the end of the cleanup operation.
 904 class G1PrintRegionLivenessInfoClosure: public HeapRegionClosure {
 905 private:
 906   // Accumulators for these values.
 907   size_t _total_used_bytes;
 908   size_t _total_capacity_bytes;
 909   size_t _total_prev_live_bytes;
 910   size_t _total_next_live_bytes;
 911 
 912   // Accumulator for the remembered set size
 913   size_t _total_remset_bytes;


< prev index next >