Commit a6cd26ee authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

Reland "[heap] Use weak cell in normalized map cache."

This is a reland of f3c8da56
Original change's description:
> [heap] Use weak cell in normalized map cache.
> 
> This replaces ad-hoc weakness in normalized map cache with weak cell.
> 
> Bug: chromium:694255
> Change-Id: I6a12301b2176fe3723b56178a65582cfb412f7d2
> Reviewed-on: https://chromium-review.googlesource.com/704834
> Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#48344}

Bug: chromium:694255
Change-Id: I181a9c02cc934373e40455f1be02f1caf140639b
Reviewed-on: https://chromium-review.googlesource.com/709354Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48442}
parent 6dc38854
...@@ -249,15 +249,11 @@ class ConcurrentMarkingVisitor final ...@@ -249,15 +249,11 @@ class ConcurrentMarkingVisitor final
} }
int VisitNativeContext(Map* map, Context* object) { int VisitNativeContext(Map* map, Context* object) {
if (marking_state_.IsGrey(object)) { if (!ShouldVisit(object)) return 0;
int size = Context::BodyDescriptorWeak::SizeOf(map, object); int size = Context::BodyDescriptorWeak::SizeOf(map, object);
VisitMapPointer(object, object->map_slot()); VisitMapPointer(object, object->map_slot());
Context::BodyDescriptorWeak::IterateBody(object, size, this); Context::BodyDescriptorWeak::IterateBody(object, size, this);
// TODO(ulan): implement proper weakness for normalized map cache return size;
// and remove this bailout.
bailout_.Push(object);
}
return 0;
} }
int VisitTransitionArray(Map* map, TransitionArray* array) { int VisitTransitionArray(Map* map, TransitionArray* array) {
......
...@@ -1470,26 +1470,6 @@ void Heap::EnsureFromSpaceIsCommitted() { ...@@ -1470,26 +1470,6 @@ void Heap::EnsureFromSpaceIsCommitted() {
} }
void Heap::ClearNormalizedMapCaches() {
if (isolate_->bootstrapper()->IsActive() &&
!incremental_marking()->IsMarking()) {
return;
}
Object* context = native_contexts_list();
while (!context->IsUndefined(isolate())) {
// GC can happen when the context is not fully initialized,
// so the cache can be undefined.
Object* cache =
Context::cast(context)->get(Context::NORMALIZED_MAP_CACHE_INDEX);
if (!cache->IsUndefined(isolate())) {
NormalizedMapCache::cast(cache)->Clear();
}
context = Context::cast(context)->next_context_link();
}
}
void Heap::UpdateSurvivalStatistics(int start_new_space_size) { void Heap::UpdateSurvivalStatistics(int start_new_space_size) {
if (start_new_space_size == 0) return; if (start_new_space_size == 0) return;
...@@ -1730,7 +1710,6 @@ void Heap::MarkCompactPrologue() { ...@@ -1730,7 +1710,6 @@ void Heap::MarkCompactPrologue() {
isolate_->compilation_cache()->MarkCompactPrologue(); isolate_->compilation_cache()->MarkCompactPrologue();
FlushNumberStringCache(); FlushNumberStringCache();
ClearNormalizedMapCaches();
} }
......
...@@ -813,8 +813,6 @@ class Heap { ...@@ -813,8 +813,6 @@ class Heap {
// scavenge operation. // scavenge operation.
inline bool ShouldBePromoted(Address old_address); inline bool ShouldBePromoted(Address old_address);
void ClearNormalizedMapCaches();
void IncrementDeferredCount(v8::Isolate::UseCounterFeature feature); void IncrementDeferredCount(v8::Isolate::UseCounterFeature feature);
inline uint32_t HashSeed(); inline uint32_t HashSeed();
......
...@@ -244,22 +244,6 @@ class IncrementalMarkingMarkingVisitor final ...@@ -244,22 +244,6 @@ class IncrementalMarkingMarkingVisitor final
return object_size; return object_size;
} }
V8_INLINE int VisitNativeContext(Map* map, Context* context) {
// We will mark cache black with a separate pass when we finish marking.
// Note that GC can happen when the context is not fully initialized,
// so the cache can be undefined.
Object* cache = context->get(Context::NORMALIZED_MAP_CACHE_INDEX);
if (!cache->IsUndefined(map->GetIsolate())) {
if (cache->IsHeapObject()) {
HeapObject* heap_obj = HeapObject::cast(cache);
// Mark the object grey if it is white, do not enque it into the marking
// deque.
incremental_marking_->marking_state()->WhiteToGrey(heap_obj);
}
}
return Parent::VisitNativeContext(map, context);
}
V8_INLINE void VisitPointer(HeapObject* host, Object** p) final { V8_INLINE void VisitPointer(HeapObject* host, Object** p) final {
Object* target = *p; Object* target = *p;
if (target->IsHeapObject()) { if (target->IsHeapObject()) {
...@@ -898,18 +882,6 @@ void IncrementalMarking::Hurry() { ...@@ -898,18 +882,6 @@ void IncrementalMarking::Hurry() {
} }
} }
} }
Object* context = heap_->native_contexts_list();
while (!context->IsUndefined(heap_->isolate())) {
// GC can happen when the context is not fully initialized,
// so the cache can be undefined.
HeapObject* cache = HeapObject::cast(
Context::cast(context)->get(Context::NORMALIZED_MAP_CACHE_INDEX));
if (!cache->IsUndefined(heap_->isolate())) {
marking_state()->GreyToBlack(cache);
}
context = Context::cast(context)->next_context_link();
}
} }
......
...@@ -1402,8 +1402,10 @@ void NormalizedMapCache::NormalizedMapCacheVerify() { ...@@ -1402,8 +1402,10 @@ void NormalizedMapCache::NormalizedMapCacheVerify() {
Isolate* isolate = GetIsolate(); Isolate* isolate = GetIsolate();
for (int i = 0; i < length(); i++) { for (int i = 0; i < length(); i++) {
Object* e = FixedArray::get(i); Object* e = FixedArray::get(i);
if (e->IsMap()) { if (e->IsWeakCell()) {
Map::cast(e)->DictionaryMapVerify(); if (!WeakCell::cast(e)->cleared()) {
Map::cast(WeakCell::cast(e)->value())->DictionaryMapVerify();
}
} else { } else {
CHECK(e->IsUndefined(isolate)); CHECK(e->IsUndefined(isolate));
} }
......
...@@ -6118,19 +6118,23 @@ MaybeHandle<Map> NormalizedMapCache::Get(Handle<Map> fast_map, ...@@ -6118,19 +6118,23 @@ MaybeHandle<Map> NormalizedMapCache::Get(Handle<Map> fast_map,
PropertyNormalizationMode mode) { PropertyNormalizationMode mode) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
Object* value = FixedArray::get(GetIndex(fast_map)); Object* value = FixedArray::get(GetIndex(fast_map));
if (!value->IsMap() || if (!value->IsWeakCell() || WeakCell::cast(value)->cleared()) {
!Map::cast(value)->EquivalentToForNormalization(*fast_map, mode)) {
return MaybeHandle<Map>(); return MaybeHandle<Map>();
} }
return handle(Map::cast(value));
}
Map* normalized_map = Map::cast(WeakCell::cast(value)->value());
if (!normalized_map->EquivalentToForNormalization(*fast_map, mode)) {
return MaybeHandle<Map>();
}
return handle(normalized_map);
}
void NormalizedMapCache::Set(Handle<Map> fast_map, void NormalizedMapCache::Set(Handle<Map> fast_map, Handle<Map> normalized_map,
Handle<Map> normalized_map) { Handle<WeakCell> normalized_map_weak_cell) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
DCHECK(normalized_map->is_dictionary_map()); DCHECK(normalized_map->is_dictionary_map());
FixedArray::set(GetIndex(fast_map), *normalized_map); DCHECK_EQ(normalized_map_weak_cell->value(), *normalized_map);
FixedArray::set(GetIndex(fast_map), *normalized_map_weak_cell);
} }
...@@ -9037,7 +9041,8 @@ Handle<Map> Map::Normalize(Handle<Map> fast_map, PropertyNormalizationMode mode, ...@@ -9037,7 +9041,8 @@ Handle<Map> Map::Normalize(Handle<Map> fast_map, PropertyNormalizationMode mode,
} else { } else {
new_map = Map::CopyNormalized(fast_map, mode); new_map = Map::CopyNormalized(fast_map, mode);
if (use_cache) { if (use_cache) {
cache->Set(fast_map, new_map); Handle<WeakCell> cell = Map::WeakCellForMap(new_map);
cache->Set(fast_map, new_map, cell);
isolate->counters()->maps_normalized()->Increment(); isolate->counters()->maps_normalized()->Increment();
} }
#if V8_TRACE_MAPS #if V8_TRACE_MAPS
......
...@@ -917,7 +917,8 @@ class NormalizedMapCache : public FixedArray { ...@@ -917,7 +917,8 @@ class NormalizedMapCache : public FixedArray {
MUST_USE_RESULT MaybeHandle<Map> Get(Handle<Map> fast_map, MUST_USE_RESULT MaybeHandle<Map> Get(Handle<Map> fast_map,
PropertyNormalizationMode mode); PropertyNormalizationMode mode);
void Set(Handle<Map> fast_map, Handle<Map> normalized_map); void Set(Handle<Map> fast_map, Handle<Map> normalized_map,
Handle<WeakCell> normalized_map_weak_cell);
void Clear(); void Clear();
......
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