122 public:
123 static size_t compute_size(size_t heap_size);
124 // Returns the amount of bytes on the heap between two marks in the bitmap.
125 static size_t mark_distance();
126 // Returns how many bytes (or bits) of the heap a single byte (or bit) of the
127 // mark bitmap corresponds to. This is the same as the mark distance above.
128 static size_t heap_map_factor() {
129 return mark_distance();
130 }
131
132 G1CMBitMap() : G1CMBitMapRO(LogMinObjAlignment), _listener() { _listener.set_bitmap(this); }
133
134 // Initializes the underlying BitMap to cover the given area.
135 void initialize(MemRegion heap, G1RegionToSpaceMapper* storage);
136
137 // Write marks.
138 inline void mark(HeapWord* addr);
139 inline void clear(HeapWord* addr);
140 inline bool parMark(HeapWord* addr);
141
142 void clearRange(MemRegion mr);
143
144 // Clear the whole mark bitmap.
145 void clearAll();
146 };
147
148 // Represents a marking stack used by ConcurrentMarking in the G1 collector.
149 class G1CMMarkStack VALUE_OBJ_CLASS_SPEC {
150 VirtualSpace _virtual_space; // Underlying backing store for actual stack
151 G1ConcurrentMark* _cm;
152 oop* _base; // bottom of stack
153 jint _index; // one more than last occupied index
154 jint _capacity; // max #elements
155 jint _saved_index; // value of _index saved at start of GC
156
157 bool _overflow;
158 bool _should_expand;
159
160 public:
161 G1CMMarkStack(G1ConcurrentMark* cm);
162 ~G1CMMarkStack();
163
164 bool allocate(size_t capacity);
165
480
481 // An array of bitmaps (one bit map per task). Each bitmap
482 // is used to record the cards spanned by the live objects
483 // marked by that task/worker.
484 BitMap* _count_card_bitmaps;
485
486 // Used to record the number of marked live bytes
487 // (for each region, by worker thread).
488 size_t** _count_marked_bytes;
489
490 // Card index of the bottom of the G1 heap. Used for biasing indices into
491 // the card bitmaps.
492 intptr_t _heap_bottom_card_num;
493
494 // Set to true when initialization is complete
495 bool _completed_initialization;
496
497 // end_timer, true to end gc timer after ending concurrent phase.
498 void register_concurrent_phase_end_common(bool end_timer);
499
500 public:
501 // Manipulation of the global mark stack.
502 // The push and pop operations are used by tasks for transfers
503 // between task-local queues and the global mark stack, and use
504 // locking for concurrency safety.
505 bool mark_stack_push(oop* arr, int n) {
506 _markStack.par_push_arr(arr, n);
507 if (_markStack.overflow()) {
508 set_has_overflown();
509 return false;
510 }
511 return true;
512 }
513 void mark_stack_pop(oop* arr, int max, int* n) {
514 _markStack.par_pop_arr(arr, max, n);
515 }
516 size_t mark_stack_size() { return _markStack.size(); }
517 size_t partial_mark_stack_size_target() { return _markStack.maxElems()/3; }
518 bool mark_stack_overflow() { return _markStack.overflow(); }
519 bool mark_stack_empty() { return _markStack.isEmpty(); }
568 uint calc_parallel_marking_threads();
569
570 // The following three are interaction between CM and
571 // G1CollectedHeap
572
573 // This notifies CM that a root during initial-mark needs to be
574 // grayed. It is MT-safe. word_size is the size of the object in
575 // words. It is passed explicitly as sometimes we cannot calculate
576 // it from the given object because it might be in an inconsistent
577 // state (e.g., in to-space and being copied). So the caller is
578 // responsible for dealing with this issue (e.g., get the size from
579 // the from-space image when the to-space image might be
580 // inconsistent) and always passing the size. hr is the region that
581 // contains the object and it's passed optionally from callers who
582 // might already have it (no point in recalculating it).
583 inline void grayRoot(oop obj,
584 size_t word_size,
585 uint worker_id,
586 HeapRegion* hr = NULL);
587
588 // Clear the next marking bitmap (will be called concurrently).
589 void clearNextBitmap();
590
591 // Return whether the next mark bitmap has no marks set. To be used for assertions
592 // only. Will not yield to pause requests.
593 bool nextMarkBitmapIsClear();
594
595 // These two do the work that needs to be done before and after the
596 // initial root checkpoint. Since this checkpoint can be done at two
597 // different points (i.e. an explicit pause or piggy-backed on a
598 // young collection), then it's nice to be able to easily share the
599 // pre/post code. It might be the case that we can put everything in
600 // the post method. TP
601 void checkpointRootsInitialPre();
602 void checkpointRootsInitialPost();
603
604 // Scan all the root regions and mark everything reachable from
605 // them.
606 void scanRootRegions();
607
608 // Scan a single root region and mark everything reachable from it.
609 void scanRootRegion(HeapRegion* hr, uint worker_id);
|
122 public:
123 static size_t compute_size(size_t heap_size);
124 // Returns the amount of bytes on the heap between two marks in the bitmap.
125 static size_t mark_distance();
126 // Returns how many bytes (or bits) of the heap a single byte (or bit) of the
127 // mark bitmap corresponds to. This is the same as the mark distance above.
128 static size_t heap_map_factor() {
129 return mark_distance();
130 }
131
132 G1CMBitMap() : G1CMBitMapRO(LogMinObjAlignment), _listener() { _listener.set_bitmap(this); }
133
134 // Initializes the underlying BitMap to cover the given area.
135 void initialize(MemRegion heap, G1RegionToSpaceMapper* storage);
136
137 // Write marks.
138 inline void mark(HeapWord* addr);
139 inline void clear(HeapWord* addr);
140 inline bool parMark(HeapWord* addr);
141
142 void clear_range(MemRegion mr);
143 };
144
145 // Represents a marking stack used by ConcurrentMarking in the G1 collector.
146 class G1CMMarkStack VALUE_OBJ_CLASS_SPEC {
147 VirtualSpace _virtual_space; // Underlying backing store for actual stack
148 G1ConcurrentMark* _cm;
149 oop* _base; // bottom of stack
150 jint _index; // one more than last occupied index
151 jint _capacity; // max #elements
152 jint _saved_index; // value of _index saved at start of GC
153
154 bool _overflow;
155 bool _should_expand;
156
157 public:
158 G1CMMarkStack(G1ConcurrentMark* cm);
159 ~G1CMMarkStack();
160
161 bool allocate(size_t capacity);
162
477
478 // An array of bitmaps (one bit map per task). Each bitmap
479 // is used to record the cards spanned by the live objects
480 // marked by that task/worker.
481 BitMap* _count_card_bitmaps;
482
483 // Used to record the number of marked live bytes
484 // (for each region, by worker thread).
485 size_t** _count_marked_bytes;
486
487 // Card index of the bottom of the G1 heap. Used for biasing indices into
488 // the card bitmaps.
489 intptr_t _heap_bottom_card_num;
490
491 // Set to true when initialization is complete
492 bool _completed_initialization;
493
494 // end_timer, true to end gc timer after ending concurrent phase.
495 void register_concurrent_phase_end_common(bool end_timer);
496
497 // Clear the given bitmap in parallel using the given WorkGang. If may_yield is
498 // true, periodically insert checks to see if this method should exit prematurely.
499 void clear_bitmap(G1CMBitMap* bitmap, WorkGang* workers, bool may_yield);
500 public:
501 // Manipulation of the global mark stack.
502 // The push and pop operations are used by tasks for transfers
503 // between task-local queues and the global mark stack, and use
504 // locking for concurrency safety.
505 bool mark_stack_push(oop* arr, int n) {
506 _markStack.par_push_arr(arr, n);
507 if (_markStack.overflow()) {
508 set_has_overflown();
509 return false;
510 }
511 return true;
512 }
513 void mark_stack_pop(oop* arr, int max, int* n) {
514 _markStack.par_pop_arr(arr, max, n);
515 }
516 size_t mark_stack_size() { return _markStack.size(); }
517 size_t partial_mark_stack_size_target() { return _markStack.maxElems()/3; }
518 bool mark_stack_overflow() { return _markStack.overflow(); }
519 bool mark_stack_empty() { return _markStack.isEmpty(); }
568 uint calc_parallel_marking_threads();
569
570 // The following three are interaction between CM and
571 // G1CollectedHeap
572
573 // This notifies CM that a root during initial-mark needs to be
574 // grayed. It is MT-safe. word_size is the size of the object in
575 // words. It is passed explicitly as sometimes we cannot calculate
576 // it from the given object because it might be in an inconsistent
577 // state (e.g., in to-space and being copied). So the caller is
578 // responsible for dealing with this issue (e.g., get the size from
579 // the from-space image when the to-space image might be
580 // inconsistent) and always passing the size. hr is the region that
581 // contains the object and it's passed optionally from callers who
582 // might already have it (no point in recalculating it).
583 inline void grayRoot(oop obj,
584 size_t word_size,
585 uint worker_id,
586 HeapRegion* hr = NULL);
587
588 // Prepare internal data structures for the next mark cycle. This includes clearing
589 // the next mark bitmap and some internal data structures. This method is intended
590 // to be called concurrently to the mutator. It will yield to safepoint requests.
591 void cleanup_for_next_mark();
592
593 // Clear the previous marking bitmap during safepoint.
594 void clear_prev_bitmap(WorkGang* workers);
595
596 // Return whether the next mark bitmap has no marks set. To be used for assertions
597 // only. Will not yield to pause requests.
598 bool nextMarkBitmapIsClear();
599
600 // These two do the work that needs to be done before and after the
601 // initial root checkpoint. Since this checkpoint can be done at two
602 // different points (i.e. an explicit pause or piggy-backed on a
603 // young collection), then it's nice to be able to easily share the
604 // pre/post code. It might be the case that we can put everything in
605 // the post method. TP
606 void checkpointRootsInitialPre();
607 void checkpointRootsInitialPost();
608
609 // Scan all the root regions and mark everything reachable from
610 // them.
611 void scanRootRegions();
612
613 // Scan a single root region and mark everything reachable from it.
614 void scanRootRegion(HeapRegion* hr, uint worker_id);
|