Commit 14274bb1 authored by Seth Brenith's avatar Seth Brenith Committed by Commit Bot

[torque] Use @generateCppClass in some simple cases

This change is mostly mechanical, but it's worth mentioning a few
slightly interesting cases:
- A couple of field definitions didn't match the signedness of their
  corresponding accessors.
- The generated accessors for Smi data use Smi values directly, but
  usually we want C++ accessors to use ints instead. I added a macro
  that hides the generated Smi accessors and exposes int accessors,
  but we might consider generating int accessors directly.
- The data held in some fields is described in comments next to the
  accessor definition for those fields. With automatically generated
  accessors, those comments need a new home. In this change I put them
  in the Torque object definition, but I'm open to other suggestions.
- gen-postmortem-metadata couldn't find updated class definitions after
  they got split across multiple lines, so I changed its matching
  logic. (Ideally debug-support.cc should be a Torque compiler output
  rather than something that involves parsing C++ with regexes, but
  this makes it correctly report subclass relationships for now.)
- The end offsets generated by Torque were off by one from the values
  that would be generated by DEFINE_FIELD_OFFSET_CONSTANTS.

Change-Id: I3df4fcd27997b46c41ca879065b9d97f6c939f07
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1692192Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#62719}
parent ab2ebc29
......@@ -93,20 +93,24 @@ type Number = Smi | HeapNumber;
type Numeric = Number | BigInt;
@abstract
@generateCppClass
extern class Name extends HeapObject {
hash_field: int32;
hash_field: uint32;
}
@generateCppClass
extern class Symbol extends Name {
flags: int32;
name: Object;
name: Object; // The print name of a symbol, or undefined if none.
}
@abstract
@generateCppClass
extern class String extends Name {
length: uint32;
length: int32;
}
@generateCppClass
extern class ConsString extends String {
first: String;
second: String;
......@@ -121,21 +125,32 @@ extern class ExternalString extends String {
extern class ExternalOneByteString extends ExternalString {}
extern class ExternalTwoByteString extends ExternalString {}
extern class InternalizedString extends String {}
@generateCppClass
extern class InternalizedString extends String {
}
// TODO(v8:8983): Add declaration for variable-sized region.
@abstract
@generateCppClass
extern class SeqString extends String {
}
extern class SeqOneByteString extends SeqString {}
extern class SeqTwoByteString extends SeqString {}
@generateCppClass
extern class SeqOneByteString extends SeqString {
}
@generateCppClass
extern class SeqTwoByteString extends SeqString {
}
@generateCppClass
extern class SlicedString extends String {
parent: String;
offset: Smi;
}
extern class ThinString extends String { actual: String; }
@generateCppClass
extern class ThinString extends String {
actual: String;
}
// The HeapNumber value NaN
type NaN extends HeapNumber;
......@@ -219,12 +234,14 @@ extern class Map extends HeapObject {
}
@generatePrint
@generateCppClass
extern class EnumCache extends Struct {
keys: FixedArray;
indices: FixedArray;
}
@generatePrint
@generateCppClass
extern class SourcePositionTableWithFrameCache extends Struct {
source_position_table: ByteArray;
stack_frame_cache: Object;
......@@ -287,7 +304,24 @@ type Constructor extends JSReceiver;
@abstract
@dirtyInstantiatedAbstractClass
@generateCppClass
extern class JSObject extends JSReceiver {
// [elements]: The elements (properties with names that are integers).
//
// Elements can be in two general modes: fast and slow. Each mode
// corresponds to a set of object representations of elements that
// have something in common.
//
// In the fast mode elements is a FixedArray and so each element can be
// quickly accessed. The elements array can have one of several maps in this
// mode: fixed_array_map, fixed_double_array_map,
// sloppy_arguments_elements_map or fixed_cow_array_map (for copy-on-write
// arrays). In the latter case the elements array may be shared by a few
// objects and so before writing to any element the array must be copied. Use
// EnsureWritableFastElements in this case.
//
// In the slow mode the elements is either a NumberDictionary or a
// FixedArray parameter map for a (sloppy) arguments object.
elements: FixedArrayBase;
}
......@@ -339,6 +373,7 @@ extern class JSFunction extends JSObject {
@noVerifier weak prototype_or_initial_map: JSReceiver | Map;
}
@generateCppClass
extern class JSProxy extends JSReceiver {
target: JSReceiver | Null;
handler: JSReceiver | Null;
......@@ -362,9 +397,17 @@ macro NewJSProxyRevocableResult(implicit context: Context)(
};
}
extern class JSGlobalProxy extends JSObject { native_context: Object; }
@generateCppClass
extern class JSGlobalProxy extends JSObject {
// [native_context]: the owner native context of this global proxy object.
// It is null value if this object is not used by any context.
native_context: Object;
}
extern class JSPrimitiveWrapper extends JSObject { value: Object; }
@generateCppClass
extern class JSPrimitiveWrapper extends JSObject {
value: Object;
}
extern class JSArgumentsObject extends JSObject {}
......
......@@ -711,8 +711,6 @@ void EmbedderDataArray::EmbedderDataArrayVerify(Isolate* isolate) {
}
}
USE_TORQUE_VERIFIER(Struct)
USE_TORQUE_VERIFIER(FixedArrayBase)
USE_TORQUE_VERIFIER(FixedArray)
......@@ -928,8 +926,6 @@ void JSAsyncGeneratorObject::JSAsyncGeneratorObjectVerify(Isolate* isolate) {
queue().HeapObjectVerify(isolate);
}
USE_TORQUE_VERIFIER(JSPrimitiveWrapper)
void JSDate::JSDateVerify(Isolate* isolate) {
TorqueGeneratedClassVerifiers::JSDateVerify(*this, isolate);
......@@ -965,8 +961,6 @@ void JSDate::JSDateVerify(Isolate* isolate) {
USE_TORQUE_VERIFIER(JSMessageObject)
USE_TORQUE_VERIFIER(Name)
void String::StringVerify(Isolate* isolate) {
TorqueGeneratedClassVerifiers::StringVerify(*this, isolate);
CHECK(length() >= 0 && length() <= Smi::kMaxValue);
......@@ -1001,8 +995,6 @@ void SlicedString::SlicedStringVerify(Isolate* isolate) {
CHECK_GE(this->length(), SlicedString::kMinLength);
}
USE_TORQUE_VERIFIER(SeqString)
USE_TORQUE_VERIFIER(ExternalString)
void JSBoundFunction::JSBoundFunctionVerify(Isolate* isolate) {
......@@ -1645,8 +1637,6 @@ void EnumCache::EnumCacheVerify(Isolate* isolate) {
}
}
USE_TORQUE_VERIFIER(SourcePositionTableWithFrameCache)
USE_TORQUE_VERIFIER(ClassPositions)
void ObjectBoilerplateDescription::ObjectBoilerplateDescriptionVerify(
......
......@@ -1314,7 +1314,7 @@ Handle<String> Factory::NewProperSubString(Handle<String> str, int begin,
slice->set_hash_field(String::kEmptyHashField);
slice->set_length(length);
slice->set_parent(isolate(), *str);
slice->set_parent(*str);
slice->set_offset(offset);
return slice;
}
......
......@@ -29,7 +29,7 @@ OBJECT_CONSTRUCTORS_IMPL(BytecodeArray, FixedArrayBase)
OBJECT_CONSTRUCTORS_IMPL(AbstractCode, HeapObject)
OBJECT_CONSTRUCTORS_IMPL(DependentCode, WeakFixedArray)
OBJECT_CONSTRUCTORS_IMPL(CodeDataContainer, HeapObject)
OBJECT_CONSTRUCTORS_IMPL(SourcePositionTableWithFrameCache, Struct)
TQ_OBJECT_CONSTRUCTORS_IMPL(SourcePositionTableWithFrameCache)
NEVER_READ_ONLY_SPACE_IMPL(AbstractCode)
......@@ -39,12 +39,6 @@ CAST_ACCESSOR(Code)
CAST_ACCESSOR(CodeDataContainer)
CAST_ACCESSOR(DependentCode)
CAST_ACCESSOR(DeoptimizationData)
CAST_ACCESSOR(SourcePositionTableWithFrameCache)
ACCESSORS(SourcePositionTableWithFrameCache, source_position_table, ByteArray,
kSourcePositionTableOffset)
ACCESSORS(SourcePositionTableWithFrameCache, stack_frame_cache,
SimpleNumberDictionary, kStackFrameCacheOffset)
int AbstractCode::raw_instruction_size() {
if (IsCode()) {
......
......@@ -935,22 +935,11 @@ class DeoptimizationData : public FixedArray {
OBJECT_CONSTRUCTORS(DeoptimizationData, FixedArray);
};
class SourcePositionTableWithFrameCache : public Struct {
class SourcePositionTableWithFrameCache
: public TorqueGeneratedSourcePositionTableWithFrameCache<
SourcePositionTableWithFrameCache, Struct> {
public:
DECL_ACCESSORS(source_position_table, ByteArray)
DECL_ACCESSORS(stack_frame_cache, SimpleNumberDictionary)
DECL_CAST(SourcePositionTableWithFrameCache)
DECL_PRINTER(SourcePositionTableWithFrameCache)
DECL_VERIFIER(SourcePositionTableWithFrameCache)
// Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(
Struct::kHeaderSize,
TORQUE_GENERATED_SOURCE_POSITION_TABLE_WITH_FRAME_CACHE_FIELDS)
OBJECT_CONSTRUCTORS(SourcePositionTableWithFrameCache, Struct);
TQ_OBJECT_CONSTRUCTORS(SourcePositionTableWithFrameCache)
};
} // namespace internal
......
......@@ -25,13 +25,9 @@ namespace v8 {
namespace internal {
OBJECT_CONSTRUCTORS_IMPL(DescriptorArray, HeapObject)
OBJECT_CONSTRUCTORS_IMPL(EnumCache, Struct)
TQ_OBJECT_CONSTRUCTORS_IMPL(EnumCache)
CAST_ACCESSOR(DescriptorArray)
CAST_ACCESSOR(EnumCache)
ACCESSORS(EnumCache, keys, FixedArray, kKeysOffset)
ACCESSORS(EnumCache, indices, FixedArray, kIndicesOffset)
ACCESSORS(DescriptorArray, enum_cache, EnumCache, kEnumCacheOffset)
RELAXED_INT16_ACCESSORS(DescriptorArray, number_of_all_descriptors,
......
......@@ -22,21 +22,11 @@ class Handle;
class Isolate;
// An EnumCache is a pair used to hold keys and indices caches.
class EnumCache : public Struct {
class EnumCache : public TorqueGeneratedEnumCache<EnumCache, Struct> {
public:
DECL_ACCESSORS(keys, FixedArray)
DECL_ACCESSORS(indices, FixedArray)
DECL_CAST(EnumCache)
DECL_PRINTER(EnumCache)
DECL_VERIFIER(EnumCache)
// Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(Struct::kHeaderSize,
TORQUE_GENERATED_ENUM_CACHE_FIELDS)
OBJECT_CONSTRUCTORS(EnumCache, Struct);
TQ_OBJECT_CONSTRUCTORS(EnumCache)
};
// A DescriptorArray is a custom array that holds instance descriptors.
......
......@@ -30,16 +30,16 @@ namespace v8 {
namespace internal {
OBJECT_CONSTRUCTORS_IMPL(JSReceiver, HeapObject)
OBJECT_CONSTRUCTORS_IMPL(JSObject, JSReceiver)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSObject)
OBJECT_CONSTRUCTORS_IMPL(JSAsyncFromSyncIterator, JSObject)
OBJECT_CONSTRUCTORS_IMPL(JSBoundFunction, JSObject)
OBJECT_CONSTRUCTORS_IMPL(JSDate, JSObject)
OBJECT_CONSTRUCTORS_IMPL(JSFunction, JSObject)
OBJECT_CONSTRUCTORS_IMPL(JSGlobalObject, JSObject)
OBJECT_CONSTRUCTORS_IMPL(JSGlobalProxy, JSObject)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSGlobalProxy)
JSIteratorResult::JSIteratorResult(Address ptr) : JSObject(ptr) {}
OBJECT_CONSTRUCTORS_IMPL(JSMessageObject, JSObject)
OBJECT_CONSTRUCTORS_IMPL(JSPrimitiveWrapper, JSObject)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSPrimitiveWrapper)
OBJECT_CONSTRUCTORS_IMPL(JSStringIterator, JSObject)
NEVER_READ_ONLY_SPACE_IMPL(JSReceiver)
......@@ -49,11 +49,8 @@ CAST_ACCESSOR(JSBoundFunction)
CAST_ACCESSOR(JSDate)
CAST_ACCESSOR(JSFunction)
CAST_ACCESSOR(JSGlobalObject)
CAST_ACCESSOR(JSGlobalProxy)
CAST_ACCESSOR(JSIteratorResult)
CAST_ACCESSOR(JSMessageObject)
CAST_ACCESSOR(JSObject)
CAST_ACCESSOR(JSPrimitiveWrapper)
CAST_ACCESSOR(JSReceiver)
CAST_ACCESSOR(JSStringIterator)
......@@ -131,8 +128,6 @@ bool JSObject::PrototypeHasNoElements(Isolate* isolate, JSObject object) {
ACCESSORS(JSReceiver, raw_properties_or_hash, Object, kPropertiesOrHashOffset)
ACCESSORS(JSObject, elements, FixedArrayBase, kElementsOffset)
void JSObject::EnsureCanContainHeapObjectElements(Handle<JSObject> object) {
JSObject::ValidateElements(*object);
ElementsKind elements_kind = object->map().elements_kind();
......@@ -465,8 +460,6 @@ ACCESSORS(JSFunction, raw_feedback_cell, FeedbackCell, kFeedbackCellOffset)
ACCESSORS(JSGlobalObject, native_context, NativeContext, kNativeContextOffset)
ACCESSORS(JSGlobalObject, global_proxy, JSGlobalProxy, kGlobalProxyOffset)
ACCESSORS(JSGlobalProxy, native_context, Object, kNativeContextOffset)
FeedbackVector JSFunction::feedback_vector() const {
DCHECK(has_feedback_vector());
return FeedbackVector::cast(raw_feedback_cell().value());
......@@ -719,8 +712,6 @@ void JSFunction::ResetIfBytecodeFlushed() {
}
}
ACCESSORS(JSPrimitiveWrapper, value, Object, kValueOffset)
ACCESSORS(JSDate, value, Object, kValueOffset)
ACCESSORS(JSDate, cache_stamp, Object, kCacheStampOffset)
ACCESSORS(JSDate, year, Object, kYearOffset)
......
......@@ -8,6 +8,7 @@
#include "src/objects/embedder-data-slot.h"
#include "src/objects/objects.h"
#include "src/objects/property-array.h"
#include "torque-generated/class-definitions-tq.h"
#include "torque-generated/field-offsets-tq.h"
// Has to be the last include (doesn't have include guards):
......@@ -276,7 +277,7 @@ class JSReceiver : public HeapObject {
// properties.
// Note that the map of JSObject changes during execution to enable inline
// caching.
class JSObject : public JSReceiver {
class JSObject : public TorqueGeneratedJSObject<JSObject, JSReceiver> {
public:
static bool IsUnmodifiedApiObject(FullObjectSlot o);
......@@ -291,23 +292,6 @@ class JSObject : public JSReceiver {
static V8_WARN_UNUSED_RESULT MaybeHandle<JSObject> ObjectCreate(
Isolate* isolate, Handle<Object> prototype);
// [elements]: The elements (properties with names that are integers).
//
// Elements can be in two general modes: fast and slow. Each mode
// corresponds to a set of object representations of elements that
// have something in common.
//
// In the fast mode elements is a FixedArray and so each element can be
// quickly accessed. The elements array can have one of several maps in this
// mode: fixed_array_map, fixed_double_array_map,
// sloppy_arguments_elements_map or fixed_cow_array_map (for copy-on-write
// arrays). In the latter case the elements array may be shared by a few
// objects and so before writing to any element the array must be copied. Use
// EnsureWritableFastElements in this case.
//
// In the slow mode the elements is either a NumberDictionary or a
// FixedArray parameter map for a (sloppy) arguments object.
DECL_ACCESSORS(elements, FixedArrayBase)
inline void initialize_elements();
static inline void SetMapAndElements(Handle<JSObject> object, Handle<Map> map,
Handle<FixedArrayBase> elements);
......@@ -683,8 +667,6 @@ class JSObject : public JSReceiver {
static bool IsExtensible(Handle<JSObject> object);
DECL_CAST(JSObject)
// Dispatched behavior.
void JSObjectShortPrint(StringStream* accumulator);
DECL_PRINTER(JSObject)
......@@ -768,15 +750,6 @@ class JSObject : public JSReceiver {
STATIC_ASSERT(kMaxNumberOfDescriptors + kFieldsAdded <=
PropertyArray::kMaxLength);
// Layout description.
#define JS_OBJECT_FIELDS(V) \
V(kElementsOffset, kTaggedSize) \
/* Header size. */ \
V(kHeaderSize, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(JSReceiver::kHeaderSize, JS_OBJECT_FIELDS)
#undef JS_OBJECT_FIELDS
STATIC_ASSERT(kHeaderSize == Internals::kJSObjectHeaderSize);
static const int kMaxInObjectProperties =
(kMaxInstanceSize - kHeaderSize) >> kTaggedSizeLog2;
......@@ -829,7 +802,7 @@ class JSObject : public JSReceiver {
V8_WARN_UNUSED_RESULT static Maybe<bool> PreventExtensionsWithTransition(
Handle<JSObject> object, ShouldThrow should_throw);
OBJECT_CONSTRUCTORS(JSObject, JSReceiver);
TQ_OBJECT_CONSTRUCTORS(JSObject)
};
// JSAccessorPropertyDescriptor is just a JSObject with a specific initial
......@@ -1178,14 +1151,9 @@ class JSFunction : public JSObject {
//
// Accessing a JSGlobalProxy requires security check.
class JSGlobalProxy : public JSObject {
class JSGlobalProxy
: public TorqueGeneratedJSGlobalProxy<JSGlobalProxy, JSObject> {
public:
// [native_context]: the owner native context of this global proxy object.
// It is null value if this object is not used by any context.
DECL_ACCESSORS(native_context, Object)
DECL_CAST(JSGlobalProxy)
inline bool IsDetachedFrom(JSGlobalObject global) const;
static int SizeWithEmbedderFields(int embedder_field_count);
......@@ -1194,11 +1162,7 @@ class JSGlobalProxy : public JSObject {
DECL_PRINTER(JSGlobalProxy)
DECL_VERIFIER(JSGlobalProxy)
// Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
TORQUE_GENERATED_JSGLOBAL_PROXY_FIELDS)
OBJECT_CONSTRUCTORS(JSGlobalProxy, JSObject);
TQ_OBJECT_CONSTRUCTORS(JSGlobalProxy)
};
// JavaScript global object.
......@@ -1237,22 +1201,13 @@ class JSGlobalObject : public JSObject {
};
// Representation for JS Wrapper objects, String, Number, Boolean, etc.
class JSPrimitiveWrapper : public JSObject {
class JSPrimitiveWrapper
: public TorqueGeneratedJSPrimitiveWrapper<JSPrimitiveWrapper, JSObject> {
public:
// [value]: the object being wrapped.
DECL_ACCESSORS(value, Object)
DECL_CAST(JSPrimitiveWrapper)
// Dispatched behavior.
DECL_PRINTER(JSPrimitiveWrapper)
DECL_VERIFIER(JSPrimitiveWrapper)
// Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(JSPrimitiveWrapper::kHeaderSize,
TORQUE_GENERATED_JSPRIMITIVE_WRAPPER_FIELDS)
OBJECT_CONSTRUCTORS(JSPrimitiveWrapper, JSObject);
TQ_OBJECT_CONSTRUCTORS(JSPrimitiveWrapper)
};
class DateCache;
......
......@@ -15,12 +15,7 @@
namespace v8 {
namespace internal {
OBJECT_CONSTRUCTORS_IMPL(JSProxy, JSReceiver)
CAST_ACCESSOR(JSProxy)
ACCESSORS(JSProxy, target, Object, kTargetOffset)
ACCESSORS(JSProxy, handler, Object, kHandlerOffset)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSProxy)
bool JSProxy::IsRevoked() const { return !handler().IsJSReceiver(); }
......
......@@ -15,21 +15,14 @@ namespace v8 {
namespace internal {
// The JSProxy describes EcmaScript Harmony proxies
class JSProxy : public JSReceiver {
class JSProxy : public TorqueGeneratedJSProxy<JSProxy, JSReceiver> {
public:
V8_WARN_UNUSED_RESULT static MaybeHandle<JSProxy> New(Isolate* isolate,
Handle<Object>,
Handle<Object>);
// [handler]: The handler property.
DECL_ACCESSORS(handler, Object)
// [target]: The target property.
DECL_ACCESSORS(target, Object)
static MaybeHandle<NativeContext> GetFunctionRealm(Handle<JSProxy> proxy);
DECL_CAST(JSProxy)
V8_INLINE bool IsRevoked() const;
static void Revoke(Handle<JSProxy> proxy);
......@@ -106,10 +99,6 @@ class JSProxy : public JSReceiver {
static const int kMaxIterationLimit = 100 * 1024;
// Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(JSReceiver::kHeaderSize,
TORQUE_GENERATED_JSPROXY_FIELDS)
// kTargetOffset aliases with the elements of JSObject. The fact that
// JSProxy::target is a Javascript value which cannot be confused with an
// elements backing store is exploited by loading from this offset from an
......@@ -125,7 +114,7 @@ class JSProxy : public JSReceiver {
PropertyDescriptor* desc,
Maybe<ShouldThrow> should_throw);
OBJECT_CONSTRUCTORS(JSProxy, JSReceiver);
TQ_OBJECT_CONSTRUCTORS(JSProxy)
};
// JSProxyRevocableResult is just a JSObject with a specific initial map.
......
......@@ -16,14 +16,9 @@
namespace v8 {
namespace internal {
OBJECT_CONSTRUCTORS_IMPL(Name, HeapObject)
OBJECT_CONSTRUCTORS_IMPL(Symbol, Name)
TQ_OBJECT_CONSTRUCTORS_IMPL(Name)
TQ_OBJECT_CONSTRUCTORS_IMPL(Symbol)
CAST_ACCESSOR(Name)
CAST_ACCESSOR(Symbol)
ACCESSORS(Symbol, name, Object, kNameOffset)
INT_ACCESSORS(Symbol, flags, kFlagsOffset)
BIT_FIELD_ACCESSORS(Symbol, flags, is_private, Symbol::IsPrivateBit)
BIT_FIELD_ACCESSORS(Symbol, flags, is_well_known_symbol,
Symbol::IsWellKnownSymbolBit)
......@@ -52,12 +47,6 @@ DEF_GETTER(Name, IsUniqueName, bool) {
return result;
}
uint32_t Name::hash_field() { return ReadField<uint32_t>(kHashFieldOffset); }
void Name::set_hash_field(uint32_t value) {
WriteField<uint32_t>(kHashFieldOffset, value);
}
bool Name::Equals(Name other) {
if (other == *this) return true;
if ((this->IsInternalizedString() && other.IsInternalizedString()) ||
......
......@@ -7,7 +7,7 @@
#include "src/objects/heap-object.h"
#include "src/objects/objects.h"
#include "torque-generated/field-offsets-tq.h"
#include "torque-generated/class-definitions-tq.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
......@@ -17,12 +17,8 @@ namespace internal {
// The Name abstract class captures anything that can be used as a property
// name, i.e., strings and symbols. All names store a hash value.
class Name : public HeapObject {
class Name : public TorqueGeneratedName<Name, HeapObject> {
public:
// Get and set the hash field of the name.
inline uint32_t hash_field();
inline void set_hash_field(uint32_t value);
// Tells whether the hash code has been computed.
inline bool HasHashCode();
......@@ -66,15 +62,9 @@ class Name : public HeapObject {
V8_WARN_UNUSED_RESULT static MaybeHandle<String> ToFunctionName(
Isolate* isolate, Handle<Name> name, Handle<String> prefix);
DECL_CAST(Name)
DECL_PRINTER(Name)
void NameShortPrint();
int NameShortPrint(Vector<char> str);
DECL_VERIFIER(Name)
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
TORQUE_GENERATED_NAME_FIELDS)
// Mask constant for checking if a name has a computed hash code
// and if it is a string that is an array index. The least significant bit
......@@ -136,17 +126,12 @@ class Name : public HeapObject {
protected:
static inline bool IsHashFieldComputed(uint32_t field);
OBJECT_CONSTRUCTORS(Name, HeapObject);
TQ_OBJECT_CONSTRUCTORS(Name)
};
// ES6 symbols.
class Symbol : public Name {
class Symbol : public TorqueGeneratedSymbol<Symbol, Name> {
public:
// [name]: The print name of a symbol, or undefined if none.
DECL_ACCESSORS(name, Object)
DECL_INT_ACCESSORS(flags)
// [is_private]: Whether this is a private symbol. Private symbols can only
// be used to designate own properties of objects.
DECL_BOOLEAN_ACCESSORS(is_private)
......@@ -174,15 +159,10 @@ class Symbol : public Name {
inline bool is_private_name() const;
inline void set_is_private_name();
DECL_CAST(Symbol)
// Dispatched behavior.
DECL_PRINTER(Symbol)
DECL_VERIFIER(Symbol)
DEFINE_FIELD_OFFSET_CONSTANTS(Name::kHeaderSize,
TORQUE_GENERATED_SYMBOL_FIELDS)
// Flags layout.
#define FLAGS_BIT_FIELDS(V, _) \
V(IsPrivateBit, bool, 1, _) \
......@@ -204,7 +184,7 @@ class Symbol : public Name {
// TODO(cbruni): remove once the new maptracer is in place.
friend class Name; // For PrivateSymbolToName.
OBJECT_CONSTRUCTORS(Symbol, Name);
TQ_OBJECT_CONSTRUCTORS(Symbol)
};
} // namespace internal
......
......@@ -224,6 +224,14 @@
TaggedField<Smi, offset>::Relaxed_Store(*this, Smi::FromInt(value)); \
}
#define TQ_SMI_ACCESSORS(holder, name) \
int holder::name() const { \
return TorqueGenerated##holder<holder, Super>::name().value(); \
} \
void holder::set_##name(int value) { \
TorqueGenerated##holder<holder, Super>::set_##name(Smi::FromInt(value)); \
}
#define BOOL_GETTER(holder, field, name, offset) \
bool holder::name() const { return BooleanBit::get(field(), offset); }
......
......@@ -22,8 +22,6 @@
namespace v8 {
namespace internal {
INT32_ACCESSORS(String, length, kLengthOffset)
int String::synchronized_length() const {
return base::AsAtomic32::Acquire_Load(
reinterpret_cast<const int32_t*>(FIELD_ADDR(*this, kLengthOffset)));
......@@ -34,29 +32,21 @@ void String::synchronized_set_length(int value) {
reinterpret_cast<int32_t*>(FIELD_ADDR(*this, kLengthOffset)), value);
}
OBJECT_CONSTRUCTORS_IMPL(String, Name)
OBJECT_CONSTRUCTORS_IMPL(SeqString, String)
OBJECT_CONSTRUCTORS_IMPL(SeqOneByteString, SeqString)
OBJECT_CONSTRUCTORS_IMPL(SeqTwoByteString, SeqString)
OBJECT_CONSTRUCTORS_IMPL(InternalizedString, String)
OBJECT_CONSTRUCTORS_IMPL(ConsString, String)
OBJECT_CONSTRUCTORS_IMPL(ThinString, String)
OBJECT_CONSTRUCTORS_IMPL(SlicedString, String)
TQ_OBJECT_CONSTRUCTORS_IMPL(String)
TQ_OBJECT_CONSTRUCTORS_IMPL(SeqString)
TQ_OBJECT_CONSTRUCTORS_IMPL(SeqOneByteString)
TQ_OBJECT_CONSTRUCTORS_IMPL(SeqTwoByteString)
TQ_OBJECT_CONSTRUCTORS_IMPL(InternalizedString)
TQ_OBJECT_CONSTRUCTORS_IMPL(ConsString)
TQ_OBJECT_CONSTRUCTORS_IMPL(ThinString)
TQ_OBJECT_CONSTRUCTORS_IMPL(SlicedString)
OBJECT_CONSTRUCTORS_IMPL(ExternalString, String)
OBJECT_CONSTRUCTORS_IMPL(ExternalOneByteString, ExternalString)
OBJECT_CONSTRUCTORS_IMPL(ExternalTwoByteString, ExternalString)
CAST_ACCESSOR(ConsString)
CAST_ACCESSOR(ExternalOneByteString)
CAST_ACCESSOR(ExternalString)
CAST_ACCESSOR(ExternalTwoByteString)
CAST_ACCESSOR(InternalizedString)
CAST_ACCESSOR(SeqOneByteString)
CAST_ACCESSOR(SeqString)
CAST_ACCESSOR(SeqTwoByteString)
CAST_ACCESSOR(SlicedString)
CAST_ACCESSOR(String)
CAST_ACCESSOR(ThinString)
StringShape::StringShape(const String str) : type_(str.map().instance_type()) {
set_valid();
......@@ -528,33 +518,21 @@ int SeqOneByteString::SeqOneByteStringSize(InstanceType instance_type) {
return SizeFor(length());
}
String SlicedString::parent() {
return TaggedField<String, kParentOffset>::load(*this);
}
void SlicedString::set_parent(Isolate* isolate, String parent,
WriteBarrierMode mode) {
void SlicedString::set_parent(String parent, WriteBarrierMode mode) {
DCHECK(parent.IsSeqString() || parent.IsExternalString());
WRITE_FIELD(*this, kParentOffset, parent);
CONDITIONAL_WRITE_BARRIER(*this, kParentOffset, parent, mode);
TorqueGeneratedSlicedString<SlicedString, Super>::set_parent(parent, mode);
}
SMI_ACCESSORS(SlicedString, offset, kOffsetOffset)
ACCESSORS(ConsString, first, String, kFirstOffset)
TQ_SMI_ACCESSORS(SlicedString, offset)
Object ConsString::unchecked_first() {
return TaggedField<Object, kFirstOffset>::load(*this);
}
ACCESSORS(ConsString, second, String, kSecondOffset)
Object ConsString::unchecked_second() {
return RELAXED_READ_FIELD(*this, kSecondOffset);
}
ACCESSORS(ThinString, actual, String, kActualOffset)
DEF_GETTER(ThinString, unchecked_actual, HeapObject) {
return TaggedField<HeapObject, kActualOffset>::load(isolate, *this);
}
......
......@@ -79,7 +79,7 @@ class StringShape {
// ordered sequence of zero or more 16-bit unsigned integer values.
//
// All string values have a length field.
class String : public Name {
class String : public TorqueGeneratedString<String, Name> {
public:
enum Encoding { ONE_BYTE_ENCODING, TWO_BYTE_ENCODING };
......@@ -152,9 +152,6 @@ class String : public Name {
template <typename Char>
inline const Char* GetChars(const DisallowHeapAllocation& no_gc);
// Get and set the length of the string.
DECL_INT_ACCESSORS(length)
// Get and set the length of the string using acquire loads and release
// stores.
DECL_SYNCHRONIZED_INT_ACCESSORS(length)
......@@ -320,8 +317,6 @@ class String : public Name {
static Handle<String> Trim(Isolate* isolate, Handle<String> string,
TrimMode mode);
DECL_CAST(String)
V8_EXPORT_PRIVATE void PrintOn(FILE* out);
// For use during stack traces. Performs rudimentary sanity check.
......@@ -338,9 +333,6 @@ class String : public Name {
inline bool IsFlat();
DEFINE_FIELD_OFFSET_CONSTANTS(Name::kHeaderSize,
TORQUE_GENERATED_STRING_FIELDS)
// Max char codes.
static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar;
static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar;
......@@ -453,7 +445,7 @@ class String : public Name {
// Compute and set the hash code.
V8_EXPORT_PRIVATE uint32_t ComputeAndSetHash();
OBJECT_CONSTRUCTORS(String, Name);
TQ_OBJECT_CONSTRUCTORS(String)
};
// clang-format off
......@@ -477,31 +469,29 @@ class SubStringRange {
};
// The SeqString abstract class captures sequential string values.
class SeqString : public String {
class SeqString : public TorqueGeneratedSeqString<SeqString, String> {
public:
DECL_CAST(SeqString)
DECL_VERIFIER(SeqString)
// Truncate the string in-place if possible and return the result.
// In case of new_length == 0, the empty string is returned without
// truncating the original string.
V8_WARN_UNUSED_RESULT static Handle<String> Truncate(Handle<SeqString> string,
int new_length);
OBJECT_CONSTRUCTORS(SeqString, String);
TQ_OBJECT_CONSTRUCTORS(SeqString)
};
class InternalizedString : public String {
class InternalizedString
: public TorqueGeneratedInternalizedString<InternalizedString, String> {
public:
DECL_CAST(InternalizedString)
// TODO(neis): Possibly move some stuff from String here.
OBJECT_CONSTRUCTORS(InternalizedString, String);
TQ_OBJECT_CONSTRUCTORS(InternalizedString)
};
// The OneByteString class captures sequential one-byte string objects.
// Each character in the OneByteString is an one-byte character.
class SeqOneByteString : public SeqString {
class SeqOneByteString
: public TorqueGeneratedSeqOneByteString<SeqOneByteString, SeqString> {
public:
static const bool kHasOneByteEncoding = true;
using Char = uint8_t;
......@@ -519,8 +509,6 @@ class SeqOneByteString : public SeqString {
// is deterministic.
void clear_padding();
DECL_CAST(SeqOneByteString)
// Garbage collection support. This method is called by the
// garbage collector to compute the actual size of an OneByteString
// instance.
......@@ -538,12 +526,13 @@ class SeqOneByteString : public SeqString {
class BodyDescriptor;
OBJECT_CONSTRUCTORS(SeqOneByteString, SeqString);
TQ_OBJECT_CONSTRUCTORS(SeqOneByteString)
};
// The TwoByteString class captures sequential unicode string objects.
// Each character in the TwoByteString is a two-byte uint16_t.
class SeqTwoByteString : public SeqString {
class SeqTwoByteString
: public TorqueGeneratedSeqTwoByteString<SeqTwoByteString, SeqString> {
public:
static const bool kHasOneByteEncoding = false;
using Char = uint16_t;
......@@ -561,8 +550,6 @@ class SeqTwoByteString : public SeqString {
// is deterministic.
void clear_padding();
DECL_CAST(SeqTwoByteString)
// Garbage collection support. This method is called by the
// garbage collector to compute the actual size of a TwoByteString
// instance.
......@@ -581,7 +568,7 @@ class SeqTwoByteString : public SeqString {
class BodyDescriptor;
OBJECT_CONSTRUCTORS(SeqTwoByteString, SeqString);
TQ_OBJECT_CONSTRUCTORS(SeqTwoByteString)
};
// The ConsString class describes string values built by using the
......@@ -592,18 +579,12 @@ class SeqTwoByteString : public SeqString {
// are non-ConsString string values. The string value represented by
// a ConsString can be obtained by concatenating the leaf string
// values in a left-to-right depth-first traversal of the tree.
class ConsString : public String {
class ConsString : public TorqueGeneratedConsString<ConsString, String> {
public:
// First string of the cons cell.
DECL_ACCESSORS(first, String)
// Doesn't check that the result is a string, even in debug mode. This is
// useful during GC where the mark bits confuse the checks.
inline Object unchecked_first();
// Second string of the cons cell.
DECL_ACCESSORS(second, String)
// Doesn't check that the result is a string, even in debug mode. This is
// useful during GC where the mark bits confuse the checks.
inline Object unchecked_second();
......@@ -611,11 +592,6 @@ class ConsString : public String {
// Dispatched behavior.
V8_EXPORT_PRIVATE uint16_t Get(int index);
DECL_CAST(ConsString)
DEFINE_FIELD_OFFSET_CONSTANTS(String::kHeaderSize,
TORQUE_GENERATED_CONS_STRING_FIELDS)
// Minimum length for a cons string.
static const int kMinLength = 13;
......@@ -623,7 +599,7 @@ class ConsString : public String {
DECL_VERIFIER(ConsString)
OBJECT_CONSTRUCTORS(ConsString, String);
TQ_OBJECT_CONSTRUCTORS(ConsString)
};
// The ThinString class describes string objects that are just references
......@@ -633,25 +609,18 @@ class ConsString : public String {
// internalized version (which is allocated as a new object).
// In terms of memory layout and most algorithms operating on strings,
// ThinStrings can be thought of as "one-part cons strings".
class ThinString : public String {
class ThinString : public TorqueGeneratedThinString<ThinString, String> {
public:
// Actual string that this ThinString refers to.
DECL_ACCESSORS(actual, String)
inline HeapObject unchecked_actual() const;
inline HeapObject unchecked_actual(Isolate* isolate) const;
V8_EXPORT_PRIVATE uint16_t Get(int index);
DECL_CAST(ThinString)
DECL_VERIFIER(ThinString)
DEFINE_FIELD_OFFSET_CONSTANTS(String::kHeaderSize,
TORQUE_GENERATED_THIN_STRING_FIELDS)
using BodyDescriptor = FixedBodyDescriptor<kActualOffset, kSize, kSize>;
OBJECT_CONSTRUCTORS(ThinString, String);
TQ_OBJECT_CONSTRUCTORS(ThinString)
};
// The Sliced String class describes strings that are substrings of another
......@@ -666,22 +635,14 @@ class ThinString : public String {
// - handling externalized parent strings
// - external strings as parent
// - truncating sliced string to enable otherwise unneeded parent to be GC'ed.
class SlicedString : public String {
class SlicedString : public TorqueGeneratedSlicedString<SlicedString, String> {
public:
inline String parent();
inline void set_parent(Isolate* isolate, String parent,
inline void set_parent(String parent,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
inline int offset() const;
inline void set_offset(int offset);
DECL_INT_ACCESSORS(offset)
// Dispatched behavior.
V8_EXPORT_PRIVATE uint16_t Get(int index);
DECL_CAST(SlicedString)
DEFINE_FIELD_OFFSET_CONSTANTS(String::kHeaderSize,
TORQUE_GENERATED_SLICED_STRING_FIELDS)
// Minimum length for a sliced string.
static const int kMinLength = 13;
......@@ -689,7 +650,7 @@ class SlicedString : public String {
DECL_VERIFIER(SlicedString)
OBJECT_CONSTRUCTORS(SlicedString, String);
TQ_OBJECT_CONSTRUCTORS(SlicedString)
};
// The ExternalString class describes string values that are backed by
......
......@@ -22,7 +22,6 @@ class Struct : public TorqueGeneratedStruct<Struct, HeapObject> {
public:
inline void InitializeBody(int object_size);
void BriefPrintDetails(std::ostream& os);
DECL_VERIFIER(Struct)
TQ_OBJECT_CONSTRUCTORS(Struct)
};
......
......@@ -3055,8 +3055,8 @@ class ClassFieldOffsetGenerator : public FieldOffsetsGenerator {
hdr_ << " static constexpr int " << field << " = " << previous_field_end_
<< ";\n";
hdr_ << " static constexpr int " << field_end << " = " << field << " + "
<< size_string << ";\n";
previous_field_end_ = field_end;
<< size_string << " - 1;\n";
previous_field_end_ = field_end + " + 1";
}
virtual void WriteMarker(const std::string& marker) {
hdr_ << " static constexpr int " << marker << " = " << previous_field_end_
......
......@@ -368,6 +368,7 @@ def load_objects_from_file(objfilename, checktypes):
in_insttype = False;
typestr = '';
uncommented_file = ''
#
# Iterate the header file line-by-line to collect type and class
......@@ -390,21 +391,26 @@ def load_objects_from_file(objfilename, checktypes):
typestr += line;
continue;
match = re.match(r'class(?:\s+V8_EXPORT(?:_PRIVATE)?)?'
r'\s+(\w[^:]*)'
uncommented_file += '\n' + line
for match in re.finditer(r'\nclass(?:\s+V8_EXPORT(?:_PRIVATE)?)?'
r'\s+(\w[^:;]*)'
r'(?:: public (\w[^{]*))?\s*{\s*',
line);
if (match):
klass = match.group(1).strip();
pklass = match.group(2);
if (pklass):
# Strip potential template arguments from parent
# class.
match = re.match(r'(\w+)(<.*>)?', pklass.strip());
pklass = match.group(1).strip();
klasses[klass] = { 'parent': pklass };
uncommented_file):
klass = match.group(1).strip();
pklass = match.group(2);
if (pklass):
# Check for generated Torque class.
gen_match = re.match(
r'TorqueGenerated\w+\s*<\s*\w+,\s*(\w+)\s*>',
pklass)
if (gen_match):
pklass = gen_match.group(1)
# Strip potential template arguments from parent
# class.
match = re.match(r'(\w+)(<.*>)?', pklass.strip());
pklass = match.group(1).strip();
klasses[klass] = { 'parent': pklass };
#
# Process the instance type declaration.
......
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