Skip to content

Commit 7725fe8

Browse files
committed
8299953: Merge ContiguousSpaceDCTOC into DirtyCardToOopClosure
Reviewed-by: tschatzl, iwalulya
1 parent a9b8acb commit 7725fe8

File tree

2 files changed

+75
-145
lines changed

2 files changed

+75
-145
lines changed

src/hotspot/share/gc/shared/space.cpp

+47-95
Original file line numberDiff line numberDiff line change
@@ -49,48 +49,42 @@
4949

5050
HeapWord* DirtyCardToOopClosure::get_actual_top(HeapWord* top,
5151
HeapWord* top_obj) {
52-
if (top_obj != NULL) {
53-
if (_sp->block_is_obj(top_obj)) {
54-
if (cast_to_oop(top_obj)->is_objArray() || cast_to_oop(top_obj)->is_typeArray()) {
55-
// An arrayOop is starting on the dirty card - since we do exact
56-
// store checks for objArrays we are done.
57-
} else {
58-
// Otherwise, it is possible that the object starting on the dirty
59-
// card spans the entire card, and that the store happened on a
60-
// later card. Figure out where the object ends.
61-
top = top_obj + cast_to_oop(top_obj)->size();
62-
}
52+
if (top_obj != NULL && top_obj < (_sp->toContiguousSpace())->top()) {
53+
if (cast_to_oop(top_obj)->is_objArray() || cast_to_oop(top_obj)->is_typeArray()) {
54+
// An arrayOop is starting on the dirty card - since we do exact
55+
// store checks for objArrays we are done.
6356
} else {
64-
top = top_obj;
57+
// Otherwise, it is possible that the object starting on the dirty
58+
// card spans the entire card, and that the store happened on a
59+
// later card. Figure out where the object ends.
60+
assert(_sp->block_size(top_obj) == cast_to_oop(top_obj)->size(),
61+
"Block size and object size mismatch");
62+
top = top_obj + cast_to_oop(top_obj)->size();
6563
}
6664
} else {
67-
assert(top == _sp->end(), "only case where top_obj == NULL");
65+
top = (_sp->toContiguousSpace())->top();
6866
}
6967
return top;
7068
}
7169

7270
void DirtyCardToOopClosure::walk_mem_region(MemRegion mr,
7371
HeapWord* bottom,
7472
HeapWord* top) {
75-
// 1. Blocks may or may not be objects.
76-
// 2. Even when a block_is_obj(), it may not entirely
77-
// occupy the block if the block quantum is larger than
78-
// the object size.
79-
// We can and should try to optimize by calling the non-MemRegion
80-
// version of oop_iterate() for all but the extremal objects
81-
// (for which we need to call the MemRegion version of
82-
// oop_iterate()) To be done post-beta XXX
83-
for (; bottom < top; bottom += _sp->block_size(bottom)) {
84-
// As in the case of contiguous space above, we'd like to
85-
// just use the value returned by oop_iterate to increment the
86-
// current pointer; unfortunately, that won't work in CMS because
87-
// we'd need an interface change (it seems) to have the space
88-
// "adjust the object size" (for instance pad it up to its
89-
// block alignment or minimum block size restrictions. XXX
90-
if (_sp->block_is_obj(bottom) &&
91-
!_sp->obj_allocated_since_save_marks(cast_to_oop(bottom))) {
92-
cast_to_oop(bottom)->oop_iterate(_cl, mr);
93-
}
73+
// Note that this assumption won't hold if we have a concurrent
74+
// collector in this space, which may have freed up objects after
75+
// they were dirtied and before the stop-the-world GC that is
76+
// examining cards here.
77+
assert(bottom < top, "ought to be at least one obj on a dirty card.");
78+
79+
if (_boundary != NULL) {
80+
// We have a boundary outside of which we don't want to look
81+
// at objects, so create a filtering closure around the
82+
// oop closure before walking the region.
83+
FilteringClosure filter(_boundary, _cl);
84+
walk_mem_region_with_cl(mr, bottom, top, &filter);
85+
} else {
86+
// No boundary, simply walk the heap with the oop closure.
87+
walk_mem_region_with_cl(mr, bottom, top, _cl);
9488
}
9589
}
9690

@@ -146,80 +140,38 @@ void DirtyCardToOopClosure::do_MemRegion(MemRegion mr) {
146140
_min_done = bottom;
147141
}
148142

149-
HeapWord* ContiguousSpaceDCTOC::get_actual_top(HeapWord* top,
150-
HeapWord* top_obj) {
151-
if (top_obj != NULL && top_obj < (_sp->toContiguousSpace())->top()) {
152-
if (cast_to_oop(top_obj)->is_objArray() || cast_to_oop(top_obj)->is_typeArray()) {
153-
// An arrayOop is starting on the dirty card - since we do exact
154-
// store checks for objArrays we are done.
155-
} else {
156-
// Otherwise, it is possible that the object starting on the dirty
157-
// card spans the entire card, and that the store happened on a
158-
// later card. Figure out where the object ends.
159-
assert(_sp->block_size(top_obj) == cast_to_oop(top_obj)->size(),
160-
"Block size and object size mismatch");
161-
top = top_obj + cast_to_oop(top_obj)->size();
162-
}
163-
} else {
164-
top = (_sp->toContiguousSpace())->top();
165-
}
166-
return top;
167-
}
168-
169-
void ContiguousSpaceDCTOC::walk_mem_region(MemRegion mr,
170-
HeapWord* bottom,
171-
HeapWord* top) {
172-
// Note that this assumption won't hold if we have a concurrent
173-
// collector in this space, which may have freed up objects after
174-
// they were dirtied and before the stop-the-world GC that is
175-
// examining cards here.
176-
assert(bottom < top, "ought to be at least one obj on a dirty card.");
177-
178-
if (_boundary != NULL) {
179-
// We have a boundary outside of which we don't want to look
180-
// at objects, so create a filtering closure around the
181-
// oop closure before walking the region.
182-
FilteringClosure filter(_boundary, _cl);
183-
walk_mem_region_with_cl(mr, bottom, top, &filter);
184-
} else {
185-
// No boundary, simply walk the heap with the oop closure.
186-
walk_mem_region_with_cl(mr, bottom, top, _cl);
187-
}
188-
189-
}
190-
191143
// We must replicate this so that the static type of "FilteringClosure"
192144
// (see above) is apparent at the oop_iterate calls.
193-
#define ContiguousSpaceDCTOC__walk_mem_region_with_cl_DEFN(ClosureType) \
194-
void ContiguousSpaceDCTOC::walk_mem_region_with_cl(MemRegion mr, \
195-
HeapWord* bottom, \
196-
HeapWord* top, \
197-
ClosureType* cl) { \
198-
bottom += cast_to_oop(bottom)->oop_iterate_size(cl, mr); \
199-
if (bottom < top) { \
200-
HeapWord* next_obj = bottom + cast_to_oop(bottom)->size(); \
201-
while (next_obj < top) { \
202-
/* Bottom lies entirely below top, so we can call the */ \
203-
/* non-memRegion version of oop_iterate below. */ \
204-
cast_to_oop(bottom)->oop_iterate(cl); \
205-
bottom = next_obj; \
206-
next_obj = bottom + cast_to_oop(bottom)->size(); \
207-
} \
208-
/* Last object. */ \
209-
cast_to_oop(bottom)->oop_iterate(cl, mr); \
210-
} \
145+
#define DirtyCardToOopClosure__walk_mem_region_with_cl_DEFN(ClosureType) \
146+
void DirtyCardToOopClosure::walk_mem_region_with_cl(MemRegion mr, \
147+
HeapWord* bottom, \
148+
HeapWord* top, \
149+
ClosureType* cl) { \
150+
bottom += cast_to_oop(bottom)->oop_iterate_size(cl, mr); \
151+
if (bottom < top) { \
152+
HeapWord* next_obj = bottom + cast_to_oop(bottom)->size(); \
153+
while (next_obj < top) { \
154+
/* Bottom lies entirely below top, so we can call the */ \
155+
/* non-memRegion version of oop_iterate below. */ \
156+
cast_to_oop(bottom)->oop_iterate(cl); \
157+
bottom = next_obj; \
158+
next_obj = bottom + cast_to_oop(bottom)->size(); \
159+
} \
160+
/* Last object. */ \
161+
cast_to_oop(bottom)->oop_iterate(cl, mr); \
162+
} \
211163
}
212164

213165
// (There are only two of these, rather than N, because the split is due
214166
// only to the introduction of the FilteringClosure, a local part of the
215167
// impl of this abstraction.)
216-
ContiguousSpaceDCTOC__walk_mem_region_with_cl_DEFN(OopIterateClosure)
217-
ContiguousSpaceDCTOC__walk_mem_region_with_cl_DEFN(FilteringClosure)
168+
DirtyCardToOopClosure__walk_mem_region_with_cl_DEFN(OopIterateClosure)
169+
DirtyCardToOopClosure__walk_mem_region_with_cl_DEFN(FilteringClosure)
218170

219171
DirtyCardToOopClosure*
220172
ContiguousSpace::new_dcto_cl(OopIterateClosure* cl,
221173
HeapWord* boundary) {
222-
return new ContiguousSpaceDCTOC(this, cl, boundary);
174+
return new DirtyCardToOopClosure(this, cl, boundary);
223175
}
224176

225177
void Space::initialize(MemRegion mr,

src/hotspot/share/gc/shared/space.hpp

+28-50
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,18 @@ class Space: public CHeapObj<mtGC> {
226226
virtual void verify() const = 0;
227227
};
228228

229-
// A MemRegionClosure (ResourceObj) whose "do_MemRegion" function applies an
230-
// OopClosure to (the addresses of) all the ref-containing fields that could
231-
// be modified by virtue of the given MemRegion being dirty. (Note that
232-
// because of the imprecise nature of the write barrier, this may iterate
233-
// over oops beyond the region.)
234-
// This base type for dirty card to oop closures handles memory regions
235-
// in non-contiguous spaces with no boundaries, and should be sub-classed
236-
// to support other space types. See ContiguousDCTOC for a sub-class
237-
// that works with ContiguousSpaces.
229+
// A dirty card to oop closure for contiguous spaces (ContiguousSpace and
230+
// sub-classes). It knows how to filter out objects that are outside of the
231+
// _boundary.
232+
// (Note that because of the imprecise nature of the write barrier, this may
233+
// iterate over oops beyond the region.)
234+
//
235+
// Assumptions:
236+
// 1. That the actual top of any area in a memory region
237+
// contained by the space is bounded by the end of the contiguous
238+
// region of the space.
239+
// 2. That the space is really made up of objects and not just
240+
// blocks.
238241

239242
class DirtyCardToOopClosure: public MemRegionClosureRO {
240243
protected:
@@ -255,15 +258,29 @@ class DirtyCardToOopClosure: public MemRegionClosureRO {
255258
// at the top is assumed to start. For example, an object may
256259
// start at the top but actually extend past the assumed top,
257260
// in which case the top becomes the end of the object.
258-
virtual HeapWord* get_actual_top(HeapWord* top, HeapWord* top_obj);
261+
HeapWord* get_actual_top(HeapWord* top, HeapWord* top_obj);
259262

260263
// Walk the given memory region from bottom to (actual) top
261264
// looking for objects and applying the oop closure (_cl) to
262265
// them. The base implementation of this treats the area as
263266
// blocks, where a block may or may not be an object. Sub-
264267
// classes should override this to provide more accurate
265268
// or possibly more efficient walking.
266-
virtual void walk_mem_region(MemRegion mr, HeapWord* bottom, HeapWord* top);
269+
void walk_mem_region(MemRegion mr, HeapWord* bottom, HeapWord* top);
270+
271+
// Walk the given memory region, from bottom to top, applying
272+
// the given oop closure to (possibly) all objects found. The
273+
// given oop closure may or may not be the same as the oop
274+
// closure with which this closure was created, as it may
275+
// be a filtering closure which makes use of the _boundary.
276+
// We offer two signatures, so the FilteringClosure static type is
277+
// apparent.
278+
void walk_mem_region_with_cl(MemRegion mr,
279+
HeapWord* bottom, HeapWord* top,
280+
OopIterateClosure* cl);
281+
void walk_mem_region_with_cl(MemRegion mr,
282+
HeapWord* bottom, HeapWord* top,
283+
FilteringClosure* cl);
267284

268285
public:
269286
DirtyCardToOopClosure(Space* sp, OopIterateClosure* cl,
@@ -508,45 +525,6 @@ class ContiguousSpace: public CompactibleSpace {
508525
void verify() const override;
509526
};
510527

511-
// A dirty card to oop closure for contiguous spaces (ContiguousSpace and
512-
// sub-classes). It knows how to filter out objects that are outside of the
513-
// _boundary.
514-
//
515-
// Assumptions:
516-
// 1. That the actual top of any area in a memory region
517-
// contained by the space is bounded by the end of the contiguous
518-
// region of the space.
519-
// 2. That the space is really made up of objects and not just
520-
// blocks.
521-
class ContiguousSpaceDCTOC : public DirtyCardToOopClosure {
522-
// Overrides.
523-
void walk_mem_region(MemRegion mr,
524-
HeapWord* bottom, HeapWord* top) override;
525-
526-
HeapWord* get_actual_top(HeapWord* top, HeapWord* top_obj) override;
527-
528-
// Walk the given memory region, from bottom to top, applying
529-
// the given oop closure to (possibly) all objects found. The
530-
// given oop closure may or may not be the same as the oop
531-
// closure with which this closure was created, as it may
532-
// be a filtering closure which makes use of the _boundary.
533-
// We offer two signatures, so the FilteringClosure static type is
534-
// apparent.
535-
void walk_mem_region_with_cl(MemRegion mr,
536-
HeapWord* bottom, HeapWord* top,
537-
OopIterateClosure* cl);
538-
void walk_mem_region_with_cl(MemRegion mr,
539-
HeapWord* bottom, HeapWord* top,
540-
FilteringClosure* cl);
541-
542-
public:
543-
ContiguousSpaceDCTOC(ContiguousSpace* sp, OopIterateClosure* cl,
544-
HeapWord* boundary) :
545-
DirtyCardToOopClosure(sp, cl, boundary)
546-
{}
547-
};
548-
549-
550528
#if INCLUDE_SERIALGC
551529

552530
// Class TenuredSpace is used by TenuredGeneration; it supports an efficient

0 commit comments

Comments
 (0)