src/share/vm/gc_implementation/g1/concurrentMark.hpp

Print this page
rev 6541 : 8055919: Remove dead code in G1 concurrent marking code
Reviewed-by: jmasa, jwilhelm


 666   void clear_concurrent_marking_in_progress() {
 667     _concurrent_marking_in_progress = false;
 668   }
 669 
 670   void update_accum_task_vtime(int i, double vtime) {
 671     _accum_task_vtime[i] += vtime;
 672   }
 673 
 674   double all_task_accum_vtime() {
 675     double ret = 0.0;
 676     for (uint i = 0; i < _max_worker_id; ++i)
 677       ret += _accum_task_vtime[i];
 678     return ret;
 679   }
 680 
 681   // Attempts to steal an object from the task queues of other tasks
 682   bool try_stealing(uint worker_id, int* hash_seed, oop& obj) {
 683     return _task_queues->steal(worker_id, hash_seed, obj);
 684   }
 685 
 686   ConcurrentMark(G1CollectedHeap* g1h, G1RegionToSpaceMapper* prev_bitmap_storage, G1RegionToSpaceMapper* next_bitmap_storage);


 687   ~ConcurrentMark();
 688 
 689   ConcurrentMarkThread* cmThread() { return _cmThread; }
 690 
 691   CMBitMapRO* prevMarkBitMap() const { return _prevMarkBitMap; }
 692   CMBitMap*   nextMarkBitMap() const { return _nextMarkBitMap; }
 693 
 694   // Returns the number of GC threads to be used in a concurrent
 695   // phase based on the number of GC threads being used in a STW
 696   // phase.
 697   uint scale_parallel_threads(uint n_par_threads);
 698 
 699   // Calculates the number of GC threads to be used in a concurrent phase.
 700   uint calc_parallel_marking_threads();
 701 
 702   // The following three are interaction between CM and
 703   // G1CollectedHeap
 704 
 705   // This notifies CM that a root during initial-mark needs to be
 706   // grayed. It is MT-safe. word_size is the size of the object in
 707   // words. It is passed explicitly as sometimes we cannot calculate
 708   // it from the given object because it might be in an inconsistent
 709   // state (e.g., in to-space and being copied). So the caller is
 710   // responsible for dealing with this issue (e.g., get the size from
 711   // the from-space image when the to-space image might be
 712   // inconsistent) and always passing the size. hr is the region that
 713   // contains the object and it's passed optionally from callers who
 714   // might already have it (no point in recalculating it).
 715   inline void grayRoot(oop obj, size_t word_size,
 716                        uint worker_id, HeapRegion* hr = NULL);


 717 
 718   // It iterates over the heap and for each object it comes across it
 719   // will dump the contents of its reference fields, as well as
 720   // liveness information for the object and its referents. The dump
 721   // will be written to a file with the following name:
 722   // G1PrintReachableBaseFile + "." + str.
 723   // vo decides whether the prev (vo == UsePrevMarking), the next
 724   // (vo == UseNextMarking) marking information, or the mark word
 725   // (vo == UseMarkWord) will be used to determine the liveness of
 726   // each object / referent.
 727   // If all is true, all objects in the heap will be dumped, otherwise
 728   // only the live ones. In the dump the following symbols / breviations
 729   // are used:
 730   //   M : an explicitly live object (its bitmap bit is set)
 731   //   > : an implicitly live object (over tams)
 732   //   O : an object outside the G1 heap (typically: in the perm gen)
 733   //   NOT : a reference field whose referent is not live
 734   //   AND MARKED : indicates that an object is both explicitly and
 735   //   implicitly live (it should be one or the other, not both)
 736   void print_reachable(const char* str,
 737                        VerifyOption vo, bool all) PRODUCT_RETURN;

 738 
 739   // Clear the next marking bitmap (will be called concurrently).
 740   void clearNextBitmap();
 741 
 742   // Return whether the next mark bitmap has no marks set. To be used for assertions
 743   // only. Will not yield to pause requests.
 744   bool nextMarkBitmapIsClear();
 745 
 746   // These two do the work that needs to be done before and after the
 747   // initial root checkpoint. Since this checkpoint can be done at two
 748   // different points (i.e. an explicit pause or piggy-backed on a
 749   // young collection), then it's nice to be able to easily share the
 750   // pre/post code. It might be the case that we can put everything in
 751   // the post method. TP
 752   void checkpointRootsInitialPre();
 753   void checkpointRootsInitialPost();
 754 
 755   // Scan all the root regions and mark everything reachable from
 756   // them.
 757   void scanRootRegions();
 758 
 759   // Scan a single root region and mark everything reachable from it.
 760   void scanRootRegion(HeapRegion* hr, uint worker_id);
 761 
 762   // Do concurrent phase of marking, to a tentative transitive closure.
 763   void markFromRoots();
 764 
 765   void checkpointRootsFinal(bool clear_all_soft_refs);
 766   void checkpointRootsFinalWork();
 767   void cleanup();
 768   void completeCleanup();
 769 
 770   // Mark in the previous bitmap.  NB: this is usually read-only, so use
 771   // this carefully!
 772   inline void markPrev(oop p);
 773 
 774   // Clears marks for all objects in the given range, for the prev,
 775   // next, or both bitmaps.  NB: the previous bitmap is usually
 776   // read-only, so use this carefully!
 777   void clearRangePrevBitmap(MemRegion mr);
 778   void clearRangeNextBitmap(MemRegion mr);
 779   void clearRangeBothBitmaps(MemRegion mr);
 780 
 781   // Notify data structures that a GC has started.
 782   void note_start_of_gc() {
 783     _markStack.note_start_of_gc();
 784   }
 785 
 786   // Notify data structures that a GC is finished.
 787   void note_end_of_gc() {
 788     _markStack.note_end_of_gc();
 789   }
 790 
 791   // Verify that there are no CSet oops on the stacks (taskqueues /
 792   // global mark stack), enqueued SATB buffers, per-thread SATB
 793   // buffers, and fingers (global / per-task). The boolean parameters
 794   // decide which of the above data structures to verify. If marking
 795   // is not in progress, it's a no-op.
 796   void verify_no_cset_oops(bool verify_stacks,
 797                            bool verify_enqueued_buffers,
 798                            bool verify_thread_buffers,
 799                            bool verify_fingers) PRODUCT_RETURN;
 800 
 801   bool isMarked(oop p) const {
 802     assert(p != NULL && p->is_oop(), "expected an oop");
 803     HeapWord* addr = (HeapWord*)p;
 804     assert(addr >= _nextMarkBitMap->startWord() ||
 805            addr < _nextMarkBitMap->endWord(), "in a region");
 806 
 807     return _nextMarkBitMap->isMarked(addr);
 808   }
 809 
 810   inline bool not_yet_marked(oop p) const;
 811 
 812   // XXX Debug code
 813   bool containing_card_is_marked(void* p);
 814   bool containing_cards_are_marked(void* start, void* last);
 815 
 816   bool isPrevMarked(oop p) const {
 817     assert(p != NULL && p->is_oop(), "expected an oop");
 818     HeapWord* addr = (HeapWord*)p;
 819     assert(addr >= _prevMarkBitMap->startWord() ||
 820            addr < _prevMarkBitMap->endWord(), "in a region");
 821 
 822     return _prevMarkBitMap->isMarked(addr);
 823   }
 824 
 825   inline bool do_yield_check(uint worker_i = 0);
 826 
 827   // Called to abort the marking cycle after a Full GC takes palce.
 828   void abort();
 829 
 830   bool has_aborted()      { return _has_aborted; }
 831 
 832   const GCId& concurrent_gc_id();
 833 
 834   // This prints the global/local fingers. It is used for debugging.
 835   NOT_PRODUCT(void print_finger();)


 881   }
 882 
 883   // Returns the array containing the marked bytes for each region,
 884   // for the given worker or task id.
 885   size_t* count_marked_bytes_array_for(uint worker_id) {
 886     assert(0 <= worker_id && worker_id < _max_worker_id, "oob");
 887     assert(_count_marked_bytes != NULL, "uninitialized");
 888     size_t* marked_bytes_array = _count_marked_bytes[worker_id];
 889     assert(marked_bytes_array != NULL, "uninitialized");
 890     return marked_bytes_array;
 891   }
 892 
 893   // Returns the index in the liveness accounting card table bitmap
 894   // for the given address
 895   inline BitMap::idx_t card_bitmap_index_for(HeapWord* addr);
 896 
 897   // Counts the size of the given memory region in the the given
 898   // marked_bytes array slot for the given HeapRegion.
 899   // Sets the bits in the given card bitmap that are associated with the
 900   // cards that are spanned by the memory region.
 901   inline void count_region(MemRegion mr, HeapRegion* hr,

 902                            size_t* marked_bytes_array,
 903                            BitMap* task_card_bm);
 904 
 905   // Counts the given memory region in the task/worker counting
 906   // data structures for the given worker id.
 907   inline void count_region(MemRegion mr, HeapRegion* hr, uint worker_id);
 908 
 909   // Counts the given memory region in the task/worker counting
 910   // data structures for the given worker id.
 911   inline void count_region(MemRegion mr, uint worker_id);
 912 
 913   // Counts the given object in the given task/worker counting
 914   // data structures.
 915   inline void count_object(oop obj, HeapRegion* hr,

 916                            size_t* marked_bytes_array,
 917                            BitMap* task_card_bm);
 918 
 919   // Counts the given object in the task/worker counting data
 920   // structures for the given worker id.
 921   inline void count_object(oop obj, HeapRegion* hr, uint worker_id);
 922 
 923   // Attempts to mark the given object and, if successful, counts
 924   // the object in the given task/worker counting structures.
 925   inline bool par_mark_and_count(oop obj, HeapRegion* hr,

 926                                  size_t* marked_bytes_array,
 927                                  BitMap* task_card_bm);
 928 
 929   // Attempts to mark the given object and, if successful, counts
 930   // the object in the task/worker counting structures for the
 931   // given worker id.
 932   inline bool par_mark_and_count(oop obj, size_t word_size,
 933                                  HeapRegion* hr, uint worker_id);
 934 
 935   // Attempts to mark the given object and, if successful, counts
 936   // the object in the task/worker counting structures for the
 937   // given worker id.
 938   inline bool par_mark_and_count(oop obj, HeapRegion* hr, uint worker_id);
 939 
 940   // Similar to the above routine but we don't know the heap region that
 941   // contains the object to be marked/counted, which this routine looks up.
 942   inline bool par_mark_and_count(oop obj, uint worker_id);
 943 
 944   // Similar to the above routine but there are times when we cannot
 945   // safely calculate the size of obj due to races and we, therefore,
 946   // pass the size in as a parameter. It is the caller's reponsibility
 947   // to ensure that the size passed in for obj is valid.
 948   inline bool par_mark_and_count(oop obj, size_t word_size, uint worker_id);
 949 
 950   // Unconditionally mark the given object, and unconditinally count
 951   // the object in the counting structures for worker id 0.
 952   // Should *not* be called from parallel code.
 953   inline bool mark_and_count(oop obj, HeapRegion* hr);
 954 
 955   // Similar to the above routine but we don't know the heap region that
 956   // contains the object to be marked/counted, which this routine looks up.
 957   // Should *not* be called from parallel code.
 958   inline bool mark_and_count(oop obj);
 959 
 960   // Returns true if initialization was successfully completed.
 961   bool completed_initialization() const {
 962     return _completed_initialization;
 963   }
 964 
 965 protected:
 966   // Clear all the per-task bitmaps and arrays used to store the
 967   // counting data.
 968   void clear_all_count_data();
 969 
 970   // Aggregates the counting data for each worker/task
 971   // that was constructed while marking. Also sets
 972   // the amount of marked bytes for each region and
 973   // the top at concurrent mark count.
 974   void aggregate_count_data();
 975 
 976   // Verification routine
 977   void verify_count_data();
 978 };


1210 
1211   // It pops and scans objects from the local queue. If partially is
1212   // true, then it stops when the queue size is of a given limit. If
1213   // partially is false, then it stops when the queue is empty.
1214   void drain_local_queue(bool partially);
1215   // It moves entries from the global stack to the local queue and
1216   // drains the local queue. If partially is true, then it stops when
1217   // both the global stack and the local queue reach a given size. If
1218   // partially if false, it tries to empty them totally.
1219   void drain_global_stack(bool partially);
1220   // It keeps picking SATB buffers and processing them until no SATB
1221   // buffers are available.
1222   void drain_satb_buffers();
1223 
1224   // moves the local finger to a new location
1225   inline void move_finger_to(HeapWord* new_finger) {
1226     assert(new_finger >= _finger && new_finger < _region_limit, "invariant");
1227     _finger = new_finger;
1228   }
1229 
1230   CMTask(uint worker_id, ConcurrentMark *cm,
1231          size_t* marked_bytes, BitMap* card_bm,
1232          CMTaskQueue* task_queue, CMTaskQueueSet* task_queues);



1233 
1234   // it prints statistics associated with this task
1235   void print_stats();
1236 
1237 #if _MARKING_STATS_
1238   void increase_objs_found_on_bitmap() { ++_objs_found_on_bitmap; }
1239 #endif // _MARKING_STATS_
1240 };
1241 
1242 // Class that's used to to print out per-region liveness
1243 // information. It's currently used at the end of marking and also
1244 // after we sort the old regions at the end of the cleanup operation.
1245 class G1PrintRegionLivenessInfoClosure: public HeapRegionClosure {
1246 private:
1247   outputStream* _out;
1248 
1249   // Accumulators for these values.
1250   size_t _total_used_bytes;
1251   size_t _total_capacity_bytes;
1252   size_t _total_prev_live_bytes;




 666   void clear_concurrent_marking_in_progress() {
 667     _concurrent_marking_in_progress = false;
 668   }
 669 
 670   void update_accum_task_vtime(int i, double vtime) {
 671     _accum_task_vtime[i] += vtime;
 672   }
 673 
 674   double all_task_accum_vtime() {
 675     double ret = 0.0;
 676     for (uint i = 0; i < _max_worker_id; ++i)
 677       ret += _accum_task_vtime[i];
 678     return ret;
 679   }
 680 
 681   // Attempts to steal an object from the task queues of other tasks
 682   bool try_stealing(uint worker_id, int* hash_seed, oop& obj) {
 683     return _task_queues->steal(worker_id, hash_seed, obj);
 684   }
 685 
 686   ConcurrentMark(G1CollectedHeap* g1h,
 687                  G1RegionToSpaceMapper* prev_bitmap_storage,
 688                  G1RegionToSpaceMapper* next_bitmap_storage);
 689   ~ConcurrentMark();
 690 
 691   ConcurrentMarkThread* cmThread() { return _cmThread; }
 692 
 693   CMBitMapRO* prevMarkBitMap() const { return _prevMarkBitMap; }
 694   CMBitMap*   nextMarkBitMap() const { return _nextMarkBitMap; }
 695 
 696   // Returns the number of GC threads to be used in a concurrent
 697   // phase based on the number of GC threads being used in a STW
 698   // phase.
 699   uint scale_parallel_threads(uint n_par_threads);
 700 
 701   // Calculates the number of GC threads to be used in a concurrent phase.
 702   uint calc_parallel_marking_threads();
 703 
 704   // The following three are interaction between CM and
 705   // G1CollectedHeap
 706 
 707   // This notifies CM that a root during initial-mark needs to be
 708   // grayed. It is MT-safe. word_size is the size of the object in
 709   // words. It is passed explicitly as sometimes we cannot calculate
 710   // it from the given object because it might be in an inconsistent
 711   // state (e.g., in to-space and being copied). So the caller is
 712   // responsible for dealing with this issue (e.g., get the size from
 713   // the from-space image when the to-space image might be
 714   // inconsistent) and always passing the size. hr is the region that
 715   // contains the object and it's passed optionally from callers who
 716   // might already have it (no point in recalculating it).
 717   inline void grayRoot(oop obj,
 718                        size_t word_size,
 719                        uint worker_id,
 720                        HeapRegion* hr = NULL);
 721 
 722   // It iterates over the heap and for each object it comes across it
 723   // will dump the contents of its reference fields, as well as
 724   // liveness information for the object and its referents. The dump
 725   // will be written to a file with the following name:
 726   // G1PrintReachableBaseFile + "." + str.
 727   // vo decides whether the prev (vo == UsePrevMarking), the next
 728   // (vo == UseNextMarking) marking information, or the mark word
 729   // (vo == UseMarkWord) will be used to determine the liveness of
 730   // each object / referent.
 731   // If all is true, all objects in the heap will be dumped, otherwise
 732   // only the live ones. In the dump the following symbols / breviations
 733   // are used:
 734   //   M : an explicitly live object (its bitmap bit is set)
 735   //   > : an implicitly live object (over tams)
 736   //   O : an object outside the G1 heap (typically: in the perm gen)
 737   //   NOT : a reference field whose referent is not live
 738   //   AND MARKED : indicates that an object is both explicitly and
 739   //   implicitly live (it should be one or the other, not both)
 740   void print_reachable(const char* str,
 741                        VerifyOption vo,
 742                        bool all) PRODUCT_RETURN;
 743 
 744   // Clear the next marking bitmap (will be called concurrently).
 745   void clearNextBitmap();
 746 
 747   // Return whether the next mark bitmap has no marks set. To be used for assertions
 748   // only. Will not yield to pause requests.
 749   bool nextMarkBitmapIsClear();
 750 
 751   // These two do the work that needs to be done before and after the
 752   // initial root checkpoint. Since this checkpoint can be done at two
 753   // different points (i.e. an explicit pause or piggy-backed on a
 754   // young collection), then it's nice to be able to easily share the
 755   // pre/post code. It might be the case that we can put everything in
 756   // the post method. TP
 757   void checkpointRootsInitialPre();
 758   void checkpointRootsInitialPost();
 759 
 760   // Scan all the root regions and mark everything reachable from
 761   // them.
 762   void scanRootRegions();
 763 
 764   // Scan a single root region and mark everything reachable from it.
 765   void scanRootRegion(HeapRegion* hr, uint worker_id);
 766 
 767   // Do concurrent phase of marking, to a tentative transitive closure.
 768   void markFromRoots();
 769 
 770   void checkpointRootsFinal(bool clear_all_soft_refs);
 771   void checkpointRootsFinalWork();
 772   void cleanup();
 773   void completeCleanup();
 774 
 775   // Mark in the previous bitmap.  NB: this is usually read-only, so use
 776   // this carefully!
 777   inline void markPrev(oop p);
 778 
 779   // Clears marks for all objects in the given range, for the prev or
 780   // next bitmaps.  NB: the previous bitmap is usually
 781   // read-only, so use this carefully!
 782   void clearRangePrevBitmap(MemRegion mr);
 783   void clearRangeNextBitmap(MemRegion mr);

 784 
 785   // Notify data structures that a GC has started.
 786   void note_start_of_gc() {
 787     _markStack.note_start_of_gc();
 788   }
 789 
 790   // Notify data structures that a GC is finished.
 791   void note_end_of_gc() {
 792     _markStack.note_end_of_gc();
 793   }
 794 
 795   // Verify that there are no CSet oops on the stacks (taskqueues /
 796   // global mark stack), enqueued SATB buffers, per-thread SATB
 797   // buffers, and fingers (global / per-task). The boolean parameters
 798   // decide which of the above data structures to verify. If marking
 799   // is not in progress, it's a no-op.
 800   void verify_no_cset_oops(bool verify_stacks,
 801                            bool verify_enqueued_buffers,
 802                            bool verify_thread_buffers,
 803                            bool verify_fingers) PRODUCT_RETURN;
 804 















 805   bool isPrevMarked(oop p) const {
 806     assert(p != NULL && p->is_oop(), "expected an oop");
 807     HeapWord* addr = (HeapWord*)p;
 808     assert(addr >= _prevMarkBitMap->startWord() ||
 809            addr < _prevMarkBitMap->endWord(), "in a region");
 810 
 811     return _prevMarkBitMap->isMarked(addr);
 812   }
 813 
 814   inline bool do_yield_check(uint worker_i = 0);
 815 
 816   // Called to abort the marking cycle after a Full GC takes palce.
 817   void abort();
 818 
 819   bool has_aborted()      { return _has_aborted; }
 820 
 821   const GCId& concurrent_gc_id();
 822 
 823   // This prints the global/local fingers. It is used for debugging.
 824   NOT_PRODUCT(void print_finger();)


 870   }
 871 
 872   // Returns the array containing the marked bytes for each region,
 873   // for the given worker or task id.
 874   size_t* count_marked_bytes_array_for(uint worker_id) {
 875     assert(0 <= worker_id && worker_id < _max_worker_id, "oob");
 876     assert(_count_marked_bytes != NULL, "uninitialized");
 877     size_t* marked_bytes_array = _count_marked_bytes[worker_id];
 878     assert(marked_bytes_array != NULL, "uninitialized");
 879     return marked_bytes_array;
 880   }
 881 
 882   // Returns the index in the liveness accounting card table bitmap
 883   // for the given address
 884   inline BitMap::idx_t card_bitmap_index_for(HeapWord* addr);
 885 
 886   // Counts the size of the given memory region in the the given
 887   // marked_bytes array slot for the given HeapRegion.
 888   // Sets the bits in the given card bitmap that are associated with the
 889   // cards that are spanned by the memory region.
 890   inline void count_region(MemRegion mr,
 891                            HeapRegion* hr,
 892                            size_t* marked_bytes_array,
 893                            BitMap* task_card_bm);
 894 
 895   // Counts the given memory region in the task/worker counting
 896   // data structures for the given worker id.
 897   inline void count_region(MemRegion mr, HeapRegion* hr, uint worker_id);
 898 




 899   // Counts the given object in the given task/worker counting
 900   // data structures.
 901   inline void count_object(oop obj,
 902                            HeapRegion* hr,
 903                            size_t* marked_bytes_array,
 904                            BitMap* task_card_bm);
 905 




 906   // Attempts to mark the given object and, if successful, counts
 907   // the object in the given task/worker counting structures.
 908   inline bool par_mark_and_count(oop obj,
 909                                  HeapRegion* hr,
 910                                  size_t* marked_bytes_array,
 911                                  BitMap* task_card_bm);
 912 
 913   // Attempts to mark the given object and, if successful, counts
 914   // the object in the task/worker counting structures for the
 915   // given worker id.
 916   inline bool par_mark_and_count(oop obj,
 917                                  size_t word_size,
 918                                  HeapRegion* hr,
 919                                  uint worker_id);























 920 
 921   // Returns true if initialization was successfully completed.
 922   bool completed_initialization() const {
 923     return _completed_initialization;
 924   }
 925 
 926 protected:
 927   // Clear all the per-task bitmaps and arrays used to store the
 928   // counting data.
 929   void clear_all_count_data();
 930 
 931   // Aggregates the counting data for each worker/task
 932   // that was constructed while marking. Also sets
 933   // the amount of marked bytes for each region and
 934   // the top at concurrent mark count.
 935   void aggregate_count_data();
 936 
 937   // Verification routine
 938   void verify_count_data();
 939 };


1171 
1172   // It pops and scans objects from the local queue. If partially is
1173   // true, then it stops when the queue size is of a given limit. If
1174   // partially is false, then it stops when the queue is empty.
1175   void drain_local_queue(bool partially);
1176   // It moves entries from the global stack to the local queue and
1177   // drains the local queue. If partially is true, then it stops when
1178   // both the global stack and the local queue reach a given size. If
1179   // partially if false, it tries to empty them totally.
1180   void drain_global_stack(bool partially);
1181   // It keeps picking SATB buffers and processing them until no SATB
1182   // buffers are available.
1183   void drain_satb_buffers();
1184 
1185   // moves the local finger to a new location
1186   inline void move_finger_to(HeapWord* new_finger) {
1187     assert(new_finger >= _finger && new_finger < _region_limit, "invariant");
1188     _finger = new_finger;
1189   }
1190 
1191   CMTask(uint worker_id,
1192          ConcurrentMark *cm,
1193          size_t* marked_bytes,
1194          BitMap* card_bm,
1195          CMTaskQueue* task_queue,
1196          CMTaskQueueSet* task_queues);
1197 
1198   // it prints statistics associated with this task
1199   void print_stats();
1200 
1201 #if _MARKING_STATS_
1202   void increase_objs_found_on_bitmap() { ++_objs_found_on_bitmap; }
1203 #endif // _MARKING_STATS_
1204 };
1205 
1206 // Class that's used to to print out per-region liveness
1207 // information. It's currently used at the end of marking and also
1208 // after we sort the old regions at the end of the cleanup operation.
1209 class G1PrintRegionLivenessInfoClosure: public HeapRegionClosure {
1210 private:
1211   outputStream* _out;
1212 
1213   // Accumulators for these values.
1214   size_t _total_used_bytes;
1215   size_t _total_capacity_bytes;
1216   size_t _total_prev_live_bytes;