diff --git a/src/compiler/code-generator.cc b/src/compiler/code-generator.cc index 49441e8f74..828176fa18 100644 --- a/src/compiler/code-generator.cc +++ b/src/compiler/code-generator.cc @@ -202,13 +202,7 @@ bool CodeGenerator::IsMaterializableFromFrame(Handle object, bool CodeGenerator::IsMaterializableFromRoot( Handle object, Heap::RootListIndex* index_return) { if (linkage()->GetIncomingDescriptor()->IsJSFunctionCall()) { -#define IMMORTAL_IMMOVABLE_ROOT(Name) \ - if (*object == isolate()->heap()->root(Heap::k##Name##RootIndex)) { \ - *index_return = Heap::k##Name##RootIndex; \ - return true; \ - } - IMMORTAL_IMMOVABLE_ROOT_LIST(IMMORTAL_IMMOVABLE_ROOT) -#undef IMMORTAL_IMMOVABLE_ROOT + return isolate()->heap()->GetRootListIndex(object, index_return); } return false; } diff --git a/src/heap/heap.cc b/src/heap/heap.cc index c3d4409862..81a446b889 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -4808,6 +4808,20 @@ bool Heap::RootIsImmortalImmovable(int root_index) { } +bool Heap::GetRootListIndex(Handle object, + Heap::RootListIndex* index_return) { + Object* ptr = *object; +#define IMMORTAL_IMMOVABLE_ROOT(Name) \ + if (ptr == roots_[Heap::k##Name##RootIndex]) { \ + *index_return = k##Name##RootIndex; \ + return true; \ + } + IMMORTAL_IMMOVABLE_ROOT_LIST(IMMORTAL_IMMOVABLE_ROOT) +#undef IMMORTAL_IMMOVABLE_ROOT + return false; +} + + #ifdef VERIFY_HEAP void Heap::Verify() { CHECK(HasBeenSetUp()); diff --git a/src/heap/heap.h b/src/heap/heap.h index 574481bd39..aa18fba177 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -1166,6 +1166,10 @@ class Heap { kSmiRootsStart = kStringTableRootIndex + 1 }; + // Get the root list index for {object} if such a root list index exists. + bool GetRootListIndex(Handle object, + Heap::RootListIndex* index_return); + Object* root(RootListIndex index) { return roots_[index]; } STATIC_ASSERT(kUndefinedValueRootIndex ==