Commit 1077308c authored by Seth Brenith's avatar Seth Brenith Committed by Commit Bot

[cleanup] Make PropertyDescriptorObject inherit from Struct

There is no particular reason that PropertyDescriptorObject should be a
subclass of FixedArray. By using a separate struct type, we get better
generated accessor functions, automatic verification, and runtime type
info, plus we save four bytes per instance.

Change-Id: If076782832aa9398806794e4ee6d019aea2f92b7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1999463Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#65756}
parent 00cd6e0d
......@@ -1085,6 +1085,7 @@ torque_files = [
"src/objects/promise.tq",
"src/objects/property-array.tq",
"src/objects/property-cell.tq",
"src/objects/property-descriptor-object.tq",
"src/objects/prototype-info.tq",
"src/objects/regexp-match-info.tq",
"src/objects/scope-info.tq",
......
......@@ -34,7 +34,7 @@ class ObjectBuiltinsAssembler : public CodeStubAssembler {
Handle<Name> name, TNode<Object> value,
Label* bailout);
TNode<JSObject> FromPropertyDescriptor(TNode<Context> context,
TNode<FixedArray> desc);
TNode<PropertyDescriptorObject> desc);
TNode<JSObject> FromPropertyDetails(TNode<Context> context,
TNode<Object> raw_value,
TNode<Word32T> details,
......@@ -1369,10 +1369,10 @@ TF_BUILTIN(ObjectGetOwnPropertyDescriptor, ObjectBuiltinsAssembler) {
GotoIf(IsUndefined(desc), &return_undefined);
TNode<FixedArray> desc_array = CAST(desc);
TNode<PropertyDescriptorObject> desc_object = CAST(desc);
// 4. Return FromPropertyDescriptor(desc).
TNode<JSObject> js_desc = FromPropertyDescriptor(context, desc_array);
TNode<JSObject> js_desc = FromPropertyDescriptor(context, desc_object);
args.PopAndReturn(js_desc);
}
BIND(&return_undefined);
......@@ -1392,7 +1392,7 @@ void ObjectBuiltinsAssembler::AddToDictionaryIf(
}
TNode<JSObject> ObjectBuiltinsAssembler::FromPropertyDescriptor(
TNode<Context> context, TNode<FixedArray> desc) {
TNode<Context> context, TNode<PropertyDescriptorObject> desc) {
TVARIABLE(JSObject, js_descriptor);
TNode<Int32T> flags = LoadAndUntagToWord32ObjectField(
......
......@@ -274,6 +274,7 @@ Type::bitset BitsetType::Lub(const MapRefLike& map) {
case ACCESSOR_PAIR_TYPE:
case EMBEDDER_DATA_ARRAY_TYPE:
case FIXED_ARRAY_TYPE:
case PROPERTY_DESCRIPTOR_OBJECT_TYPE:
case HASH_TABLE_TYPE:
case ORDERED_HASH_MAP_TYPE:
case ORDERED_HASH_SET_TYPE:
......
......@@ -62,6 +62,7 @@
#include "src/objects/module-inl.h"
#include "src/objects/oddball-inl.h"
#include "src/objects/promise-inl.h"
#include "src/objects/property-descriptor-object-inl.h"
#include "src/objects/stack-frame-info-inl.h"
#include "src/objects/struct-inl.h"
#include "src/objects/template-objects-inl.h"
......
......@@ -58,6 +58,7 @@
#include "src/objects/module-inl.h"
#include "src/objects/oddball-inl.h"
#include "src/objects/promise-inl.h"
#include "src/objects/property-descriptor-object-inl.h"
#include "src/objects/stack-frame-info-inl.h"
#include "src/objects/struct-inl.h"
#include "src/objects/template-objects-inl.h"
......
......@@ -51,6 +51,7 @@
#include "src/objects/microtask-inl.h"
#include "src/objects/module-inl.h"
#include "src/objects/promise-inl.h"
#include "src/objects/property-descriptor-object-inl.h"
#include "src/objects/scope-info.h"
#include "src/objects/stack-frame-info-inl.h"
#include "src/objects/struct-inl.h"
......@@ -706,6 +707,17 @@ Handle<AccessorPair> Factory::NewAccessorPair() {
return accessors;
}
Handle<PropertyDescriptorObject> Factory::NewPropertyDescriptorObject() {
Handle<PropertyDescriptorObject> object =
Handle<PropertyDescriptorObject>::cast(
NewStruct(PROPERTY_DESCRIPTOR_OBJECT_TYPE, AllocationType::kYoung));
object->set_flags(Smi::zero());
object->set_value(*the_hole_value(), SKIP_WRITE_BARRIER);
object->set_get(*the_hole_value(), SKIP_WRITE_BARRIER);
object->set_set(*the_hole_value(), SKIP_WRITE_BARRIER);
return object;
}
// Internalized strings are created in the old generation (data space).
Handle<String> Factory::InternalizeUtf8String(
const Vector<const char>& string) {
......
......@@ -225,6 +225,9 @@ class V8_EXPORT_PRIVATE Factory {
// Create a pre-tenured empty AccessorPair.
Handle<AccessorPair> NewAccessorPair();
// Create a new PropertyDescriptorObject struct.
Handle<PropertyDescriptorObject> NewPropertyDescriptorObject();
// Finds the internalized copy for string in the string table.
// If not found, a new string is added to the table and returned.
Handle<String> InternalizeUtf8String(const Vector<const char>& str);
......
......@@ -34,6 +34,7 @@
#include "src/objects/oddball-inl.h"
#include "src/objects/ordered-hash-table.h"
#include "src/objects/promise.h"
#include "src/objects/property-descriptor-object.h"
#include "src/objects/script.h"
#include "src/objects/shared-function-info.h"
#include "src/objects/smi.h"
......
......@@ -210,13 +210,12 @@ V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
InstanceType instance_type);
// List of object types that have a single unique instance type.
#define INSTANCE_TYPE_CHECKERS_SINGLE(V) \
TORQUE_INSTANCE_CHECKERS_SINGLE_FULLY_DEFINED(V) \
TORQUE_INSTANCE_CHECKERS_SINGLE_ONLY_DECLARED(V) \
V(BigInt, BIGINT_TYPE) \
V(CoverageInfo, FIXED_ARRAY_TYPE) \
V(FixedArrayExact, FIXED_ARRAY_TYPE) \
V(PropertyDescriptorObject, FIXED_ARRAY_TYPE)
#define INSTANCE_TYPE_CHECKERS_SINGLE(V) \
TORQUE_INSTANCE_CHECKERS_SINGLE_FULLY_DEFINED(V) \
TORQUE_INSTANCE_CHECKERS_SINGLE_ONLY_DECLARED(V) \
V(BigInt, BIGINT_TYPE) \
V(CoverageInfo, FIXED_ARRAY_TYPE) \
V(FixedArrayExact, FIXED_ARRAY_TYPE)
#define INSTANCE_TYPE_CHECKERS_RANGE(V) \
TORQUE_INSTANCE_CHECKERS_RANGE_FULLY_DEFINED(V) \
......
......@@ -190,7 +190,6 @@ class ZoneForwardList;
V(PromiseReactionJobTask) \
V(PropertyArray) \
V(PropertyCell) \
V(PropertyDescriptorObject) \
V(RegExpMatchInfo) \
V(ScopeInfo) \
V(ScriptContextTable) \
......
......@@ -138,6 +138,8 @@ namespace internal {
V(_, INTERPRETER_DATA_TYPE, InterpreterData, interpreter_data) \
V(_, PROMISE_CAPABILITY_TYPE, PromiseCapability, promise_capability) \
V(_, PROMISE_REACTION_TYPE, PromiseReaction, promise_reaction) \
V(_, PROPERTY_DESCRIPTOR_OBJECT_TYPE, PropertyDescriptorObject, \
property_descriptor_object) \
V(_, PROTOTYPE_INFO_TYPE, PrototypeInfo, prototype_info) \
V(_, SCRIPT_TYPE, Script, script) \
V(_, SOURCE_TEXT_MODULE_INFO_ENTRY_TYPE, SourceTextModuleInfoEntry, \
......
......@@ -98,6 +98,7 @@
#include "src/objects/microtask-inl.h"
#include "src/objects/module-inl.h"
#include "src/objects/promise-inl.h"
#include "src/objects/property-descriptor-object-inl.h"
#include "src/objects/property-descriptor.h"
#include "src/objects/prototype.h"
#include "src/objects/slots-atomic-inl.h"
......
......@@ -167,6 +167,7 @@
// - StackFrameInfo
// - StackTraceFrame
// - CodeCache
// - PropertyDescriptorObject
// - PrototypeInfo
// - Microtask
// - CallbackTask
......
......@@ -14,8 +14,7 @@
namespace v8 {
namespace internal {
OBJECT_CONSTRUCTORS_IMPL(PropertyDescriptorObject, FixedArray)
CAST_ACCESSOR(PropertyDescriptorObject)
TQ_OBJECT_CONSTRUCTORS_IMPL(PropertyDescriptorObject)
}
} // namespace v8
......
......@@ -6,8 +6,7 @@
#define V8_OBJECTS_PROPERTY_DESCRIPTOR_OBJECT_H_
#include "src/base/bit-field.h"
#include "src/objects/fixed-array.h"
#include "src/objects/objects.h"
#include "src/objects/struct.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
......@@ -15,7 +14,9 @@
namespace v8 {
namespace internal {
class PropertyDescriptorObject : public FixedArray {
class PropertyDescriptorObject
: public TorqueGeneratedPropertyDescriptorObject<PropertyDescriptorObject,
Struct> {
public:
#define FLAGS_BIT_FIELDS(V, _) \
V(IsEnumerableBit, bool, 1, _) \
......@@ -31,10 +32,6 @@ class PropertyDescriptorObject : public FixedArray {
DEFINE_BIT_FIELDS(FLAGS_BIT_FIELDS)
#undef FLAGS_BIT_FIELDS
enum { kFlagsIndex, kValueIndex, kGetIndex, kSetIndex, kLength };
DECL_CAST(PropertyDescriptorObject)
static const int kRegularAccessorPropertyBits =
HasEnumerableBit::kMask | HasConfigurableBit::kMask | HasGetBit::kMask |
HasSetBit::kMask;
......@@ -48,16 +45,7 @@ class PropertyDescriptorObject : public FixedArray {
HasWritableBit::kMask | HasValueBit::kMask |
HasGetBit::kMask | HasSetBit::kMask;
static const int kValueOffset =
FixedArray::OffsetOfElementAt(PropertyDescriptorObject::kValueIndex);
static const int kFlagsOffset =
FixedArray::OffsetOfElementAt(PropertyDescriptorObject::kFlagsIndex);
static const int kGetOffset =
FixedArray::OffsetOfElementAt(PropertyDescriptorObject::kGetIndex);
static const int kSetOffset =
FixedArray::OffsetOfElementAt(PropertyDescriptorObject::kSetIndex);
OBJECT_CONSTRUCTORS(PropertyDescriptorObject, FixedArray);
TQ_OBJECT_CONSTRUCTORS(PropertyDescriptorObject)
};
} // namespace internal
......
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include 'src/objects/property-descriptor-object.h'
@generateCppClass
@generatePrint
extern class PropertyDescriptorObject extends Struct {
flags: Smi;
value: JSAny|TheHole;
get: JSAny|TheHole;
set: JSAny|TheHole;
}
......@@ -341,8 +341,8 @@ void PropertyDescriptor::CompletePropertyDescriptor(Isolate* isolate,
Handle<PropertyDescriptorObject> PropertyDescriptor::ToPropertyDescriptorObject(
Isolate* isolate) {
Handle<PropertyDescriptorObject> obj = Handle<PropertyDescriptorObject>::cast(
isolate->factory()->NewFixedArray(PropertyDescriptorObject::kLength));
Handle<PropertyDescriptorObject> obj =
isolate->factory()->NewPropertyDescriptorObject();
int flags =
PropertyDescriptorObject::IsEnumerableBit::encode(enumerable_) |
......@@ -355,14 +355,11 @@ Handle<PropertyDescriptorObject> PropertyDescriptor::ToPropertyDescriptorObject(
PropertyDescriptorObject::HasGetBit::encode(has_get()) |
PropertyDescriptorObject::HasSetBit::encode(has_set());
obj->set(PropertyDescriptorObject::kFlagsIndex, Smi::FromInt(flags));
obj->set_flags(Smi::FromInt(flags));
obj->set(PropertyDescriptorObject::kValueIndex,
has_value() ? *value_ : ReadOnlyRoots(isolate).the_hole_value());
obj->set(PropertyDescriptorObject::kGetIndex,
has_get() ? *get_ : ReadOnlyRoots(isolate).the_hole_value());
obj->set(PropertyDescriptorObject::kSetIndex,
has_set() ? *set_ : ReadOnlyRoots(isolate).the_hole_value());
if (has_value()) obj->set_value(*value_);
if (has_get()) obj->set_get(*get_);
if (has_set()) obj->set_set(*set_);
return obj;
}
......
......@@ -3584,6 +3584,8 @@ void ImplementationVisitor::GenerateClassDefinitions(
implementation << "#include \"src/objects/microtask-inl.h\"\n";
implementation << "#include \"src/objects/module-inl.h\"\n";
implementation << "#include \"src/objects/promise-inl.h\"\n";
implementation
<< "#include \"src/objects/property-descriptor-object-inl.h\"\n";
implementation << "#include \"src/objects/stack-frame-info-inl.h\"\n";
implementation << "#include \"src/objects/struct-inl.h\"\n";
implementation << "#include \"src/objects/template-objects-inl.h\"\n\n";
......
This diff is collapsed.
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