8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_CONCURRENTMARK_HPP
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_CONCURRENTMARK_HPP
27
28 #include "gc_implementation/g1/heapRegionSet.hpp"
29 #include "gc_implementation/shared/gcId.hpp"
30 #include "utilities/taskqueue.hpp"
31
32 class G1CollectedHeap;
33 class CMTask;
34 typedef GenericTaskQueue<oop, mtGC> CMTaskQueue;
35 typedef GenericTaskQueueSet<CMTaskQueue, mtGC> CMTaskQueueSet;
36
37 // Closure used by CM during concurrent reference discovery
38 // and reference processing (during remarking) to determine
39 // if a particular object is alive. It is primarily used
40 // to determine if referents of discovered reference objects
41 // are alive. An instance is also embedded into the
42 // reference processor as the _is_alive_non_header field
43 class G1CMIsAliveClosure: public BoolObjectClosure {
44 G1CollectedHeap* _g1;
45 public:
46 G1CMIsAliveClosure(G1CollectedHeap* g1) : _g1(g1) { }
47
69 HeapWord* startWord() const { return _bmStartWord; }
70 size_t sizeInWords() const { return _bmWordSize; }
71 // the following is one past the last word in space
72 HeapWord* endWord() const { return _bmStartWord + _bmWordSize; }
73
74 // read marks
75
76 bool isMarked(HeapWord* addr) const {
77 assert(_bmStartWord <= addr && addr < (_bmStartWord + _bmWordSize),
78 "outside underlying space?");
79 return _bm.at(heapWordToOffset(addr));
80 }
81
82 // iteration
83 inline bool iterate(BitMapClosure* cl, MemRegion mr);
84 inline bool iterate(BitMapClosure* cl);
85
86 // Return the address corresponding to the next marked bit at or after
87 // "addr", and before "limit", if "limit" is non-NULL. If there is no
88 // such bit, returns "limit" if that is non-NULL, or else "endWord()".
89 HeapWord* getNextMarkedWordAddress(HeapWord* addr,
90 HeapWord* limit = NULL) const;
91 // Return the address corresponding to the next unmarked bit at or after
92 // "addr", and before "limit", if "limit" is non-NULL. If there is no
93 // such bit, returns "limit" if that is non-NULL, or else "endWord()".
94 HeapWord* getNextUnmarkedWordAddress(HeapWord* addr,
95 HeapWord* limit = NULL) const;
96
97 // conversion utilities
98 HeapWord* offsetToHeapWord(size_t offset) const {
99 return _bmStartWord + (offset << _shifter);
100 }
101 size_t heapWordToOffset(HeapWord* addr) const {
102 return pointer_delta(addr, _bmStartWord) >> _shifter;
103 }
104 int heapWordDiffToOffsetDiff(size_t diff) const;
105
106 // The argument addr should be the start address of a valid object
107 HeapWord* nextObject(HeapWord* addr) {
108 oop obj = (oop) addr;
109 HeapWord* res = addr + obj->size();
110 assert(offsetToHeapWord(heapWordToOffset(res)) == res, "sanity");
111 return res;
112 }
113
114 void print_on_error(outputStream* st, const char* prefix) const;
115
116 // debugging
117 NOT_PRODUCT(bool covers(ReservedSpace rs) const;)
118 };
119
120 class CMBitMap : public CMBitMapRO {
121
459
460 // Verbose level
461 CMVerboseLevel _verbose_level;
462
463 // All of these times are in ms
464 NumberSeq _init_times;
465 NumberSeq _remark_times;
466 NumberSeq _remark_mark_times;
467 NumberSeq _remark_weak_ref_times;
468 NumberSeq _cleanup_times;
469 double _total_counting_time;
470 double _total_rs_scrub_time;
471
472 double* _accum_task_vtime; // Accumulated task vtime
473
474 FlexibleWorkGang* _parallel_workers;
475
476 ForceOverflowSettings _force_overflow_conc;
477 ForceOverflowSettings _force_overflow_stw;
478
479 void weakRefsWork(bool clear_all_soft_refs);
480
481 void swapMarkBitMaps();
482
483 // It resets the global marking data structures, as well as the
484 // task local ones; should be called during initial mark.
485 void reset();
486
487 // Resets all the marking data structures. Called when we have to restart
488 // marking or when marking completes (via set_non_marking_state below).
489 void reset_marking_state(bool clear_overflow = true);
490
491 // We do this after we're done with marking so that the marking data
492 // structures are initialized to a sensible and predictable state.
493 void set_non_marking_state();
494
495 // Called to indicate how many threads are currently active.
496 void set_concurrency(uint active_tasks);
497
498 // It should be called to indicate which phase we're in (concurrent
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_CONCURRENTMARK_HPP
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_CONCURRENTMARK_HPP
27
28 #include "classfile/javaClasses.hpp"
29 #include "gc_implementation/g1/heapRegionSet.hpp"
30 #include "gc_implementation/shared/gcId.hpp"
31 #include "utilities/taskqueue.hpp"
32
33 class G1CollectedHeap;
34 class CMTask;
35 typedef GenericTaskQueue<oop, mtGC> CMTaskQueue;
36 typedef GenericTaskQueueSet<CMTaskQueue, mtGC> CMTaskQueueSet;
37
38 // Closure used by CM during concurrent reference discovery
39 // and reference processing (during remarking) to determine
40 // if a particular object is alive. It is primarily used
41 // to determine if referents of discovered reference objects
42 // are alive. An instance is also embedded into the
43 // reference processor as the _is_alive_non_header field
44 class G1CMIsAliveClosure: public BoolObjectClosure {
45 G1CollectedHeap* _g1;
46 public:
47 G1CMIsAliveClosure(G1CollectedHeap* g1) : _g1(g1) { }
48
70 HeapWord* startWord() const { return _bmStartWord; }
71 size_t sizeInWords() const { return _bmWordSize; }
72 // the following is one past the last word in space
73 HeapWord* endWord() const { return _bmStartWord + _bmWordSize; }
74
75 // read marks
76
77 bool isMarked(HeapWord* addr) const {
78 assert(_bmStartWord <= addr && addr < (_bmStartWord + _bmWordSize),
79 "outside underlying space?");
80 return _bm.at(heapWordToOffset(addr));
81 }
82
83 // iteration
84 inline bool iterate(BitMapClosure* cl, MemRegion mr);
85 inline bool iterate(BitMapClosure* cl);
86
87 // Return the address corresponding to the next marked bit at or after
88 // "addr", and before "limit", if "limit" is non-NULL. If there is no
89 // such bit, returns "limit" if that is non-NULL, or else "endWord()".
90 HeapWord* getNextMarkedWordAddress(const HeapWord* addr,
91 const HeapWord* limit = NULL) const;
92 // Return the address corresponding to the next unmarked bit at or after
93 // "addr", and before "limit", if "limit" is non-NULL. If there is no
94 // such bit, returns "limit" if that is non-NULL, or else "endWord()".
95 HeapWord* getNextUnmarkedWordAddress(const HeapWord* addr,
96 const HeapWord* limit = NULL) const;
97
98 // conversion utilities
99 HeapWord* offsetToHeapWord(size_t offset) const {
100 return _bmStartWord + (offset << _shifter);
101 }
102 size_t heapWordToOffset(const HeapWord* addr) const {
103 return pointer_delta(addr, _bmStartWord) >> _shifter;
104 }
105 int heapWordDiffToOffsetDiff(size_t diff) const;
106
107 // The argument addr should be the start address of a valid object
108 HeapWord* nextObject(HeapWord* addr) {
109 oop obj = (oop) addr;
110 HeapWord* res = addr + obj->size();
111 assert(offsetToHeapWord(heapWordToOffset(res)) == res, "sanity");
112 return res;
113 }
114
115 void print_on_error(outputStream* st, const char* prefix) const;
116
117 // debugging
118 NOT_PRODUCT(bool covers(ReservedSpace rs) const;)
119 };
120
121 class CMBitMap : public CMBitMapRO {
122
460
461 // Verbose level
462 CMVerboseLevel _verbose_level;
463
464 // All of these times are in ms
465 NumberSeq _init_times;
466 NumberSeq _remark_times;
467 NumberSeq _remark_mark_times;
468 NumberSeq _remark_weak_ref_times;
469 NumberSeq _cleanup_times;
470 double _total_counting_time;
471 double _total_rs_scrub_time;
472
473 double* _accum_task_vtime; // Accumulated task vtime
474
475 FlexibleWorkGang* _parallel_workers;
476
477 ForceOverflowSettings _force_overflow_conc;
478 ForceOverflowSettings _force_overflow_stw;
479
480 void weakRefsWorkParallelPart(BoolObjectClosure* is_alive, bool purged_classes);
481 void weakRefsWork(bool clear_all_soft_refs);
482
483 void swapMarkBitMaps();
484
485 // It resets the global marking data structures, as well as the
486 // task local ones; should be called during initial mark.
487 void reset();
488
489 // Resets all the marking data structures. Called when we have to restart
490 // marking or when marking completes (via set_non_marking_state below).
491 void reset_marking_state(bool clear_overflow = true);
492
493 // We do this after we're done with marking so that the marking data
494 // structures are initialized to a sensible and predictable state.
495 void set_non_marking_state();
496
497 // Called to indicate how many threads are currently active.
498 void set_concurrency(uint active_tasks);
499
500 // It should be called to indicate which phase we're in (concurrent
|