Commit 2af5e365 authored by ishell's avatar ishell Committed by Commit bot

Allow in-object properties in JSCollections, JSWeakCollections and JSRegExp.

BUG=v8:4531
LOG=Y

Review URL: https://codereview.chromium.org/1468933004

Cr-Commit-Position: refs/heads/master@{#32281}
parent 46401fcb
......@@ -386,6 +386,9 @@ void StaticMarkingVisitor<StaticVisitor>::VisitAllocationSite(
template <typename StaticVisitor>
void StaticMarkingVisitor<StaticVisitor>::VisitWeakCollection(
Map* map, HeapObject* object) {
typedef FlexibleBodyVisitor<StaticVisitor,
JSWeakCollection::BodyDescriptorWeak,
void> JSWeakCollectionBodyVisitor;
Heap* heap = map->GetHeap();
JSWeakCollection* weak_collection =
reinterpret_cast<JSWeakCollection*>(object);
......@@ -398,14 +401,7 @@ void StaticMarkingVisitor<StaticVisitor>::VisitWeakCollection(
// Skip visiting the backing hash table containing the mappings and the
// pointer to the other enqueued weak collections, both are post-processed.
StaticVisitor::VisitPointers(
heap, object,
HeapObject::RawField(object, JSWeakCollection::kPropertiesOffset),
HeapObject::RawField(object, JSWeakCollection::kTableOffset));
STATIC_ASSERT(JSWeakCollection::kTableOffset + kPointerSize ==
JSWeakCollection::kNextOffset);
STATIC_ASSERT(JSWeakCollection::kNextOffset + kPointerSize ==
JSWeakCollection::kSize);
JSWeakCollectionBodyVisitor::Visit(map, object);
// Partially initialized weak collection is enqueued, but table is ignored.
if (!weak_collection->table()->IsHashTable()) return;
......@@ -521,9 +517,7 @@ void StaticMarkingVisitor<StaticVisitor>::VisitJSFunction(Map* map,
template <typename StaticVisitor>
void StaticMarkingVisitor<StaticVisitor>::VisitJSRegExp(Map* map,
HeapObject* object) {
typedef FlexibleBodyVisitor<StaticVisitor, JSRegExp::BodyDescriptor, void>
JSRegExpBodyVisitor;
JSRegExpBodyVisitor::Visit(map, object);
JSObjectVisitor::Visit(map, object);
}
......
......@@ -89,8 +89,6 @@ StaticVisitorBase::VisitorId StaticVisitorBase::GetVisitorId(
case SHARED_FUNCTION_INFO_TYPE:
return kVisitSharedFunctionInfo;
case JS_SET_TYPE:
case JS_MAP_TYPE:
case JS_PROXY_TYPE:
case JS_FUNCTION_PROXY_TYPE:
return GetVisitorIdForSize(kVisitStruct, kVisitStructGeneric,
......@@ -118,6 +116,8 @@ StaticVisitorBase::VisitorId StaticVisitorBase::GetVisitorId(
case JS_GLOBAL_PROXY_TYPE:
case JS_GLOBAL_OBJECT_TYPE:
case JS_MESSAGE_OBJECT_TYPE:
case JS_SET_TYPE:
case JS_MAP_TYPE:
case JS_SET_ITERATOR_TYPE:
case JS_MAP_ITERATOR_TYPE:
case JS_ITERATOR_RESULT_TYPE:
......
......@@ -253,36 +253,42 @@ class FixedTypedArrayBase::BodyDescriptor final : public BodyDescriptorBase {
};
class JSWeakCollection::BodyDescriptor final : public BodyDescriptorBase {
template <JSWeakCollection::BodyVisitingPolicy body_visiting_policy>
class JSWeakCollection::BodyDescriptorImpl final : public BodyDescriptorBase {
public:
STATIC_ASSERT(kTableOffset + kPointerSize == kNextOffset);
STATIC_ASSERT(kNextOffset + kPointerSize == kSize);
static bool IsValidSlot(HeapObject* obj, int offset) {
// TODO(ishell): v8:4531, fix when JSWeakCollections are allowed to have
// in-object properties
// return IsValidSlotImpl(obj, offset);
return true;
return IsValidSlotImpl(obj, offset);
}
template <typename ObjectVisitor>
static inline void IterateBody(HeapObject* obj, int object_size,
ObjectVisitor* v) {
IteratePointers(obj, kPropertiesOffset, kSize, v);
// TODO(ishell): v8:4531, fix when JSWeakCollections are allowed to have
// in-object properties
// IterateBodyImpl(obj, kSize, object_size, v);
if (body_visiting_policy == kVisitStrong) {
IterateBodyImpl(obj, kPropertiesOffset, object_size, v);
} else {
IteratePointers(obj, kPropertiesOffset, kTableOffset, v);
IterateBodyImpl(obj, kSize, object_size, v);
}
}
template <typename StaticVisitor>
static inline void IterateBody(HeapObject* obj, int object_size) {
Heap* heap = obj->GetHeap();
IteratePointers<StaticVisitor>(heap, obj, kPropertiesOffset, kSize);
// TODO(ishell): v8:4531, fix when JSWeakCollections are allowed to have
// in-object properties
// IterateBodyImpl<StaticVisitor>(heap, obj, kSize, object_size);
if (body_visiting_policy == kVisitStrong) {
IterateBodyImpl<StaticVisitor>(heap, obj, kPropertiesOffset, object_size);
} else {
IteratePointers<StaticVisitor>(heap, obj, kPropertiesOffset,
kTableOffset);
IterateBodyImpl<StaticVisitor>(heap, obj, kSize, object_size);
}
}
static inline int SizeOf(Map* map, HeapObject* object) { return kSize; }
static inline int SizeOf(Map* map, HeapObject* object) {
return map->instance_size();
}
};
......
......@@ -12057,22 +12057,22 @@ bool CanSubclassHaveInobjectProperties(InstanceType instance_type) {
case JS_DATE_TYPE:
case JS_ARRAY_TYPE:
case JS_MESSAGE_OBJECT_TYPE:
case JS_SET_TYPE:
case JS_MAP_TYPE:
case JS_SET_ITERATOR_TYPE:
case JS_MAP_ITERATOR_TYPE:
case JS_ITERATOR_RESULT_TYPE:
case JS_WEAK_MAP_TYPE:
case JS_WEAK_SET_TYPE:
case JS_PROMISE_TYPE:
case JS_REGEXP_TYPE:
case JS_FUNCTION_TYPE:
return true;
case JS_TYPED_ARRAY_TYPE:
case JS_DATA_VIEW_TYPE:
case JS_REGEXP_TYPE:
case JS_SET_TYPE:
case JS_MAP_TYPE:
case JS_PROXY_TYPE:
case JS_FUNCTION_PROXY_TYPE:
case JS_WEAK_MAP_TYPE:
case JS_WEAK_SET_TYPE:
case JS_ARRAY_BUFFER_TYPE:
return false;
......
......@@ -9840,7 +9840,19 @@ class JSWeakCollection: public JSObject {
static const int kNextOffset = kTableOffset + kPointerSize;
static const int kSize = kNextOffset + kPointerSize;
class BodyDescriptor;
// Visiting policy defines whether the table and next collection fields
// should be visited or not.
enum BodyVisitingPolicy { kVisitStrong, kVisitWeak };
// Iterates the function object according to the visiting policy.
template <BodyVisitingPolicy>
class BodyDescriptorImpl;
// Visit the whole object.
typedef BodyDescriptorImpl<kVisitStrong> BodyDescriptor;
// Don't visit table and next collection fields.
typedef BodyDescriptorImpl<kVisitWeak> BodyDescriptorWeak;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakCollection);
......
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