Commit 25cd2453 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[cleanup] Make Heap::InToSpace static

Like Heap::InFromSpace, it doesn't use any members, so should be made
static. Also clean up call sites to not call via a heap pointer.

Change-Id: If55484ddac51351d789c73093f1f7ebf1c568bea
Reviewed-on: https://chromium-review.googlesource.com/1088618Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53842}
parent 7f2fc562
...@@ -360,17 +360,20 @@ bool Heap::InFromSpace(HeapObject* heap_object) { ...@@ -360,17 +360,20 @@ bool Heap::InFromSpace(HeapObject* heap_object) {
->IsFlagSet(Page::IN_FROM_SPACE); ->IsFlagSet(Page::IN_FROM_SPACE);
} }
// static
bool Heap::InToSpace(Object* object) { bool Heap::InToSpace(Object* object) {
DCHECK(!HasWeakHeapObjectTag(object)); DCHECK(!HasWeakHeapObjectTag(object));
return object->IsHeapObject() && InToSpace(HeapObject::cast(object)); return object->IsHeapObject() && InToSpace(HeapObject::cast(object));
} }
// static
bool Heap::InToSpace(MaybeObject* object) { bool Heap::InToSpace(MaybeObject* object) {
HeapObject* heap_object; HeapObject* heap_object;
return object->ToStrongOrWeakHeapObject(&heap_object) && return object->ToStrongOrWeakHeapObject(&heap_object) &&
InToSpace(heap_object); InToSpace(heap_object);
} }
// static
bool Heap::InToSpace(HeapObject* heap_object) { bool Heap::InToSpace(HeapObject* heap_object) {
return MemoryChunk::FromHeapObject(heap_object)->IsFlagSet(Page::IN_TO_SPACE); return MemoryChunk::FromHeapObject(heap_object)->IsFlagSet(Page::IN_TO_SPACE);
} }
......
...@@ -1975,16 +1975,14 @@ void Heap::CheckNewSpaceExpansionCriteria() { ...@@ -1975,16 +1975,14 @@ void Heap::CheckNewSpaceExpansionCriteria() {
} }
static bool IsUnscavengedHeapObject(Heap* heap, Object** p) { static bool IsUnscavengedHeapObject(Heap* heap, Object** p) {
return heap->InFromSpace(*p) && return Heap::InFromSpace(*p) &&
!HeapObject::cast(*p)->map_word().IsForwardingAddress(); !HeapObject::cast(*p)->map_word().IsForwardingAddress();
} }
class ScavengeWeakObjectRetainer : public WeakObjectRetainer { class ScavengeWeakObjectRetainer : public WeakObjectRetainer {
public: public:
explicit ScavengeWeakObjectRetainer(Heap* heap) : heap_(heap) {}
virtual Object* RetainAs(Object* object) { virtual Object* RetainAs(Object* object) {
if (!heap_->InFromSpace(object)) { if (!Heap::InFromSpace(object)) {
return object; return object;
} }
...@@ -1994,9 +1992,6 @@ class ScavengeWeakObjectRetainer : public WeakObjectRetainer { ...@@ -1994,9 +1992,6 @@ class ScavengeWeakObjectRetainer : public WeakObjectRetainer {
} }
return nullptr; return nullptr;
} }
private:
Heap* heap_;
}; };
void Heap::EvacuateYoungGeneration() { void Heap::EvacuateYoungGeneration() {
...@@ -2237,7 +2232,7 @@ void Heap::Scavenge() { ...@@ -2237,7 +2232,7 @@ void Heap::Scavenge() {
} }
} }
ScavengeWeakObjectRetainer weak_object_retainer(this); ScavengeWeakObjectRetainer weak_object_retainer;
ProcessYoungWeakReferences(&weak_object_retainer); ProcessYoungWeakReferences(&weak_object_retainer);
// Set age mark. // Set age mark.
...@@ -3812,7 +3807,7 @@ class OldToNewSlotVerifyingVisitor : public SlotVerifyingVisitor { ...@@ -3812,7 +3807,7 @@ class OldToNewSlotVerifyingVisitor : public SlotVerifyingVisitor {
bool ShouldHaveBeenRecorded(HeapObject* host, MaybeObject* target) override { bool ShouldHaveBeenRecorded(HeapObject* host, MaybeObject* target) override {
DCHECK_IMPLIES( DCHECK_IMPLIES(
target->IsStrongOrWeakHeapObject() && heap_->InNewSpace(target), target->IsStrongOrWeakHeapObject() && heap_->InNewSpace(target),
heap_->InToSpace(target)); Heap::InToSpace(target));
return target->IsStrongOrWeakHeapObject() && heap_->InNewSpace(target) && return target->IsStrongOrWeakHeapObject() && heap_->InNewSpace(target) &&
!heap_->InNewSpace(host); !heap_->InNewSpace(host);
} }
......
...@@ -1368,9 +1368,9 @@ class Heap { ...@@ -1368,9 +1368,9 @@ class Heap {
static inline bool InFromSpace(Object* object); static inline bool InFromSpace(Object* object);
static inline bool InFromSpace(MaybeObject* object); static inline bool InFromSpace(MaybeObject* object);
static inline bool InFromSpace(HeapObject* heap_object); static inline bool InFromSpace(HeapObject* heap_object);
inline bool InToSpace(Object* object); static inline bool InToSpace(Object* object);
inline bool InToSpace(MaybeObject* object); static inline bool InToSpace(MaybeObject* object);
inline bool InToSpace(HeapObject* heap_object); static inline bool InToSpace(HeapObject* heap_object);
// Returns whether the object resides in old space. // Returns whether the object resides in old space.
inline bool InOldSpace(Object* object); inline bool InOldSpace(Object* object);
......
...@@ -601,7 +601,7 @@ void IncrementalMarking::UpdateMarkingWorklistAfterScavenge() { ...@@ -601,7 +601,7 @@ void IncrementalMarking::UpdateMarkingWorklistAfterScavenge() {
HeapObject* obj, HeapObject** out) -> bool { HeapObject* obj, HeapObject** out) -> bool {
DCHECK(obj->IsHeapObject()); DCHECK(obj->IsHeapObject());
// Only pointers to from space have to be updated. // Only pointers to from space have to be updated.
if (heap_->InFromSpace(obj)) { if (Heap::InFromSpace(obj)) {
MapWord map_word = obj->map_word(); MapWord map_word = obj->map_word();
if (!map_word.IsForwardingAddress()) { if (!map_word.IsForwardingAddress()) {
// There may be objects on the marking deque that do not exist anymore, // There may be objects on the marking deque that do not exist anymore,
...@@ -615,7 +615,7 @@ void IncrementalMarking::UpdateMarkingWorklistAfterScavenge() { ...@@ -615,7 +615,7 @@ void IncrementalMarking::UpdateMarkingWorklistAfterScavenge() {
DCHECK_IMPLIES(marking_state()->IsWhite(obj), obj->IsFiller()); DCHECK_IMPLIES(marking_state()->IsWhite(obj), obj->IsFiller());
*out = dest; *out = dest;
return true; return true;
} else if (heap_->InToSpace(obj)) { } else if (Heap::InToSpace(obj)) {
// The object may be on a page that was moved in new space. // The object may be on a page that was moved in new space.
DCHECK( DCHECK(
Page::FromAddress(obj->address())->IsFlagSet(Page::SWEEP_TO_ITERATE)); Page::FromAddress(obj->address())->IsFlagSet(Page::SWEEP_TO_ITERATE));
......
...@@ -300,7 +300,7 @@ class FullEvacuationVerifier : public EvacuationVerifier { ...@@ -300,7 +300,7 @@ class FullEvacuationVerifier : public EvacuationVerifier {
if ((*current)->IsHeapObject()) { if ((*current)->IsHeapObject()) {
HeapObject* object = HeapObject::cast(*current); HeapObject* object = HeapObject::cast(*current);
if (heap()->InNewSpace(object)) { if (heap()->InNewSpace(object)) {
CHECK(heap()->InToSpace(object)); CHECK(Heap::InToSpace(object));
} }
CHECK(!MarkCompactCollector::IsOnEvacuationCandidate(object)); CHECK(!MarkCompactCollector::IsOnEvacuationCandidate(object));
} }
...@@ -311,7 +311,7 @@ class FullEvacuationVerifier : public EvacuationVerifier { ...@@ -311,7 +311,7 @@ class FullEvacuationVerifier : public EvacuationVerifier {
HeapObject* object; HeapObject* object;
if ((*current)->ToStrongHeapObject(&object)) { if ((*current)->ToStrongHeapObject(&object)) {
if (heap()->InNewSpace(object)) { if (heap()->InNewSpace(object)) {
CHECK(heap()->InToSpace(object)); CHECK(Heap::InToSpace(object));
} }
CHECK(!MarkCompactCollector::IsOnEvacuationCandidate(object)); CHECK(!MarkCompactCollector::IsOnEvacuationCandidate(object));
} }
...@@ -2859,7 +2859,7 @@ class RememberedSetUpdatingItem : public UpdatingItem { ...@@ -2859,7 +2859,7 @@ class RememberedSetUpdatingItem : public UpdatingItem {
if (!(*slot)->ToStrongOrWeakHeapObject(&heap_object)) { if (!(*slot)->ToStrongOrWeakHeapObject(&heap_object)) {
return REMOVE_SLOT; return REMOVE_SLOT;
} }
if (heap_->InFromSpace(heap_object)) { if (Heap::InFromSpace(heap_object)) {
MapWord map_word = heap_object->map_word(); MapWord map_word = heap_object->map_word();
if (map_word.IsForwardingAddress()) { if (map_word.IsForwardingAddress()) {
HeapObjectReference::Update( HeapObjectReference::Update(
...@@ -2873,10 +2873,10 @@ class RememberedSetUpdatingItem : public UpdatingItem { ...@@ -2873,10 +2873,10 @@ class RememberedSetUpdatingItem : public UpdatingItem {
// callback in to space, the object is still live. // callback in to space, the object is still live.
// Unfortunately, we do not know about the slot. It could be in a // Unfortunately, we do not know about the slot. It could be in a
// just freed free space object. // just freed free space object.
if (heap_->InToSpace(heap_object)) { if (Heap::InToSpace(heap_object)) {
return KEEP_SLOT; return KEEP_SLOT;
} }
} else if (heap_->InToSpace(heap_object)) { } else if (Heap::InToSpace(heap_object)) {
// Slots can point to "to" space if the page has been moved, or if the // Slots can point to "to" space if the page has been moved, or if the
// slot has been recorded multiple times in the remembered set, or // slot has been recorded multiple times in the remembered set, or
// if the slot was already updated during old->old updating. // if the slot was already updated during old->old updating.
...@@ -3451,7 +3451,7 @@ class YoungGenerationEvacuationVerifier : public EvacuationVerifier { ...@@ -3451,7 +3451,7 @@ class YoungGenerationEvacuationVerifier : public EvacuationVerifier {
for (Object** current = start; current < end; current++) { for (Object** current = start; current < end; current++) {
if ((*current)->IsHeapObject()) { if ((*current)->IsHeapObject()) {
HeapObject* object = HeapObject::cast(*current); HeapObject* object = HeapObject::cast(*current);
CHECK_IMPLIES(heap()->InNewSpace(object), heap()->InToSpace(object)); CHECK_IMPLIES(heap()->InNewSpace(object), Heap::InToSpace(object));
} }
} }
} }
...@@ -3459,7 +3459,7 @@ class YoungGenerationEvacuationVerifier : public EvacuationVerifier { ...@@ -3459,7 +3459,7 @@ class YoungGenerationEvacuationVerifier : public EvacuationVerifier {
for (MaybeObject** current = start; current < end; current++) { for (MaybeObject** current = start; current < end; current++) {
HeapObject* object; HeapObject* object;
if ((*current)->ToStrongOrWeakHeapObject(&object)) { if ((*current)->ToStrongOrWeakHeapObject(&object)) {
CHECK_IMPLIES(heap()->InNewSpace(object), heap()->InToSpace(object)); CHECK_IMPLIES(heap()->InNewSpace(object), Heap::InToSpace(object));
} }
} }
} }
...@@ -3482,7 +3482,7 @@ void SeedGlobalHandles(Heap* heap, GlobalHandles* global_handles, ...@@ -3482,7 +3482,7 @@ void SeedGlobalHandles(Heap* heap, GlobalHandles* global_handles,
} }
bool IsUnmarkedObjectForYoungGeneration(Heap* heap, Object** p) { bool IsUnmarkedObjectForYoungGeneration(Heap* heap, Object** p) {
DCHECK_IMPLIES(heap->InNewSpace(*p), heap->InToSpace(*p)); DCHECK_IMPLIES(heap->InNewSpace(*p), Heap::InToSpace(*p));
return heap->InNewSpace(*p) && !heap->minor_mark_compact_collector() return heap->InNewSpace(*p) && !heap->minor_mark_compact_collector()
->non_atomic_marking_state() ->non_atomic_marking_state()
->IsGrey(HeapObject::cast(*p)); ->IsGrey(HeapObject::cast(*p));
...@@ -4089,7 +4089,7 @@ class PageMarkingItem : public MarkingItem { ...@@ -4089,7 +4089,7 @@ class PageMarkingItem : public MarkingItem {
if (heap()->InNewSpace(object)) { if (heap()->InNewSpace(object)) {
// Marking happens before flipping the young generation, so the object // Marking happens before flipping the young generation, so the object
// has to be in ToSpace. // has to be in ToSpace.
DCHECK(heap()->InToSpace(object)); DCHECK(Heap::InToSpace(object));
HeapObject* heap_object; HeapObject* heap_object;
bool success = object->ToStrongOrWeakHeapObject(&heap_object); bool success = object->ToStrongOrWeakHeapObject(&heap_object);
USE(success); USE(success);
......
...@@ -202,7 +202,7 @@ void Scavenger::EvacuateShortcutCandidate(Map* map, HeapObject** slot, ...@@ -202,7 +202,7 @@ void Scavenger::EvacuateShortcutCandidate(Map* map, HeapObject** slot,
void Scavenger::EvacuateObject(HeapObjectReference** slot, Map* map, void Scavenger::EvacuateObject(HeapObjectReference** slot, Map* map,
HeapObject* source) { HeapObject* source) {
SLOW_DCHECK(heap_->InFromSpace(source)); SLOW_DCHECK(Heap::InFromSpace(source));
SLOW_DCHECK(!MapWord::FromMap(map).IsForwardingAddress()); SLOW_DCHECK(!MapWord::FromMap(map).IsForwardingAddress());
int size = source->SizeFromMap(map); int size = source->SizeFromMap(map);
// Cannot use ::cast() below because that would add checks in debug mode // Cannot use ::cast() below because that would add checks in debug mode
...@@ -227,7 +227,7 @@ void Scavenger::EvacuateObject(HeapObjectReference** slot, Map* map, ...@@ -227,7 +227,7 @@ void Scavenger::EvacuateObject(HeapObjectReference** slot, Map* map,
} }
void Scavenger::ScavengeObject(HeapObjectReference** p, HeapObject* object) { void Scavenger::ScavengeObject(HeapObjectReference** p, HeapObject* object) {
DCHECK(heap()->InFromSpace(object)); DCHECK(Heap::InFromSpace(object));
// Synchronized load that consumes the publishing CAS of MigrateObject. // Synchronized load that consumes the publishing CAS of MigrateObject.
MapWord first_word = object->synchronized_map_word(); MapWord first_word = object->synchronized_map_word();
...@@ -236,7 +236,7 @@ void Scavenger::ScavengeObject(HeapObjectReference** p, HeapObject* object) { ...@@ -236,7 +236,7 @@ void Scavenger::ScavengeObject(HeapObjectReference** p, HeapObject* object) {
// copied. // copied.
if (first_word.IsForwardingAddress()) { if (first_word.IsForwardingAddress()) {
HeapObject* dest = first_word.ToForwardingAddress(); HeapObject* dest = first_word.ToForwardingAddress();
DCHECK(heap()->InFromSpace(*p)); DCHECK(Heap::InFromSpace(*p));
if ((*p)->IsWeakHeapObject()) { if ((*p)->IsWeakHeapObject()) {
*p = HeapObjectReference::Weak(dest); *p = HeapObjectReference::Weak(dest);
} else { } else {
...@@ -257,7 +257,7 @@ SlotCallbackResult Scavenger::CheckAndScavengeObject(Heap* heap, ...@@ -257,7 +257,7 @@ SlotCallbackResult Scavenger::CheckAndScavengeObject(Heap* heap,
Address slot_address) { Address slot_address) {
MaybeObject** slot = reinterpret_cast<MaybeObject**>(slot_address); MaybeObject** slot = reinterpret_cast<MaybeObject**>(slot_address);
MaybeObject* object = *slot; MaybeObject* object = *slot;
if (heap->InFromSpace(object)) { if (Heap::InFromSpace(object)) {
HeapObject* heap_object; HeapObject* heap_object;
bool success = object->ToStrongOrWeakHeapObject(&heap_object); bool success = object->ToStrongOrWeakHeapObject(&heap_object);
USE(success); USE(success);
...@@ -272,10 +272,10 @@ SlotCallbackResult Scavenger::CheckAndScavengeObject(Heap* heap, ...@@ -272,10 +272,10 @@ SlotCallbackResult Scavenger::CheckAndScavengeObject(Heap* heap,
// Unfortunately, we do not know about the slot. It could be in a // Unfortunately, we do not know about the slot. It could be in a
// just freed free space object. // just freed free space object.
PageMemoryFence(object); PageMemoryFence(object);
if (heap->InToSpace(object)) { if (Heap::InToSpace(object)) {
return KEEP_SLOT; return KEEP_SLOT;
} }
} else if (heap->InToSpace(object)) { } else if (Heap::InToSpace(object)) {
// Already updated slot. This can happen when processing of the work list // Already updated slot. This can happen when processing of the work list
// is interleaved with processing roots. // is interleaved with processing roots.
return KEEP_SLOT; return KEEP_SLOT;
......
...@@ -52,7 +52,7 @@ class IterateAndScavengePromotedObjectsVisitor final : public ObjectVisitor { ...@@ -52,7 +52,7 @@ class IterateAndScavengePromotedObjectsVisitor final : public ObjectVisitor {
reinterpret_cast<HeapObjectReference**>(slot_address); reinterpret_cast<HeapObjectReference**>(slot_address);
scavenger_->PageMemoryFence(reinterpret_cast<MaybeObject*>(target)); scavenger_->PageMemoryFence(reinterpret_cast<MaybeObject*>(target));
if (heap_->InFromSpace(target)) { if (Heap::InFromSpace(target)) {
scavenger_->ScavengeObject(slot, target); scavenger_->ScavengeObject(slot, target);
bool success = (*slot)->ToStrongOrWeakHeapObject(&target); bool success = (*slot)->ToStrongOrWeakHeapObject(&target);
USE(success); USE(success);
...@@ -61,7 +61,7 @@ class IterateAndScavengePromotedObjectsVisitor final : public ObjectVisitor { ...@@ -61,7 +61,7 @@ class IterateAndScavengePromotedObjectsVisitor final : public ObjectVisitor {
if (heap_->InNewSpace(target)) { if (heap_->InNewSpace(target)) {
SLOW_DCHECK(target->IsHeapObject()); SLOW_DCHECK(target->IsHeapObject());
SLOW_DCHECK(heap_->InToSpace(target)); SLOW_DCHECK(Heap::InToSpace(target));
RememberedSet<OLD_TO_NEW>::Insert(Page::FromAddress(slot_address), RememberedSet<OLD_TO_NEW>::Insert(Page::FromAddress(slot_address),
slot_address); slot_address);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment