Commit 71be4434 authored by ishell's avatar ishell Committed by Commit bot

Reland "Prepare to enable in-object properties in subclasses on a case by case basis."

Original issue's description:
> Prepare to enable in-object properties in subclasses on a case by case basis.
>
> Minor cleanup in VisitorId selection.
>
> Committed: https://crrev.com/7c449a62edfc03aed84d94da323dcfe2b51a3600
> Cr-Commit-Position: refs/heads/master@{#32030}

This is a mostly clean reland.

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

Cr-Commit-Position: refs/heads/master@{#32148}
parent 05f01e69
...@@ -79,14 +79,6 @@ StaticVisitorBase::VisitorId StaticVisitorBase::GetVisitorId( ...@@ -79,14 +79,6 @@ StaticVisitorBase::VisitorId StaticVisitorBase::GetVisitorId(
case WEAK_CELL_TYPE: case WEAK_CELL_TYPE:
return kVisitWeakCell; return kVisitWeakCell;
case JS_SET_TYPE:
return GetVisitorIdForSize(kVisitStruct, kVisitStructGeneric,
JSSet::kSize, has_unboxed_fields);
case JS_MAP_TYPE:
return GetVisitorIdForSize(kVisitStruct, kVisitStructGeneric,
JSMap::kSize, has_unboxed_fields);
case JS_WEAK_MAP_TYPE: case JS_WEAK_MAP_TYPE:
case JS_WEAK_SET_TYPE: case JS_WEAK_SET_TYPE:
return kVisitJSWeakCollection; return kVisitJSWeakCollection;
...@@ -97,24 +89,16 @@ StaticVisitorBase::VisitorId StaticVisitorBase::GetVisitorId( ...@@ -97,24 +89,16 @@ StaticVisitorBase::VisitorId StaticVisitorBase::GetVisitorId(
case SHARED_FUNCTION_INFO_TYPE: case SHARED_FUNCTION_INFO_TYPE:
return kVisitSharedFunctionInfo; return kVisitSharedFunctionInfo;
case JS_SET_TYPE:
case JS_MAP_TYPE:
case JS_PROXY_TYPE: case JS_PROXY_TYPE:
return GetVisitorIdForSize(kVisitStruct, kVisitStructGeneric,
JSProxy::kSize, has_unboxed_fields);
case JS_FUNCTION_PROXY_TYPE: case JS_FUNCTION_PROXY_TYPE:
return GetVisitorIdForSize(kVisitStruct, kVisitStructGeneric, return GetVisitorIdForSize(kVisitStruct, kVisitStructGeneric,
JSFunctionProxy::kSize, has_unboxed_fields); instance_size, has_unboxed_fields);
case FOREIGN_TYPE:
return GetVisitorIdForSize(kVisitDataObject, kVisitDataObjectGeneric,
Foreign::kSize, has_unboxed_fields);
case SYMBOL_TYPE: case SYMBOL_TYPE:
return kVisitSymbol; return kVisitSymbol;
case FILLER_TYPE:
return kVisitDataObjectGeneric;
case JS_ARRAY_BUFFER_TYPE: case JS_ARRAY_BUFFER_TYPE:
return kVisitJSArrayBuffer; return kVisitJSArrayBuffer;
...@@ -144,6 +128,10 @@ StaticVisitorBase::VisitorId StaticVisitorBase::GetVisitorId( ...@@ -144,6 +128,10 @@ StaticVisitorBase::VisitorId StaticVisitorBase::GetVisitorId(
case JS_FUNCTION_TYPE: case JS_FUNCTION_TYPE:
return kVisitJSFunction; return kVisitJSFunction;
case FILLER_TYPE:
if (instance_size == kPointerSize) return kVisitDataObjectGeneric;
// Fall through.
case FOREIGN_TYPE:
case HEAP_NUMBER_TYPE: case HEAP_NUMBER_TYPE:
case MUTABLE_HEAP_NUMBER_TYPE: case MUTABLE_HEAP_NUMBER_TYPE:
case SIMD128_VALUE_TYPE: case SIMD128_VALUE_TYPE:
......
...@@ -11944,6 +11944,76 @@ void JSFunction::SetInitialMap(Handle<JSFunction> function, Handle<Map> map, ...@@ -11944,6 +11944,76 @@ void JSFunction::SetInitialMap(Handle<JSFunction> function, Handle<Map> map,
} }
namespace {
bool CanSubclassHaveInobjectProperties(InstanceType instance_type) {
switch (instance_type) {
case JS_OBJECT_TYPE:
case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
case JS_GENERATOR_OBJECT_TYPE:
case JS_MODULE_TYPE:
case JS_VALUE_TYPE:
case JS_DATE_TYPE:
case JS_ARRAY_TYPE:
case JS_MESSAGE_OBJECT_TYPE:
case JS_SET_ITERATOR_TYPE:
case JS_MAP_ITERATOR_TYPE:
case JS_ITERATOR_RESULT_TYPE:
case JS_PROMISE_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:
case JS_FUNCTION_TYPE:
return false;
case JS_GLOBAL_PROXY_TYPE:
case JS_GLOBAL_OBJECT_TYPE:
case FIXED_ARRAY_TYPE:
case FIXED_DOUBLE_ARRAY_TYPE:
case ODDBALL_TYPE:
case FOREIGN_TYPE:
case MAP_TYPE:
case CODE_TYPE:
case CELL_TYPE:
case PROPERTY_CELL_TYPE:
case WEAK_CELL_TYPE:
case SYMBOL_TYPE:
case BYTECODE_ARRAY_TYPE:
case HEAP_NUMBER_TYPE:
case MUTABLE_HEAP_NUMBER_TYPE:
case SIMD128_VALUE_TYPE:
case FILLER_TYPE:
case BYTE_ARRAY_TYPE:
case FREE_SPACE_TYPE:
case SHARED_FUNCTION_INFO_TYPE:
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
case FIXED_##TYPE##_ARRAY_TYPE:
#undef TYPED_ARRAY_CASE
#define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE:
STRUCT_LIST(MAKE_STRUCT_CASE)
#undef MAKE_STRUCT_CASE
// We must not end up here for these instance types at all.
UNREACHABLE();
// Fall through.
default:
return false;
}
}
} // namespace
void JSFunction::EnsureHasInitialMap(Handle<JSFunction> function) { void JSFunction::EnsureHasInitialMap(Handle<JSFunction> function) {
if (function->has_initial_map()) return; if (function->has_initial_map()) return;
Isolate* isolate = function->GetIsolate(); Isolate* isolate = function->GetIsolate();
...@@ -12018,25 +12088,27 @@ Handle<Map> JSFunction::EnsureDerivedHasInitialMap( ...@@ -12018,25 +12088,27 @@ Handle<Map> JSFunction::EnsureDerivedHasInitialMap(
// Finally link initial map and constructor function if the original // Finally link initial map and constructor function if the original
// constructor is actually a subclass constructor. // constructor is actually a subclass constructor.
if (IsSubclassConstructor(new_target->shared()->kind())) { if (IsSubclassConstructor(new_target->shared()->kind())) {
// TODO(ishell): v8:4531, allow ES6 built-ins subclasses to have // TODO(ishell): v8:4531, allow ES6 built-ins subclasses to have
// in-object properties. // in-object properties.
#if 0
InstanceType instance_type = constructor_initial_map->instance_type(); InstanceType instance_type = constructor_initial_map->instance_type();
int internal_fields = Handle<Map> map;
JSObject::GetInternalFieldCount(*constructor_initial_map); if (CanSubclassHaveInobjectProperties(instance_type)) {
int pre_allocated = constructor_initial_map->GetInObjectProperties() - int internal_fields =
constructor_initial_map->unused_property_fields(); JSObject::GetInternalFieldCount(*constructor_initial_map);
int instance_size; int pre_allocated = constructor_initial_map->GetInObjectProperties() -
int in_object_properties; constructor_initial_map->unused_property_fields();
new_target->CalculateInstanceSizeForDerivedClass( int instance_size;
instance_type, internal_fields, &instance_size, &in_object_properties); int in_object_properties;
new_target->CalculateInstanceSizeForDerivedClass(
int unused_property_fields = in_object_properties - pre_allocated; instance_type, internal_fields, &instance_size,
Handle<Map> map = &in_object_properties);
Map::CopyInitialMap(constructor_initial_map, instance_size,
in_object_properties, unused_property_fields); int unused_property_fields = in_object_properties - pre_allocated;
#endif map = Map::CopyInitialMap(constructor_initial_map, instance_size,
Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); in_object_properties, unused_property_fields);
} else {
map = Map::CopyInitialMap(constructor_initial_map);
}
JSFunction::SetInitialMap(new_target, map, prototype); JSFunction::SetInitialMap(new_target, map, prototype);
map->SetConstructor(*constructor); map->SetConstructor(*constructor);
......
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