Commit 63c4c76c authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[in-place weak refs] Replace WeakCell (object_create_map) in PrototypeInfo.

BUG=v8:7308

Change-Id: Ide6440933d81fa82dd69d9eade9f289880ec0cb2
Reviewed-on: https://chromium-review.googlesource.com/1078308
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53437}
parent 812f2420
......@@ -1166,10 +1166,10 @@ TF_BUILTIN(CreateObjectWithoutProperties, ObjectBuiltinsAssembler) {
Comment("Try loading the prototype info");
Node* prototype_info =
LoadMapPrototypeInfo(LoadMap(prototype), &call_runtime);
Node* weak_cell =
LoadObjectField(prototype_info, PrototypeInfo::kObjectCreateMap);
GotoIf(IsUndefined(weak_cell), &call_runtime);
map.Bind(LoadWeakCellValue(weak_cell, &call_runtime));
TNode<MaybeObject> maybe_map = LoadMaybeWeakObjectField(
prototype_info, PrototypeInfo::kObjectCreateMapOffset);
GotoIf(IsStrongReferenceTo(maybe_map, UndefinedConstant()), &call_runtime);
map.Bind(ToWeakHeapObject(maybe_map, &call_runtime));
Goto(&instantiate_map);
}
......@@ -1261,10 +1261,11 @@ TF_BUILTIN(ObjectCreate, ObjectBuiltinsAssembler) {
Node* prototype_info =
LoadMapPrototypeInfo(LoadMap(prototype), &call_runtime);
Comment("Load ObjectCreateMap from PrototypeInfo");
Node* weak_cell =
LoadObjectField(prototype_info, PrototypeInfo::kObjectCreateMap);
GotoIf(IsUndefined(weak_cell), &call_runtime);
map.Bind(LoadWeakCellValue(weak_cell, &call_runtime));
TNode<MaybeObject> maybe_map = LoadMaybeWeakObjectField(
prototype_info, PrototypeInfo::kObjectCreateMapOffset);
GotoIf(IsStrongReferenceTo(maybe_map, UndefinedConstant()),
&call_runtime);
map.Bind(ToWeakHeapObject(maybe_map, &call_runtime));
Goto(&instantiate_map);
}
......
......@@ -1785,6 +1785,12 @@ TNode<BoolT> CodeStubAssembler::IsWeakReferenceTo(TNode<MaybeObject> object,
BitcastTaggedToWord(value));
}
TNode<BoolT> CodeStubAssembler::IsStrongReferenceTo(TNode<MaybeObject> object,
TNode<Object> value) {
return WordEqual(BitcastMaybeObjectToWord(object),
BitcastTaggedToWord(value));
}
TNode<BoolT> CodeStubAssembler::IsNotWeakReferenceTo(TNode<MaybeObject> object,
TNode<Object> value) {
return WordNotEqual(WordAnd(BitcastMaybeObjectToWord(object),
......
......@@ -710,6 +710,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
TNode<Object> value);
TNode<BoolT> IsNotWeakReferenceTo(TNode<MaybeObject> object,
TNode<Object> value);
TNode<BoolT> IsStrongReferenceTo(TNode<MaybeObject> object,
TNode<Object> value);
TNode<MaybeObject> MakeWeak(TNode<HeapObject> value);
......
......@@ -47,6 +47,7 @@ class JSWeakCollection;
V(Oddball) \
V(PropertyArray) \
V(PropertyCell) \
V(PrototypeInfo) \
V(SeqOneByteString) \
V(SeqTwoByteString) \
V(SharedFunctionInfo) \
......
......@@ -345,6 +345,25 @@ class FeedbackVector::BodyDescriptor final : public BodyDescriptorBase {
}
};
class PrototypeInfo::BodyDescriptor final : public BodyDescriptorBase {
public:
static bool IsValidSlot(Map* map, HeapObject* obj, int offset) {
return offset >= HeapObject::kHeaderSize;
}
template <typename ObjectVisitor>
static inline void IterateBody(Map* map, HeapObject* obj, int object_size,
ObjectVisitor* v) {
IteratePointers(obj, HeapObject::kHeaderSize, kObjectCreateMapOffset, v);
IterateMaybeWeakPointer(obj, kObjectCreateMapOffset, v);
IteratePointers(obj, kObjectCreateMapOffset + kPointerSize, object_size, v);
}
static inline int SizeOf(Map* map, HeapObject* obj) {
return obj->SizeFromMap(map);
}
};
template <JSWeakCollection::BodyVisitingPolicy body_visiting_policy>
class JSWeakCollection::BodyDescriptorImpl final : public BodyDescriptorBase {
public:
......@@ -722,6 +741,9 @@ ReturnType BodyDescriptorApply(InstanceType type, T1 p1, T2 p2, T3 p3, T4 p4) {
if (type == ALLOCATION_SITE_TYPE) {
return Op::template apply<AllocationSite::BodyDescriptor>(p1, p2, p3,
p4);
} else if (type == PROTOTYPE_INFO_TYPE) {
return Op::template apply<PrototypeInfo::BodyDescriptor>(p1, p2, p3,
p4);
} else {
return Op::template apply<StructBodyDescriptor>(p1, p2, p3, p4);
}
......
......@@ -2324,24 +2324,23 @@ ACCESSORS(AsyncGeneratorRequest, value, Object, kValueOffset)
ACCESSORS(AsyncGeneratorRequest, promise, Object, kPromiseOffset)
Map* PrototypeInfo::ObjectCreateMap() {
return Map::cast(WeakCell::cast(object_create_map())->value());
return Map::cast(object_create_map()->ToWeakHeapObject());
}
// static
void PrototypeInfo::SetObjectCreateMap(Handle<PrototypeInfo> info,
Handle<Map> map) {
Handle<WeakCell> cell = Map::WeakCellForMap(map);
info->set_object_create_map(*cell);
info->set_object_create_map(HeapObjectReference::Weak(*map));
}
bool PrototypeInfo::HasObjectCreateMap() {
Object* cache = object_create_map();
return cache->IsWeakCell() && !WeakCell::cast(cache)->cleared();
MaybeObject* cache = object_create_map();
return cache->IsWeakHeapObject();
}
ACCESSORS(PrototypeInfo, weak_cell, Object, kWeakCellOffset)
ACCESSORS(PrototypeInfo, prototype_users, Object, kPrototypeUsersOffset)
ACCESSORS(PrototypeInfo, object_create_map, Object, kObjectCreateMap)
WEAK_ACCESSORS(PrototypeInfo, object_create_map, kObjectCreateMapOffset)
SMI_ACCESSORS(PrototypeInfo, registry_slot, kRegistrySlotOffset)
SMI_ACCESSORS(PrototypeInfo, bit_field, kBitFieldOffset)
BOOL_ACCESSORS(PrototypeInfo, bit_field, should_be_fast_map, kShouldBeFastBit)
......
......@@ -1638,7 +1638,7 @@ void PrototypeInfo::PrototypeInfoPrint(std::ostream& os) { // NOLINT
os << "\n - weak cell: " << Brief(weak_cell());
os << "\n - prototype users: " << Brief(prototype_users());
os << "\n - registry slot: " << registry_slot();
os << "\n - object create map: " << Brief(object_create_map());
os << "\n - object create map: " << MaybeObjectBrief(object_create_map());
os << "\n - should_be_fast_map: " << should_be_fast_map();
os << "\n";
}
......
......@@ -3134,6 +3134,8 @@ VisitorId Map::GetVisitorId(Map* map) {
#undef MAKE_STRUCT_CASE
if (instance_type == ALLOCATION_SITE_TYPE) {
return kVisitAllocationSite;
} else if (instance_type == PROTOTYPE_INFO_TYPE) {
return kVisitPrototypeInfo;
}
return kVisitStruct;
......
......@@ -3023,15 +3023,17 @@ class PrototypeInfo : public Struct {
static const int kPrototypeUsersOffset = kWeakCellOffset + kPointerSize;
static const int kRegistrySlotOffset = kPrototypeUsersOffset + kPointerSize;
static const int kValidityCellOffset = kRegistrySlotOffset + kPointerSize;
static const int kObjectCreateMap = kValidityCellOffset + kPointerSize;
static const int kBitFieldOffset = kObjectCreateMap + kPointerSize;
static const int kObjectCreateMapOffset = kValidityCellOffset + kPointerSize;
static const int kBitFieldOffset = kObjectCreateMapOffset + kPointerSize;
static const int kSize = kBitFieldOffset + kPointerSize;
// Bit field usage.
static const int kShouldBeFastBit = 0;
class BodyDescriptor;
private:
DECL_ACCESSORS(object_create_map, Object)
DECL_ACCESSORS(object_create_map, MaybeObject)
DISALLOW_IMPLICIT_CONSTRUCTORS(PrototypeInfo);
};
......
......@@ -45,6 +45,7 @@ namespace internal {
V(Oddball) \
V(PropertyArray) \
V(PropertyCell) \
V(PrototypeInfo) \
V(SeqOneByteString) \
V(SeqTwoByteString) \
V(SharedFunctionInfo) \
......
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