Reviewers: mvstanton,
Message:
Michael, could you please take a look. If it looks ok, I'll implement other
platforms.
Hannes, Toon, Jakob: this is fyi.
Description:
Use weak cells in map checks in polymorphic ICs.
BUG=v8:3663
LOG=N
Please review this at https://codereview.chromium.org/753993003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+24, -4 lines):
M src/heap/objects-visiting-inl.h
M src/ic/x64/ic-compiler-x64.cc
M src/objects.h
M src/objects.cc
M src/x64/macro-assembler-x64.h
M src/x64/macro-assembler-x64.cc
Index: src/heap/objects-visiting-inl.h
diff --git a/src/heap/objects-visiting-inl.h
b/src/heap/objects-visiting-inl.h
index
1f37306a7cd5438b86dd0c9da3b37c767d112a80..f0637932d6299e9a37c83e074cf8cff59c4b98f9
100644
--- a/src/heap/objects-visiting-inl.h
+++ b/src/heap/objects-visiting-inl.h
@@ -263,9 +263,7 @@ void
StaticMarkingVisitor<StaticVisitor>::VisitCodeTarget(Heap* heap,
// to be serialized.
if (FLAG_cleanup_code_caches_at_gc && target->is_inline_cache_stub() &&
!target->is_call_stub() &&
- (target->ic_state() == MEGAMORPHIC || target->ic_state() == GENERIC |
|
- target->ic_state() == POLYMORPHIC ||
- (heap->flush_monomorphic_ics() && !target->is_weak_stub()) ||
+ ((heap->flush_monomorphic_ics() && !target->is_weak_stub()) ||
heap->isolate()->serializer_enabled() ||
target->ic_age() != heap->global_ic_age() ||
target->is_invalidated_weak_stub())) {
Index: src/ic/x64/ic-compiler-x64.cc
diff --git a/src/ic/x64/ic-compiler-x64.cc b/src/ic/x64/ic-compiler-x64.cc
index
a5848b6dda231369ee78e984bf8542de1487027c..11e6a09ea65dee382a67cb08ef91c690b6a9d7ef
100644
--- a/src/ic/x64/ic-compiler-x64.cc
+++ b/src/ic/x64/ic-compiler-x64.cc
@@ -107,10 +107,11 @@ Handle<Code>
PropertyICCompiler::CompilePolymorphic(TypeHandleList* types,
for (int current = 0; current < receiver_count; ++current) {
Handle<HeapType> type = types->at(current);
Handle<Map> map = IC::TypeToMap(*type, isolate());
+ Handle<WeakCell> cell = Map::WeakCellForMap(map);
if (!map->is_deprecated()) {
number_of_handled_maps++;
// Check map and tail call if there's a match
- __ Cmp(map_reg, map);
+ __ CmpWeakValue(map_reg, scratch2(), cell);
if (type->Is(HeapType::Number())) {
DCHECK(!number_case.is_unused());
__ bind(&number_case);
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
f4d22188b68fa747ae837d0367ab5d9050fb5cc8..aabb65816aefa3c24bd013da62030f42d8574ef7
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -3417,6 +3417,12 @@ bool Map::IsMapInArrayPrototypeChain() {
}
+Handle<WeakCell> Map::WeakCellForMap(Handle<Map> map) {
+ // TODO(ulan): Cache the weak cell and avoid many allocations.
+ return map->GetIsolate()->factory()->NewWeakCell(map);
+}
+
+
static Handle<Map> AddMissingElementsTransitions(Handle<Map> map,
ElementsKind to_kind) {
DCHECK(IsTransitionElementsKind(map->elements_kind()));
@@ -10541,6 +10547,7 @@ Object* Code::FindNthObject(int n, Map* match_map) {
for (RelocIterator it(this, mask); !it.done(); it.next()) {
RelocInfo* info = it.rinfo();
Object* object = info->target_object();
+ if (object->IsWeakCell()) object = WeakCell::cast(object)->value();
if (object->IsHeapObject()) {
if (HeapObject::cast(object)->map() == match_map) {
if (--n == 0) return object;
@@ -10573,6 +10580,7 @@ void Code::FindAndReplace(const
FindAndReplacePattern& pattern) {
RelocInfo* info = it.rinfo();
Object* object = info->target_object();
if (object->IsHeapObject()) {
+ DCHECK(!object->IsWeakCell());
Map* map = HeapObject::cast(object)->map();
if (map == *pattern.find_[current_pattern]) {
info->set_target_object(*pattern.replace_[current_pattern]);
@@ -10591,6 +10599,7 @@ void Code::FindAllMaps(MapHandleList* maps) {
for (RelocIterator it(this, mask); !it.done(); it.next()) {
RelocInfo* info = it.rinfo();
Object* object = info->target_object();
+ if (object->IsWeakCell()) object = WeakCell::cast(object)->value();
if (object->IsMap()) maps->Add(handle(Map::cast(object)));
}
}
@@ -10637,6 +10646,7 @@ MaybeHandle<Code> Code::FindHandlerForMap(Map* map)
{
RelocInfo* info = it.rinfo();
if (info->rmode() == RelocInfo::EMBEDDED_OBJECT) {
Object* object = info->target_object();
+ if (object->IsWeakCell()) object = WeakCell::cast(object)->value();
if (object == map) return_next = true;
} else if (return_next) {
Code* code = Code::GetCodeFromTargetAddress(info->target_address());
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
746f88d1c4c0c10083e63263a005f79ec4378b9d..06b36df03a2789d365d54ed5e02ba8de2b696824
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -6186,6 +6186,8 @@ class Map: public HeapObject {
bool IsMapInArrayPrototypeChain();
+ static Handle<WeakCell> WeakCellForMap(Handle<Map> map);
+
// Dispatched behavior.
DECLARE_PRINTER(Map)
DECLARE_VERIFIER(Map)
Index: src/x64/macro-assembler-x64.cc
diff --git a/src/x64/macro-assembler-x64.cc b/src/x64/macro-assembler-x64.cc
index
d8878a83ee3890a5fa181c0c4124b2e195a6912c..80fc13a2ebcb81d5eaf1a81c8bd4f76faf9f6962
100644
--- a/src/x64/macro-assembler-x64.cc
+++ b/src/x64/macro-assembler-x64.cc
@@ -2852,6 +2852,13 @@ void MacroAssembler::LoadGlobalCell(Register dst,
Handle<Cell> cell) {
}
+void MacroAssembler::CmpWeakValue(Register value, Register scratch,
+ Handle<WeakCell> cell) {
+ Move(scratch, cell, RelocInfo::EMBEDDED_OBJECT);
+ cmpp(value, FieldOperand(scratch, WeakCell::kValueOffset));
+}
+
+
void MacroAssembler::Drop(int stack_elements) {
if (stack_elements > 0) {
addp(rsp, Immediate(stack_elements * kPointerSize));
Index: src/x64/macro-assembler-x64.h
diff --git a/src/x64/macro-assembler-x64.h b/src/x64/macro-assembler-x64.h
index
24eea383949527c3edb7df1e37f34a032884afe3..4d36842e9dee22be0641e8124b69f119503e2044
100644
--- a/src/x64/macro-assembler-x64.h
+++ b/src/x64/macro-assembler-x64.h
@@ -847,6 +847,8 @@ class MacroAssembler: public Assembler {
// Load a global cell into a register.
void LoadGlobalCell(Register dst, Handle<Cell> cell);
+ void CmpWeakValue(Register value, Register scratch, Handle<WeakCell>
cell);
+
// Emit code to discard a non-negative number of pointer-sized elements
// from the stack, clobbering only the rsp register.
void Drop(int stack_elements);
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.