Commit c6201bc0 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[ptr-compr][cleanup] Derive Object from TaggedImpl<>

Having an TaggedImpl template will simplify adding compressed variants
of Object and MaybeObject which is required for avoiding unnecessary
value decompression in tight copying loops and write barrier
implementations.

Bug: v8:7703, v8:9183
Change-Id: I388b008aad0dbeb2d33fc5fb80c5f29b55ef993e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1588419
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61441}
parent 90c003a3
...@@ -1909,6 +1909,8 @@ Address CheckObjectType(Address raw_value, Address raw_type, ...@@ -1909,6 +1909,8 @@ Address CheckObjectType(Address raw_value, Address raw_type,
break; break;
TYPE_CASE(Object) TYPE_CASE(Object)
TYPE_CASE(Smi)
TYPE_CASE(HeapObject)
OBJECT_TYPE_LIST(TYPE_CASE) OBJECT_TYPE_LIST(TYPE_CASE)
HEAP_OBJECT_TYPE_LIST(TYPE_CASE) HEAP_OBJECT_TYPE_LIST(TYPE_CASE)
STRUCT_LIST(TYPE_STRUCT_CASE) STRUCT_LIST(TYPE_STRUCT_CASE)
......
...@@ -66,14 +66,12 @@ class JSFinalizationGroupCleanupIterator; ...@@ -66,14 +66,12 @@ class JSFinalizationGroupCleanupIterator;
class JSWeakMap; class JSWeakMap;
class JSWeakRef; class JSWeakRef;
class JSWeakSet; class JSWeakSet;
class MaybeObject;
class PromiseCapability; class PromiseCapability;
class PromiseFulfillReactionJobTask; class PromiseFulfillReactionJobTask;
class PromiseReaction; class PromiseReaction;
class PromiseReactionJobTask; class PromiseReactionJobTask;
class PromiseRejectReactionJobTask; class PromiseRejectReactionJobTask;
class WasmDebugInfo; class WasmDebugInfo;
class WeakCell;
class Zone; class Zone;
template <typename T> template <typename T>
...@@ -280,9 +278,12 @@ class int31_t { ...@@ -280,9 +278,12 @@ class int31_t {
#define ENUM_ELEMENT(Name) k##Name, #define ENUM_ELEMENT(Name) k##Name,
#define ENUM_STRUCT_ELEMENT(NAME, Name, name) k##Name, #define ENUM_STRUCT_ELEMENT(NAME, Name, name) k##Name,
enum class ObjectType { enum class ObjectType {
kObject, ENUM_ELEMENT(Object) //
OBJECT_TYPE_LIST(ENUM_ELEMENT) HEAP_OBJECT_TYPE_LIST(ENUM_ELEMENT) ENUM_ELEMENT(Smi) //
STRUCT_LIST(ENUM_STRUCT_ELEMENT) ENUM_ELEMENT(HeapObject) //
OBJECT_TYPE_LIST(ENUM_ELEMENT) //
HEAP_OBJECT_TYPE_LIST(ENUM_ELEMENT) //
STRUCT_LIST(ENUM_STRUCT_ELEMENT) //
}; };
#undef ENUM_ELEMENT #undef ENUM_ELEMENT
#undef ENUM_STRUCT_ELEMENT #undef ENUM_STRUCT_ELEMENT
...@@ -349,6 +350,8 @@ struct ObjectTypeOf {}; ...@@ -349,6 +350,8 @@ struct ObjectTypeOf {};
static const ObjectType value = ObjectType::k##Name; \ static const ObjectType value = ObjectType::k##Name; \
}; };
OBJECT_TYPE_CASE(Object) OBJECT_TYPE_CASE(Object)
OBJECT_TYPE_CASE(Smi)
OBJECT_TYPE_CASE(HeapObject)
OBJECT_TYPE_LIST(OBJECT_TYPE_CASE) OBJECT_TYPE_LIST(OBJECT_TYPE_CASE)
HEAP_OBJECT_ORDINARY_TYPE_LIST(OBJECT_TYPE_CASE) HEAP_OBJECT_ORDINARY_TYPE_LIST(OBJECT_TYPE_CASE)
STRUCT_LIST(OBJECT_TYPE_STRUCT_CASE) STRUCT_LIST(OBJECT_TYPE_STRUCT_CASE)
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "src/objects/shared-function-info.h" #include "src/objects/shared-function-info.h"
#include "src/objects/slots-inl.h" #include "src/objects/slots-inl.h"
#include "src/objects/smi-inl.h" #include "src/objects/smi-inl.h"
#include "src/objects/tagged-impl-inl.h"
#include "src/objects/templates.h" #include "src/objects/templates.h"
#include "src/property-details.h" #include "src/property-details.h"
#include "src/property.h" #include "src/property.h"
...@@ -749,21 +750,6 @@ bool Object::ToArrayIndex(uint32_t* index) const { ...@@ -749,21 +750,6 @@ bool Object::ToArrayIndex(uint32_t* index) const {
return Object::ToUint32(index) && *index != kMaxUInt32; return Object::ToUint32(index) && *index != kMaxUInt32;
} }
bool Object::GetHeapObjectIfStrong(HeapObject* result) const {
return GetHeapObject(result);
}
bool Object::GetHeapObject(HeapObject* result) const {
if (!IsHeapObject()) return false;
*result = HeapObject::cast(*this);
return true;
}
HeapObject Object::GetHeapObject() const {
DCHECK(IsHeapObject());
return HeapObject::cast(*this);
}
int RegExpMatchInfo::NumberOfCaptureRegisters() { int RegExpMatchInfo::NumberOfCaptureRegisters() {
DCHECK_GE(length(), kLastMatchOverhead); DCHECK_GE(length(), kLastMatchOverhead);
Object obj = get(kNumberOfCapturesIndex); Object obj = get(kNumberOfCapturesIndex);
......
...@@ -265,29 +265,15 @@ ShouldThrow GetShouldThrow(Isolate* isolate, Maybe<ShouldThrow> should_throw); ...@@ -265,29 +265,15 @@ ShouldThrow GetShouldThrow(Isolate* isolate, Maybe<ShouldThrow> should_throw);
// There must only be a single data member in Object: the Address ptr, // There must only be a single data member in Object: the Address ptr,
// containing the tagged heap pointer that this Object instance refers to. // containing the tagged heap pointer that this Object instance refers to.
// For a design overview, see https://goo.gl/Ph4CGz. // For a design overview, see https://goo.gl/Ph4CGz.
class Object { class Object : public TaggedImpl<HeapObjectReferenceType::STRONG, Address> {
public: public:
constexpr Object() : ptr_(kNullAddress) {} constexpr Object() : TaggedImpl(kNullAddress) {}
explicit constexpr Object(Address ptr) : ptr_(ptr) {} explicit constexpr Object(Address ptr) : TaggedImpl(ptr) {}
// Make clang on Linux catch what MSVC complains about on Windows:
operator bool() const = delete;
bool operator==(const Object that) const { return this->ptr() == that.ptr(); }
bool operator!=(const Object that) const { return this->ptr() != that.ptr(); }
// Usage in std::set requires operator<.
bool operator<(const Object that) const { return this->ptr() < that.ptr(); }
// Returns the tagged "(heap) object pointer" representation of this object.
constexpr Address ptr() const { return ptr_; }
// These operator->() overloads are required for handlified code. // These operator->() overloads are required for handlified code.
Object* operator->() { return this; } Object* operator->() { return this; }
const Object* operator->() const { return this; } const Object* operator->() const { return this; }
// Type testing.
bool IsObject() const { return true; }
#define IS_TYPE_FUNCTION_DECL(Type) V8_INLINE bool Is##Type() const; #define IS_TYPE_FUNCTION_DECL(Type) V8_INLINE bool Is##Type() const;
OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
...@@ -588,34 +574,6 @@ class Object { ...@@ -588,34 +574,6 @@ class Object {
// and length. // and length.
bool IterationHasObservableEffects(); bool IterationHasObservableEffects();
//
// The following GetHeapObjectXX methods mimic corresponding functionality
// in MaybeObject. Having them here allows us to unify code that processes
// ObjectSlots and MaybeObjectSlots.
//
// If this Object is a strong pointer to a HeapObject, returns true and
// sets *result. Otherwise returns false.
inline bool GetHeapObjectIfStrong(HeapObject* result) const;
// If this Object is a strong pointer to a HeapObject (weak pointers are not
// expected), returns true and sets *result. Otherwise returns false.
inline bool GetHeapObject(HeapObject* result) const;
// DCHECKs that this Object is a strong pointer to a HeapObject and returns
// the HeapObject.
inline HeapObject GetHeapObject() const;
// Always returns false because Object is not expected to be a weak pointer
// to a HeapObject.
inline bool GetHeapObjectIfWeak(HeapObject* result) const {
DCHECK(!HAS_WEAK_HEAP_OBJECT_TAG(ptr_));
return false;
}
// Always returns false because Object is not expected to be a weak pointer
// to a HeapObject.
inline bool IsCleared() const { return false; }
EXPORT_DECL_VERIFIER(Object) EXPORT_DECL_VERIFIER(Object)
#ifdef VERIFY_HEAP #ifdef VERIFY_HEAP
...@@ -706,19 +664,10 @@ class Object { ...@@ -706,19 +664,10 @@ class Object {
Isolate* isolate, Handle<Object> input); Isolate* isolate, Handle<Object> input);
V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ConvertToIndex( V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ConvertToIndex(
Isolate* isolate, Handle<Object> input, MessageTemplate error_index); Isolate* isolate, Handle<Object> input, MessageTemplate error_index);
Address ptr_;
}; };
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, const Object& obj); V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, const Object& obj);
// In objects.h to be usable without objects-inl.h inclusion.
bool Object::IsSmi() const { return HAS_SMI_TAG(ptr()); }
bool Object::IsHeapObject() const {
DCHECK_EQ(!IsSmi(), Internals::HasHeapObjectTag(ptr()));
return !IsSmi();
}
struct Brief { struct Brief {
template <typename TObject> template <typename TObject>
explicit Brief(TObject v) : value{v.ptr()} {} explicit Brief(TObject v) : value{v.ptr()} {}
......
...@@ -66,9 +66,7 @@ template <typename T> ...@@ -66,9 +66,7 @@ template <typename T>
class ZoneForwardList; class ZoneForwardList;
#define OBJECT_TYPE_LIST(V) \ #define OBJECT_TYPE_LIST(V) \
V(Smi) \
V(LayoutDescriptor) \ V(LayoutDescriptor) \
V(HeapObject) \
V(Primitive) \ V(Primitive) \
V(Number) \ V(Number) \
V(Numeric) V(Numeric)
......
...@@ -402,7 +402,11 @@ def load_objects_from_file(objfilename, checktypes): ...@@ -402,7 +402,11 @@ def load_objects_from_file(objfilename, checktypes):
klass = match.group(1).strip(); klass = match.group(1).strip();
pklass = match.group(2); pklass = match.group(2);
if (pklass): if (pklass):
pklass = pklass.strip(); # Strip potential template arguments from parent
# class.
match = re.match(r'(\w+)(<.*>)?', pklass.strip());
pklass = match.group(1).strip();
klasses[klass] = { 'parent': pklass }; klasses[klass] = { 'parent': pklass };
# #
......
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