Commit a2f18248 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[ubsan] Replace internal::Object references in v8.h

with internal::Address. This is in preparation for the upcoming
changes to internal::Object. The public API is unchanged, and
there should be no change in behavior either.

Most of the casts newly introduced here will disappear again once
the migration is complete.

Bug: v8:3770
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: I2990b06a2511ccc5de3f98fd95a805f30ed589ab
Reviewed-on: https://chromium-review.googlesource.com/c/1036612Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56705}
parent db6db6ed
...@@ -20,7 +20,8 @@ class Isolate; ...@@ -20,7 +20,8 @@ class Isolate;
namespace internal { namespace internal {
class Object; typedef uintptr_t Address;
static const Address kNullAddress = 0;
/** /**
* Configuration of tagging scheme. * Configuration of tagging scheme.
...@@ -45,11 +46,11 @@ template <size_t tagged_ptr_size> ...@@ -45,11 +46,11 @@ template <size_t tagged_ptr_size>
struct SmiTagging; struct SmiTagging;
template <int kSmiShiftSize> template <int kSmiShiftSize>
V8_INLINE internal::Object* IntToSmi(int value) { V8_INLINE internal::Address IntToSmi(int value) {
int smi_shift_bits = kSmiTagSize + kSmiShiftSize; int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
intptr_t tagged_value = uintptr_t tagged_value =
(static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag; (static_cast<uintptr_t>(value) << smi_shift_bits) | kSmiTag;
return reinterpret_cast<internal::Object*>(tagged_value); return static_cast<internal::Address>(tagged_value);
} }
// Smi constants for systems where tagged pointer is a 32-bit value. // Smi constants for systems where tagged pointer is a 32-bit value.
...@@ -58,19 +59,19 @@ struct SmiTagging<4> { ...@@ -58,19 +59,19 @@ struct SmiTagging<4> {
enum { kSmiShiftSize = 0, kSmiValueSize = 31 }; enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
static int SmiShiftSize() { return kSmiShiftSize; } static int SmiShiftSize() { return kSmiShiftSize; }
static int SmiValueSize() { return kSmiValueSize; } static int SmiValueSize() { return kSmiValueSize; }
V8_INLINE static int SmiToInt(const internal::Object* value) { V8_INLINE static int SmiToInt(const internal::Address value) {
int shift_bits = kSmiTagSize + kSmiShiftSize; int shift_bits = kSmiTagSize + kSmiShiftSize;
// Throw away top 32 bits and shift down (requires >> to be sign extending). // Shift down (requires >> to be sign extending).
return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; return static_cast<int>(static_cast<intptr_t>(value)) >> shift_bits;
} }
V8_INLINE static internal::Object* IntToSmi(int value) { V8_INLINE static internal::Address IntToSmi(int value) {
return internal::IntToSmi<kSmiShiftSize>(value); return internal::IntToSmi<kSmiShiftSize>(value);
} }
V8_INLINE static constexpr bool IsValidSmi(intptr_t value) { V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
// To be representable as an tagged small integer, the two // To be representable as an tagged small integer, the two
// most-significant bits of 'value' must be either 00 or 11 due to // most-significant bits of 'value' must be either 00 or 11 due to
// sign-extension. To check this we add 01 to the two // sign-extension. To check this we add 01 to the two
// most-significant bits, and check if the most-significant bit is 0 // most-significant bits, and check if the most-significant bit is 0.
// //
// CAUTION: The original code below: // CAUTION: The original code below:
// bool result = ((value + 0x40000000) & 0x80000000) == 0; // bool result = ((value + 0x40000000) & 0x80000000) == 0;
...@@ -88,12 +89,12 @@ struct SmiTagging<8> { ...@@ -88,12 +89,12 @@ struct SmiTagging<8> {
enum { kSmiShiftSize = 31, kSmiValueSize = 32 }; enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
static int SmiShiftSize() { return kSmiShiftSize; } static int SmiShiftSize() { return kSmiShiftSize; }
static int SmiValueSize() { return kSmiValueSize; } static int SmiValueSize() { return kSmiValueSize; }
V8_INLINE static int SmiToInt(const internal::Object* value) { V8_INLINE static int SmiToInt(const internal::Address value) {
int shift_bits = kSmiTagSize + kSmiShiftSize; int shift_bits = kSmiTagSize + kSmiShiftSize;
// Shift down and throw away top 32 bits. // Shift down and throw away top 32 bits.
return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); return static_cast<int>(static_cast<intptr_t>(value) >> shift_bits);
} }
V8_INLINE static internal::Object* IntToSmi(int value) { V8_INLINE static internal::Address IntToSmi(int value) {
return internal::IntToSmi<kSmiShiftSize>(value); return internal::IntToSmi<kSmiShiftSize>(value);
} }
V8_INLINE static constexpr bool IsValidSmi(intptr_t value) { V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
...@@ -191,16 +192,15 @@ class Internals { ...@@ -191,16 +192,15 @@ class Internals {
#endif #endif
} }
V8_INLINE static bool HasHeapObjectTag(const internal::Object* value) { V8_INLINE static bool HasHeapObjectTag(const internal::Address value) {
return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == return (value & kHeapObjectTagMask) == static_cast<Address>(kHeapObjectTag);
kHeapObjectTag);
} }
V8_INLINE static int SmiValue(const internal::Object* value) { V8_INLINE static int SmiValue(const internal::Address value) {
return PlatformSmiTagging::SmiToInt(value); return PlatformSmiTagging::SmiToInt(value);
} }
V8_INLINE static internal::Object* IntToSmi(int value) { V8_INLINE static internal::Address IntToSmi(int value) {
return PlatformSmiTagging::IntToSmi(value); return PlatformSmiTagging::IntToSmi(value);
} }
...@@ -208,15 +208,14 @@ class Internals { ...@@ -208,15 +208,14 @@ class Internals {
return PlatformSmiTagging::IsValidSmi(value); return PlatformSmiTagging::IsValidSmi(value);
} }
V8_INLINE static int GetInstanceType(const internal::Object* obj) { V8_INLINE static int GetInstanceType(const internal::Address obj) {
typedef internal::Object O; typedef internal::Address A;
O* map = ReadField<O*>(obj, kHeapObjectMapOffset); A map = ReadField<A>(obj, kHeapObjectMapOffset);
return ReadField<uint16_t>(map, kMapInstanceTypeOffset); return ReadField<uint16_t>(map, kMapInstanceTypeOffset);
} }
V8_INLINE static int GetOddballKind(const internal::Object* obj) { V8_INLINE static int GetOddballKind(const internal::Address obj) {
typedef internal::Object O; return SmiValue(ReadField<internal::Address>(obj, kOddballKindOffset));
return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
} }
V8_INLINE static bool IsExternalTwoByteString(int instance_type) { V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
...@@ -224,63 +223,66 @@ class Internals { ...@@ -224,63 +223,66 @@ class Internals {
return representation == kExternalTwoByteRepresentationTag; return representation == kExternalTwoByteRepresentationTag;
} }
V8_INLINE static uint8_t GetNodeFlag(internal::Object** obj, int shift) { V8_INLINE static uint8_t GetNodeFlag(internal::Address* obj, int shift) {
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
return *addr & static_cast<uint8_t>(1U << shift); return *addr & static_cast<uint8_t>(1U << shift);
} }
V8_INLINE static void UpdateNodeFlag(internal::Object** obj, bool value, V8_INLINE static void UpdateNodeFlag(internal::Address* obj, bool value,
int shift) { int shift) {
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
uint8_t mask = static_cast<uint8_t>(1U << shift); uint8_t mask = static_cast<uint8_t>(1U << shift);
*addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift)); *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
} }
V8_INLINE static uint8_t GetNodeState(internal::Object** obj) { V8_INLINE static uint8_t GetNodeState(internal::Address* obj) {
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
return *addr & kNodeStateMask; return *addr & kNodeStateMask;
} }
V8_INLINE static void UpdateNodeState(internal::Object** obj, uint8_t value) { V8_INLINE static void UpdateNodeState(internal::Address* obj, uint8_t value) {
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
*addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value); *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
} }
V8_INLINE static void SetEmbedderData(v8::Isolate* isolate, uint32_t slot, V8_INLINE static void SetEmbedderData(v8::Isolate* isolate, uint32_t slot,
void* data) { void* data) {
uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
kIsolateEmbedderDataOffset + slot * kApiPointerSize; kIsolateEmbedderDataOffset +
slot * kApiPointerSize;
*reinterpret_cast<void**>(addr) = data; *reinterpret_cast<void**>(addr) = data;
} }
V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate, V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
uint32_t slot) { uint32_t slot) {
const uint8_t* addr = reinterpret_cast<const uint8_t*>(isolate) + internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
kIsolateEmbedderDataOffset + slot * kApiPointerSize; kIsolateEmbedderDataOffset +
slot * kApiPointerSize;
return *reinterpret_cast<void* const*>(addr); return *reinterpret_cast<void* const*>(addr);
} }
V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate, int index) { V8_INLINE static internal::Address* GetRoot(v8::Isolate* isolate, int index) {
uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; internal::Address addr =
return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); reinterpret_cast<internal::Address>(isolate) + kIsolateRootsOffset;
return reinterpret_cast<internal::Address*>(addr + index * kApiPointerSize);
} }
template <typename T> template <typename T>
V8_INLINE static T ReadField(const internal::Object* ptr, int offset) { V8_INLINE static T ReadField(const internal::Address heap_object_ptr,
const uint8_t* addr = int offset) {
reinterpret_cast<const uint8_t*>(ptr) + offset - kHeapObjectTag; internal::Address addr = heap_object_ptr + offset - kHeapObjectTag;
return *reinterpret_cast<const T*>(addr); return *reinterpret_cast<const T*>(addr);
} }
template <typename T> template <typename T>
V8_INLINE static T ReadEmbedderData(const v8::Context* context, int index) { V8_INLINE static T ReadEmbedderData(const v8::Context* context, int index) {
typedef internal::Object O; typedef internal::Address A;
typedef internal::Internals I; typedef internal::Internals I;
O* ctx = *reinterpret_cast<O* const*>(context); A ctx = *reinterpret_cast<const A*>(context);
int embedder_data_offset = int embedder_data_offset =
I::kContextHeaderSize + I::kContextHeaderSize +
(internal::kApiPointerSize * I::kContextEmbedderDataIndex); (internal::kApiPointerSize * I::kContextEmbedderDataIndex);
O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset); A embedder_data = I::ReadField<A>(ctx, embedder_data_offset);
int value_offset = int value_offset =
I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index); I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
return I::ReadField<T>(embedder_data, value_offset); return I::ReadField<T>(embedder_data, value_offset);
......
...@@ -29,9 +29,8 @@ enum PersistentContainerCallbackType { ...@@ -29,9 +29,8 @@ enum PersistentContainerCallbackType {
kWeak = kWeakWithParameter // For backwards compatibility. Deprecate. kWeak = kWeakWithParameter // For backwards compatibility. Deprecate.
}; };
/** /**
* A default trait implemenation for PersistentValueMap which uses std::map * A default trait implementation for PersistentValueMap which uses std::map
* as a backing map. * as a backing map.
* *
* Users will have to implement their own weak callbacks & dispose traits. * Users will have to implement their own weak callbacks & dispose traits.
...@@ -203,7 +202,7 @@ class PersistentValueMapBase { ...@@ -203,7 +202,7 @@ class PersistentValueMapBase {
void RegisterExternallyReferencedObject(K& key) { void RegisterExternallyReferencedObject(K& key) {
assert(Contains(key)); assert(Contains(key));
V8::RegisterExternallyReferencedObject( V8::RegisterExternallyReferencedObject(
reinterpret_cast<internal::Object**>(FromVal(Traits::Get(&impl_, key))), reinterpret_cast<internal::Address*>(FromVal(Traits::Get(&impl_, key))),
reinterpret_cast<internal::Isolate*>(GetIsolate())); reinterpret_cast<internal::Isolate*>(GetIsolate()));
} }
...@@ -340,7 +339,7 @@ class PersistentValueMapBase { ...@@ -340,7 +339,7 @@ class PersistentValueMapBase {
bool hasValue = value != kPersistentContainerNotFound; bool hasValue = value != kPersistentContainerNotFound;
if (hasValue) { if (hasValue) {
returnValue->SetInternal( returnValue->SetInternal(
*reinterpret_cast<internal::Object**>(FromVal(value))); *reinterpret_cast<internal::Address*>(FromVal(value)));
} }
return hasValue; return hasValue;
} }
......
...@@ -118,7 +118,6 @@ class HeapObject; ...@@ -118,7 +118,6 @@ class HeapObject;
class Isolate; class Isolate;
class LocalEmbedderHeapTracer; class LocalEmbedderHeapTracer;
class NeverReadOnlySpaceObject; class NeverReadOnlySpaceObject;
class Object;
struct ScriptStreamingData; struct ScriptStreamingData;
template<typename T> class CustomArguments; template<typename T> class CustomArguments;
class PropertyCallbackArguments; class PropertyCallbackArguments;
...@@ -212,8 +211,8 @@ class Local { ...@@ -212,8 +211,8 @@ class Local {
*/ */
template <class S> template <class S>
V8_INLINE bool operator==(const Local<S>& that) const { V8_INLINE bool operator==(const Local<S>& that) const {
internal::Object** a = reinterpret_cast<internal::Object**>(this->val_); internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
internal::Object** b = reinterpret_cast<internal::Object**>(that.val_); internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
if (a == nullptr) return b == nullptr; if (a == nullptr) return b == nullptr;
if (b == nullptr) return false; if (b == nullptr) return false;
return *a == *b; return *a == *b;
...@@ -221,8 +220,8 @@ class Local { ...@@ -221,8 +220,8 @@ class Local {
template <class S> V8_INLINE bool operator==( template <class S> V8_INLINE bool operator==(
const PersistentBase<S>& that) const { const PersistentBase<S>& that) const {
internal::Object** a = reinterpret_cast<internal::Object**>(this->val_); internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
internal::Object** b = reinterpret_cast<internal::Object**>(that.val_); internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
if (a == nullptr) return b == nullptr; if (a == nullptr) return b == nullptr;
if (b == nullptr) return false; if (b == nullptr) return false;
return *a == *b; return *a == *b;
...@@ -477,8 +476,8 @@ template <class T> class PersistentBase { ...@@ -477,8 +476,8 @@ template <class T> class PersistentBase {
template <class S> template <class S>
V8_INLINE bool operator==(const PersistentBase<S>& that) const { V8_INLINE bool operator==(const PersistentBase<S>& that) const {
internal::Object** a = reinterpret_cast<internal::Object**>(this->val_); internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
internal::Object** b = reinterpret_cast<internal::Object**>(that.val_); internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
if (a == nullptr) return b == nullptr; if (a == nullptr) return b == nullptr;
if (b == nullptr) return false; if (b == nullptr) return false;
return *a == *b; return *a == *b;
...@@ -486,8 +485,8 @@ template <class T> class PersistentBase { ...@@ -486,8 +485,8 @@ template <class T> class PersistentBase {
template <class S> template <class S>
V8_INLINE bool operator==(const Local<S>& that) const { V8_INLINE bool operator==(const Local<S>& that) const {
internal::Object** a = reinterpret_cast<internal::Object**>(this->val_); internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
internal::Object** b = reinterpret_cast<internal::Object**>(that.val_); internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
if (a == nullptr) return b == nullptr; if (a == nullptr) return b == nullptr;
if (b == nullptr) return false; if (b == nullptr) return false;
return *a == *b; return *a == *b;
...@@ -859,8 +858,8 @@ class V8_EXPORT HandleScope { ...@@ -859,8 +858,8 @@ class V8_EXPORT HandleScope {
void Initialize(Isolate* isolate); void Initialize(Isolate* isolate);
static internal::Object** CreateHandle(internal::Isolate* isolate, static internal::Address* CreateHandle(internal::Isolate* isolate,
internal::Object* value); internal::Address value);
private: private:
// Declaring operator new and delete as deleted is not spec compliant. // Declaring operator new and delete as deleted is not spec compliant.
...@@ -871,12 +870,12 @@ class V8_EXPORT HandleScope { ...@@ -871,12 +870,12 @@ class V8_EXPORT HandleScope {
void operator delete[](void*, size_t); void operator delete[](void*, size_t);
// Uses heap_object to obtain the current Isolate. // Uses heap_object to obtain the current Isolate.
static internal::Object** CreateHandle( static internal::Address* CreateHandle(
internal::NeverReadOnlySpaceObject* heap_object, internal::Object* value); internal::NeverReadOnlySpaceObject* heap_object, internal::Address value);
internal::Isolate* isolate_; internal::Isolate* isolate_;
internal::Object** prev_next_; internal::Address* prev_next_;
internal::Object** prev_limit_; internal::Address* prev_limit_;
// Local::New uses CreateHandle with an Isolate* parameter. // Local::New uses CreateHandle with an Isolate* parameter.
template<class F> friend class Local; template<class F> friend class Local;
...@@ -903,8 +902,8 @@ class V8_EXPORT EscapableHandleScope : public HandleScope { ...@@ -903,8 +902,8 @@ class V8_EXPORT EscapableHandleScope : public HandleScope {
*/ */
template <class T> template <class T>
V8_INLINE Local<T> Escape(Local<T> value) { V8_INLINE Local<T> Escape(Local<T> value) {
internal::Object** slot = internal::Address* slot =
Escape(reinterpret_cast<internal::Object**>(*value)); Escape(reinterpret_cast<internal::Address*>(*value));
return Local<T>(reinterpret_cast<T*>(slot)); return Local<T>(reinterpret_cast<T*>(slot));
} }
...@@ -924,8 +923,8 @@ class V8_EXPORT EscapableHandleScope : public HandleScope { ...@@ -924,8 +923,8 @@ class V8_EXPORT EscapableHandleScope : public HandleScope {
void operator delete(void*, size_t); void operator delete(void*, size_t);
void operator delete[](void*, size_t); void operator delete[](void*, size_t);
internal::Object** Escape(internal::Object** escape_value); internal::Address* Escape(internal::Address* escape_value);
internal::Object** escape_slot_; internal::Address* escape_slot_;
}; };
/** /**
...@@ -950,7 +949,7 @@ class V8_EXPORT SealHandleScope { ...@@ -950,7 +949,7 @@ class V8_EXPORT SealHandleScope {
void operator delete[](void*, size_t); void operator delete[](void*, size_t);
internal::Isolate* const isolate_; internal::Isolate* const isolate_;
internal::Object** prev_limit_; internal::Address* prev_limit_;
int prev_sealed_level_; int prev_sealed_level_;
}; };
...@@ -2925,8 +2924,6 @@ class V8_EXPORT String : public Name { ...@@ -2925,8 +2924,6 @@ class V8_EXPORT String : public Name {
ExternalStringResource* GetExternalStringResourceSlow() const; ExternalStringResource* GetExternalStringResourceSlow() const;
ExternalStringResourceBase* GetExternalStringResourceBaseSlow( ExternalStringResourceBase* GetExternalStringResourceBaseSlow(
String::Encoding* encoding_out) const; String::Encoding* encoding_out) const;
const ExternalOneByteStringResource* GetExternalOneByteStringResourceSlow()
const;
static void CheckCast(v8::Value* obj); static void CheckCast(v8::Value* obj);
}; };
...@@ -3797,10 +3794,10 @@ class ReturnValue { ...@@ -3797,10 +3794,10 @@ class ReturnValue {
template<class F> friend class PropertyCallbackInfo; template<class F> friend class PropertyCallbackInfo;
template <class F, class G, class H> template <class F, class G, class H>
friend class PersistentValueMapBase; friend class PersistentValueMapBase;
V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; } V8_INLINE void SetInternal(internal::Address value) { *value_ = value; }
V8_INLINE internal::Object* GetDefaultValue(); V8_INLINE internal::Address GetDefaultValue();
V8_INLINE explicit ReturnValue(internal::Object** slot); V8_INLINE explicit ReturnValue(internal::Address* slot);
internal::Object** value_; internal::Address* value_;
}; };
...@@ -3854,10 +3851,10 @@ class FunctionCallbackInfo { ...@@ -3854,10 +3851,10 @@ class FunctionCallbackInfo {
static const int kDataIndex = 4; static const int kDataIndex = 4;
static const int kNewTargetIndex = 5; static const int kNewTargetIndex = 5;
V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args, V8_INLINE FunctionCallbackInfo(internal::Address* implicit_args,
internal::Object** values, int length); internal::Address* values, int length);
internal::Object** implicit_args_; internal::Address* implicit_args_;
internal::Object** values_; internal::Address* values_;
int length_; int length_;
}; };
...@@ -3969,8 +3966,8 @@ class PropertyCallbackInfo { ...@@ -3969,8 +3966,8 @@ class PropertyCallbackInfo {
static const int kDataIndex = 5; static const int kDataIndex = 5;
static const int kThisIndex = 6; static const int kThisIndex = 6;
V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {} V8_INLINE PropertyCallbackInfo(internal::Address* args) : args_(args) {}
internal::Object** args_; internal::Address* args_;
}; };
...@@ -8275,7 +8272,7 @@ class V8_EXPORT Isolate { ...@@ -8275,7 +8272,7 @@ class V8_EXPORT Isolate {
template <class K, class V, class Traits> template <class K, class V, class Traits>
friend class PersistentValueMapBase; friend class PersistentValueMapBase;
internal::Object** GetDataFromSnapshotOnce(size_t index); internal::Address* GetDataFromSnapshotOnce(size_t index);
void ReportExternalAllocationLimitReached(); void ReportExternalAllocationLimitReached();
void CheckMemoryPressure(); void CheckMemoryPressure();
}; };
...@@ -8478,26 +8475,20 @@ class V8_EXPORT V8 { ...@@ -8478,26 +8475,20 @@ class V8_EXPORT V8 {
private: private:
V8(); V8();
static internal::Object** GlobalizeReference(internal::Isolate* isolate, static internal::Address* GlobalizeReference(internal::Isolate* isolate,
internal::Object** handle); internal::Address* handle);
static internal::Object** CopyPersistent(internal::Object** handle); static internal::Address* CopyPersistent(internal::Address* handle);
static void DisposeGlobal(internal::Object** global_handle); static void DisposeGlobal(internal::Address* global_handle);
static void MakeWeak(internal::Object** location, void* data, static void MakeWeak(internal::Address* location, void* data,
WeakCallbackInfo<void>::Callback weak_callback, WeakCallbackInfo<void>::Callback weak_callback,
WeakCallbackType type); WeakCallbackType type);
static void MakeWeak(internal::Object** location, void* data, static void MakeWeak(internal::Address** location_addr);
// Must be 0 or -1. static void* ClearWeak(internal::Address* location);
int internal_field_index1, static void AnnotateStrongRetainer(internal::Address* location,
// Must be 1 or -1.
int internal_field_index2,
WeakCallbackInfo<void>::Callback weak_callback);
static void MakeWeak(internal::Object*** location_addr);
static void* ClearWeak(internal::Object** location);
static void AnnotateStrongRetainer(internal::Object** location,
const char* label); const char* label);
static Value* Eternalize(Isolate* isolate, Value* handle); static Value* Eternalize(Isolate* isolate, Value* handle);
static void RegisterExternallyReferencedObject(internal::Object** object, static void RegisterExternallyReferencedObject(internal::Address* location,
internal::Isolate* isolate); internal::Isolate* isolate);
template <class K, class V, class T> template <class K, class V, class T>
...@@ -8618,8 +8609,8 @@ class V8_EXPORT SnapshotCreator { ...@@ -8618,8 +8609,8 @@ class V8_EXPORT SnapshotCreator {
void operator=(const SnapshotCreator&) = delete; void operator=(const SnapshotCreator&) = delete;
private: private:
size_t AddData(Local<Context> context, internal::Object* object); size_t AddData(Local<Context> context, internal::Address object);
size_t AddData(internal::Object* object); size_t AddData(internal::Address object);
void* data_; void* data_;
}; };
...@@ -9162,7 +9153,7 @@ class V8_EXPORT Context { ...@@ -9162,7 +9153,7 @@ class V8_EXPORT Context {
friend class Object; friend class Object;
friend class Function; friend class Function;
internal::Object** GetDataFromSnapshotOnce(size_t index); internal::Address* GetDataFromSnapshotOnce(size_t index);
Local<Value> SlowGetEmbedderData(int index); Local<Value> SlowGetEmbedderData(int index);
void* SlowGetAlignedPointerFromEmbedderData(int index); void* SlowGetAlignedPointerFromEmbedderData(int index);
}; };
...@@ -9309,7 +9300,7 @@ template <class T> ...@@ -9309,7 +9300,7 @@ template <class T>
Local<T> Local<T>::New(Isolate* isolate, T* that) { Local<T> Local<T>::New(Isolate* isolate, T* that) {
if (that == nullptr) return Local<T>(); if (that == nullptr) return Local<T>();
T* that_ptr = that; T* that_ptr = that;
internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); internal::Address* p = reinterpret_cast<internal::Address*>(that_ptr);
return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
reinterpret_cast<internal::Isolate*>(isolate), *p))); reinterpret_cast<internal::Isolate*>(isolate), *p)));
} }
...@@ -9352,7 +9343,7 @@ void* WeakCallbackInfo<T>::GetInternalField(int index) const { ...@@ -9352,7 +9343,7 @@ void* WeakCallbackInfo<T>::GetInternalField(int index) const {
template <class T> template <class T>
T* PersistentBase<T>::New(Isolate* isolate, T* that) { T* PersistentBase<T>::New(Isolate* isolate, T* that) {
if (that == nullptr) return nullptr; if (that == nullptr) return nullptr;
internal::Object** p = reinterpret_cast<internal::Object**>(that); internal::Address* p = reinterpret_cast<internal::Address*>(that);
return reinterpret_cast<T*>( return reinterpret_cast<T*>(
V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
p)); p));
...@@ -9365,7 +9356,7 @@ void Persistent<T, M>::Copy(const Persistent<S, M2>& that) { ...@@ -9365,7 +9356,7 @@ void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
TYPE_CHECK(T, S); TYPE_CHECK(T, S);
this->Reset(); this->Reset();
if (that.IsEmpty()) return; if (that.IsEmpty()) return;
internal::Object** p = reinterpret_cast<internal::Object**>(that.val_); internal::Address* p = reinterpret_cast<internal::Address*>(that.val_);
this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p)); this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p));
M::Copy(that, this); M::Copy(that, this);
} }
...@@ -9374,7 +9365,7 @@ template <class T> ...@@ -9374,7 +9365,7 @@ template <class T>
bool PersistentBase<T>::IsIndependent() const { bool PersistentBase<T>::IsIndependent() const {
typedef internal::Internals I; typedef internal::Internals I;
if (this->IsEmpty()) return false; if (this->IsEmpty()) return false;
return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), return I::GetNodeFlag(reinterpret_cast<internal::Address*>(this->val_),
I::kNodeIsIndependentShift); I::kNodeIsIndependentShift);
} }
...@@ -9383,7 +9374,7 @@ bool PersistentBase<T>::IsNearDeath() const { ...@@ -9383,7 +9374,7 @@ bool PersistentBase<T>::IsNearDeath() const {
typedef internal::Internals I; typedef internal::Internals I;
if (this->IsEmpty()) return false; if (this->IsEmpty()) return false;
uint8_t node_state = uint8_t node_state =
I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)); I::GetNodeState(reinterpret_cast<internal::Address*>(this->val_));
return node_state == I::kNodeStateIsNearDeathValue || return node_state == I::kNodeStateIsNearDeathValue ||
node_state == I::kNodeStateIsPendingValue; node_state == I::kNodeStateIsPendingValue;
} }
...@@ -9393,15 +9384,15 @@ template <class T> ...@@ -9393,15 +9384,15 @@ template <class T>
bool PersistentBase<T>::IsWeak() const { bool PersistentBase<T>::IsWeak() const {
typedef internal::Internals I; typedef internal::Internals I;
if (this->IsEmpty()) return false; if (this->IsEmpty()) return false;
return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == return I::GetNodeState(reinterpret_cast<internal::Address*>(this->val_)) ==
I::kNodeStateIsWeakValue; I::kNodeStateIsWeakValue;
} }
template <class T> template <class T>
void PersistentBase<T>::Reset() { void PersistentBase<T>::Reset() {
if (this->IsEmpty()) return; if (this->IsEmpty()) return;
V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_)); V8::DisposeGlobal(reinterpret_cast<internal::Address*>(this->val_));
val_ = nullptr; val_ = nullptr;
} }
...@@ -9433,25 +9424,25 @@ V8_INLINE void PersistentBase<T>::SetWeak( ...@@ -9433,25 +9424,25 @@ V8_INLINE void PersistentBase<T>::SetWeak(
P* parameter, typename WeakCallbackInfo<P>::Callback callback, P* parameter, typename WeakCallbackInfo<P>::Callback callback,
WeakCallbackType type) { WeakCallbackType type) {
typedef typename WeakCallbackInfo<void>::Callback Callback; typedef typename WeakCallbackInfo<void>::Callback Callback;
V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter, V8::MakeWeak(reinterpret_cast<internal::Address*>(this->val_), parameter,
reinterpret_cast<Callback>(callback), type); reinterpret_cast<Callback>(callback), type);
} }
template <class T> template <class T>
void PersistentBase<T>::SetWeak() { void PersistentBase<T>::SetWeak() {
V8::MakeWeak(reinterpret_cast<internal::Object***>(&this->val_)); V8::MakeWeak(reinterpret_cast<internal::Address**>(&this->val_));
} }
template <class T> template <class T>
template <typename P> template <typename P>
P* PersistentBase<T>::ClearWeak() { P* PersistentBase<T>::ClearWeak() {
return reinterpret_cast<P*>( return reinterpret_cast<P*>(
V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_))); V8::ClearWeak(reinterpret_cast<internal::Address*>(this->val_)));
} }
template <class T> template <class T>
void PersistentBase<T>::AnnotateStrongRetainer(const char* label) { void PersistentBase<T>::AnnotateStrongRetainer(const char* label) {
V8::AnnotateStrongRetainer(reinterpret_cast<internal::Object**>(this->val_), V8::AnnotateStrongRetainer(reinterpret_cast<internal::Address*>(this->val_),
label); label);
} }
...@@ -9459,7 +9450,7 @@ template <class T> ...@@ -9459,7 +9450,7 @@ template <class T>
void PersistentBase<T>::RegisterExternalReference(Isolate* isolate) const { void PersistentBase<T>::RegisterExternalReference(Isolate* isolate) const {
if (IsEmpty()) return; if (IsEmpty()) return;
V8::RegisterExternallyReferencedObject( V8::RegisterExternallyReferencedObject(
reinterpret_cast<internal::Object**>(this->val_), reinterpret_cast<internal::Address*>(this->val_),
reinterpret_cast<internal::Isolate*>(isolate)); reinterpret_cast<internal::Isolate*>(isolate));
} }
...@@ -9467,7 +9458,7 @@ template <class T> ...@@ -9467,7 +9458,7 @@ template <class T>
void PersistentBase<T>::MarkIndependent() { void PersistentBase<T>::MarkIndependent() {
typedef internal::Internals I; typedef internal::Internals I;
if (this->IsEmpty()) return; if (this->IsEmpty()) return;
I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), true, I::UpdateNodeFlag(reinterpret_cast<internal::Address*>(this->val_), true,
I::kNodeIsIndependentShift); I::kNodeIsIndependentShift);
} }
...@@ -9475,7 +9466,7 @@ template <class T> ...@@ -9475,7 +9466,7 @@ template <class T>
void PersistentBase<T>::MarkActive() { void PersistentBase<T>::MarkActive() {
typedef internal::Internals I; typedef internal::Internals I;
if (this->IsEmpty()) return; if (this->IsEmpty()) return;
I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), true, I::UpdateNodeFlag(reinterpret_cast<internal::Address*>(this->val_), true,
I::kNodeIsActiveShift); I::kNodeIsActiveShift);
} }
...@@ -9484,7 +9475,7 @@ template <class T> ...@@ -9484,7 +9475,7 @@ template <class T>
void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) { void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) {
typedef internal::Internals I; typedef internal::Internals I;
if (this->IsEmpty()) return; if (this->IsEmpty()) return;
internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); internal::Address* obj = reinterpret_cast<internal::Address*>(this->val_);
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
*reinterpret_cast<uint16_t*>(addr) = class_id; *reinterpret_cast<uint16_t*>(addr) = class_id;
} }
...@@ -9494,14 +9485,13 @@ template <class T> ...@@ -9494,14 +9485,13 @@ template <class T>
uint16_t PersistentBase<T>::WrapperClassId() const { uint16_t PersistentBase<T>::WrapperClassId() const {
typedef internal::Internals I; typedef internal::Internals I;
if (this->IsEmpty()) return 0; if (this->IsEmpty()) return 0;
internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); internal::Address* obj = reinterpret_cast<internal::Address*>(this->val_);
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
return *reinterpret_cast<uint16_t*>(addr); return *reinterpret_cast<uint16_t*>(addr);
} }
template <typename T>
template<typename T> ReturnValue<T>::ReturnValue(internal::Address* slot) : value_(slot) {}
ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
template<typename T> template<typename T>
template<typename S> template<typename S>
...@@ -9510,7 +9500,7 @@ void ReturnValue<T>::Set(const Persistent<S>& handle) { ...@@ -9510,7 +9500,7 @@ void ReturnValue<T>::Set(const Persistent<S>& handle) {
if (V8_UNLIKELY(handle.IsEmpty())) { if (V8_UNLIKELY(handle.IsEmpty())) {
*value_ = GetDefaultValue(); *value_ = GetDefaultValue();
} else { } else {
*value_ = *reinterpret_cast<internal::Object**>(*handle); *value_ = *reinterpret_cast<internal::Address*>(*handle);
} }
} }
...@@ -9521,7 +9511,7 @@ void ReturnValue<T>::Set(const Global<S>& handle) { ...@@ -9521,7 +9511,7 @@ void ReturnValue<T>::Set(const Global<S>& handle) {
if (V8_UNLIKELY(handle.IsEmpty())) { if (V8_UNLIKELY(handle.IsEmpty())) {
*value_ = GetDefaultValue(); *value_ = GetDefaultValue();
} else { } else {
*value_ = *reinterpret_cast<internal::Object**>(*handle); *value_ = *reinterpret_cast<internal::Address*>(*handle);
} }
} }
...@@ -9532,7 +9522,7 @@ void ReturnValue<T>::Set(const Local<S> handle) { ...@@ -9532,7 +9522,7 @@ void ReturnValue<T>::Set(const Local<S> handle) {
if (V8_UNLIKELY(handle.IsEmpty())) { if (V8_UNLIKELY(handle.IsEmpty())) {
*value_ = GetDefaultValue(); *value_ = GetDefaultValue();
} else { } else {
*value_ = *reinterpret_cast<internal::Object**>(*handle); *value_ = *reinterpret_cast<internal::Address*>(*handle);
} }
} }
...@@ -9620,15 +9610,15 @@ void ReturnValue<T>::Set(S* whatever) { ...@@ -9620,15 +9610,15 @@ void ReturnValue<T>::Set(S* whatever) {
TYPE_CHECK(S*, Primitive); TYPE_CHECK(S*, Primitive);
} }
template<typename T> template <typename T>
internal::Object* ReturnValue<T>::GetDefaultValue() { internal::Address ReturnValue<T>::GetDefaultValue() {
// Default value is always the pointer below value_ on the stack. // Default value is always the pointer below value_ on the stack.
return value_[-1]; return value_[-1];
} }
template <typename T> template <typename T>
FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args, FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Address* implicit_args,
internal::Object** values, internal::Address* values,
int length) int length)
: implicit_args_(implicit_args), values_(values), length_(length) {} : implicit_args_(implicit_args), values_(values), length_(length) {}
...@@ -9798,9 +9788,9 @@ AccessorSignature* AccessorSignature::Cast(Data* data) { ...@@ -9798,9 +9788,9 @@ AccessorSignature* AccessorSignature::Cast(Data* data) {
Local<Value> Object::GetInternalField(int index) { Local<Value> Object::GetInternalField(int index) {
#ifndef V8_ENABLE_CHECKS #ifndef V8_ENABLE_CHECKS
typedef internal::Object O; typedef internal::Address A;
typedef internal::Internals I; typedef internal::Internals I;
O* obj = *reinterpret_cast<O**>(this); A obj = *reinterpret_cast<A*>(this);
// Fast path: If the object is a plain JSObject, which is the common case, we // Fast path: If the object is a plain JSObject, which is the common case, we
// know where to find the internal fields and can return the value directly. // know where to find the internal fields and can return the value directly.
auto instance_type = I::GetInstanceType(obj); auto instance_type = I::GetInstanceType(obj);
...@@ -9808,8 +9798,8 @@ Local<Value> Object::GetInternalField(int index) { ...@@ -9808,8 +9798,8 @@ Local<Value> Object::GetInternalField(int index) {
instance_type == I::kJSApiObjectType || instance_type == I::kJSApiObjectType ||
instance_type == I::kJSSpecialApiObjectType) { instance_type == I::kJSSpecialApiObjectType) {
int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
O* value = I::ReadField<O*>(obj, offset); A value = I::ReadField<A>(obj, offset);
O** result = HandleScope::CreateHandle( A* result = HandleScope::CreateHandle(
reinterpret_cast<internal::NeverReadOnlySpaceObject*>(obj), value); reinterpret_cast<internal::NeverReadOnlySpaceObject*>(obj), value);
return Local<Value>(reinterpret_cast<Value*>(result)); return Local<Value>(reinterpret_cast<Value*>(result));
} }
...@@ -9820,9 +9810,9 @@ Local<Value> Object::GetInternalField(int index) { ...@@ -9820,9 +9810,9 @@ Local<Value> Object::GetInternalField(int index) {
void* Object::GetAlignedPointerFromInternalField(int index) { void* Object::GetAlignedPointerFromInternalField(int index) {
#ifndef V8_ENABLE_CHECKS #ifndef V8_ENABLE_CHECKS
typedef internal::Object O; typedef internal::Address A;
typedef internal::Internals I; typedef internal::Internals I;
O* obj = *reinterpret_cast<O**>(this); A obj = *reinterpret_cast<A*>(this);
// Fast path: If the object is a plain JSObject, which is the common case, we // Fast path: If the object is a plain JSObject, which is the common case, we
// know where to find the internal fields and can return the value directly. // know where to find the internal fields and can return the value directly.
auto instance_type = I::GetInstanceType(obj); auto instance_type = I::GetInstanceType(obj);
...@@ -9845,7 +9835,7 @@ String* String::Cast(v8::Value* value) { ...@@ -9845,7 +9835,7 @@ String* String::Cast(v8::Value* value) {
Local<String> String::Empty(Isolate* isolate) { Local<String> String::Empty(Isolate* isolate) {
typedef internal::Object* S; typedef internal::Address S;
typedef internal::Internals I; typedef internal::Internals I;
I::CheckInitialized(isolate); I::CheckInitialized(isolate);
S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex); S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
...@@ -9854,9 +9844,9 @@ Local<String> String::Empty(Isolate* isolate) { ...@@ -9854,9 +9844,9 @@ Local<String> String::Empty(Isolate* isolate) {
String::ExternalStringResource* String::GetExternalStringResource() const { String::ExternalStringResource* String::GetExternalStringResource() const {
typedef internal::Object O; typedef internal::Address A;
typedef internal::Internals I; typedef internal::Internals I;
O* obj = *reinterpret_cast<O* const*>(this); A obj = *reinterpret_cast<const A*>(this);
ExternalStringResource* result; ExternalStringResource* result;
if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
...@@ -9874,9 +9864,9 @@ String::ExternalStringResource* String::GetExternalStringResource() const { ...@@ -9874,9 +9864,9 @@ String::ExternalStringResource* String::GetExternalStringResource() const {
String::ExternalStringResourceBase* String::GetExternalStringResourceBase( String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
String::Encoding* encoding_out) const { String::Encoding* encoding_out) const {
typedef internal::Object O; typedef internal::Address A;
typedef internal::Internals I; typedef internal::Internals I;
O* obj = *reinterpret_cast<O* const*>(this); A obj = *reinterpret_cast<const A*>(this);
int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask; int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
*encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask); *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
ExternalStringResourceBase* resource; ExternalStringResourceBase* resource;
...@@ -9903,9 +9893,9 @@ bool Value::IsUndefined() const { ...@@ -9903,9 +9893,9 @@ bool Value::IsUndefined() const {
} }
bool Value::QuickIsUndefined() const { bool Value::QuickIsUndefined() const {
typedef internal::Object O; typedef internal::Address A;
typedef internal::Internals I; typedef internal::Internals I;
O* obj = *reinterpret_cast<O* const*>(this); A obj = *reinterpret_cast<const A*>(this);
if (!I::HasHeapObjectTag(obj)) return false; if (!I::HasHeapObjectTag(obj)) return false;
if (I::GetInstanceType(obj) != I::kOddballType) return false; if (I::GetInstanceType(obj) != I::kOddballType) return false;
return (I::GetOddballKind(obj) == I::kUndefinedOddballKind); return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
...@@ -9921,9 +9911,9 @@ bool Value::IsNull() const { ...@@ -9921,9 +9911,9 @@ bool Value::IsNull() const {
} }
bool Value::QuickIsNull() const { bool Value::QuickIsNull() const {
typedef internal::Object O; typedef internal::Address A;
typedef internal::Internals I; typedef internal::Internals I;
O* obj = *reinterpret_cast<O* const*>(this); A obj = *reinterpret_cast<const A*>(this);
if (!I::HasHeapObjectTag(obj)) return false; if (!I::HasHeapObjectTag(obj)) return false;
if (I::GetInstanceType(obj) != I::kOddballType) return false; if (I::GetInstanceType(obj) != I::kOddballType) return false;
return (I::GetOddballKind(obj) == I::kNullOddballKind); return (I::GetOddballKind(obj) == I::kNullOddballKind);
...@@ -9938,9 +9928,9 @@ bool Value::IsNullOrUndefined() const { ...@@ -9938,9 +9928,9 @@ bool Value::IsNullOrUndefined() const {
} }
bool Value::QuickIsNullOrUndefined() const { bool Value::QuickIsNullOrUndefined() const {
typedef internal::Object O; typedef internal::Address A;
typedef internal::Internals I; typedef internal::Internals I;
O* obj = *reinterpret_cast<O* const*>(this); A obj = *reinterpret_cast<const A*>(this);
if (!I::HasHeapObjectTag(obj)) return false; if (!I::HasHeapObjectTag(obj)) return false;
if (I::GetInstanceType(obj) != I::kOddballType) return false; if (I::GetInstanceType(obj) != I::kOddballType) return false;
int kind = I::GetOddballKind(obj); int kind = I::GetOddballKind(obj);
...@@ -9956,9 +9946,9 @@ bool Value::IsString() const { ...@@ -9956,9 +9946,9 @@ bool Value::IsString() const {
} }
bool Value::QuickIsString() const { bool Value::QuickIsString() const {
typedef internal::Object O; typedef internal::Address A;
typedef internal::Internals I; typedef internal::Internals I;
O* obj = *reinterpret_cast<O* const*>(this); A obj = *reinterpret_cast<const A*>(this);
if (!I::HasHeapObjectTag(obj)) return false; if (!I::HasHeapObjectTag(obj)) return false;
return (I::GetInstanceType(obj) < I::kFirstNonstringType); return (I::GetInstanceType(obj) < I::kFirstNonstringType);
} }
...@@ -10333,7 +10323,7 @@ bool PropertyCallbackInfo<T>::ShouldThrowOnError() const { ...@@ -10333,7 +10323,7 @@ bool PropertyCallbackInfo<T>::ShouldThrowOnError() const {
Local<Primitive> Undefined(Isolate* isolate) { Local<Primitive> Undefined(Isolate* isolate) {
typedef internal::Object* S; typedef internal::Address S;
typedef internal::Internals I; typedef internal::Internals I;
I::CheckInitialized(isolate); I::CheckInitialized(isolate);
S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex); S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
...@@ -10342,7 +10332,7 @@ Local<Primitive> Undefined(Isolate* isolate) { ...@@ -10342,7 +10332,7 @@ Local<Primitive> Undefined(Isolate* isolate) {
Local<Primitive> Null(Isolate* isolate) { Local<Primitive> Null(Isolate* isolate) {
typedef internal::Object* S; typedef internal::Address S;
typedef internal::Internals I; typedef internal::Internals I;
I::CheckInitialized(isolate); I::CheckInitialized(isolate);
S* slot = I::GetRoot(isolate, I::kNullValueRootIndex); S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
...@@ -10351,7 +10341,7 @@ Local<Primitive> Null(Isolate* isolate) { ...@@ -10351,7 +10341,7 @@ Local<Primitive> Null(Isolate* isolate) {
Local<Boolean> True(Isolate* isolate) { Local<Boolean> True(Isolate* isolate) {
typedef internal::Object* S; typedef internal::Address S;
typedef internal::Internals I; typedef internal::Internals I;
I::CheckInitialized(isolate); I::CheckInitialized(isolate);
S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex); S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
...@@ -10360,7 +10350,7 @@ Local<Boolean> True(Isolate* isolate) { ...@@ -10360,7 +10350,7 @@ Local<Boolean> True(Isolate* isolate) {
Local<Boolean> False(Isolate* isolate) { Local<Boolean> False(Isolate* isolate) {
typedef internal::Object* S; typedef internal::Address S;
typedef internal::Internals I; typedef internal::Internals I;
I::CheckInitialized(isolate); I::CheckInitialized(isolate);
S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
...@@ -10428,11 +10418,11 @@ int64_t Isolate::AdjustAmountOfExternalAllocatedMemory( ...@@ -10428,11 +10418,11 @@ int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
Local<Value> Context::GetEmbedderData(int index) { Local<Value> Context::GetEmbedderData(int index) {
#ifndef V8_ENABLE_CHECKS #ifndef V8_ENABLE_CHECKS
typedef internal::Object O; typedef internal::Address A;
typedef internal::Internals I; typedef internal::Internals I;
auto* context = *reinterpret_cast<internal::NeverReadOnlySpaceObject**>(this); auto* context = *reinterpret_cast<internal::NeverReadOnlySpaceObject**>(this);
O** result = A* result =
HandleScope::CreateHandle(context, I::ReadEmbedderData<O*>(this, index)); HandleScope::CreateHandle(context, I::ReadEmbedderData<A>(this, index));
return Local<Value>(reinterpret_cast<Value*>(result)); return Local<Value>(reinterpret_cast<Value*>(result));
#else #else
return SlowGetEmbedderData(index); return SlowGetEmbedderData(index);
...@@ -10459,14 +10449,14 @@ MaybeLocal<T> Context::GetDataFromSnapshotOnce(size_t index) { ...@@ -10459,14 +10449,14 @@ MaybeLocal<T> Context::GetDataFromSnapshotOnce(size_t index) {
template <class T> template <class T>
size_t SnapshotCreator::AddData(Local<Context> context, Local<T> object) { size_t SnapshotCreator::AddData(Local<Context> context, Local<T> object) {
T* object_ptr = *object; T* object_ptr = *object;
internal::Object** p = reinterpret_cast<internal::Object**>(object_ptr); internal::Address* p = reinterpret_cast<internal::Address*>(object_ptr);
return AddData(context, *p); return AddData(context, *p);
} }
template <class T> template <class T>
size_t SnapshotCreator::AddData(Local<T> object) { size_t SnapshotCreator::AddData(Local<T> object) {
T* object_ptr = *object; T* object_ptr = *object;
internal::Object** p = reinterpret_cast<internal::Object**>(object_ptr); internal::Address* p = reinterpret_cast<internal::Address*>(object_ptr);
return AddData(*p); return AddData(*p);
} }
......
...@@ -61,7 +61,8 @@ inline JSObject* FunctionCallbackArguments::holder() { ...@@ -61,7 +61,8 @@ inline JSObject* FunctionCallbackArguments::holder() {
} \ } \
VMState<EXTERNAL> state(ISOLATE); \ VMState<EXTERNAL> state(ISOLATE); \
ExternalCallbackScope call_scope(ISOLATE, FUNCTION_ADDR(F)); \ ExternalCallbackScope call_scope(ISOLATE, FUNCTION_ADDR(F)); \
PropertyCallbackInfo<API_RETURN_TYPE> callback_info(begin()); PropertyCallbackInfo<API_RETURN_TYPE> callback_info( \
reinterpret_cast<Address*>(begin()));
#define PREPARE_CALLBACK_INFO_FAIL_SIDE_EFFECT_CHECK(ISOLATE, F, RETURN_VALUE, \ #define PREPARE_CALLBACK_INFO_FAIL_SIDE_EFFECT_CHECK(ISOLATE, F, RETURN_VALUE, \
API_RETURN_TYPE) \ API_RETURN_TYPE) \
...@@ -70,7 +71,8 @@ inline JSObject* FunctionCallbackArguments::holder() { ...@@ -70,7 +71,8 @@ inline JSObject* FunctionCallbackArguments::holder() {
} \ } \
VMState<EXTERNAL> state(ISOLATE); \ VMState<EXTERNAL> state(ISOLATE); \
ExternalCallbackScope call_scope(ISOLATE, FUNCTION_ADDR(F)); \ ExternalCallbackScope call_scope(ISOLATE, FUNCTION_ADDR(F)); \
PropertyCallbackInfo<API_RETURN_TYPE> callback_info(begin()); PropertyCallbackInfo<API_RETURN_TYPE> callback_info( \
reinterpret_cast<Address*>(begin()));
#define CREATE_NAMED_CALLBACK(FUNCTION, TYPE, RETURN_TYPE, API_RETURN_TYPE, \ #define CREATE_NAMED_CALLBACK(FUNCTION, TYPE, RETURN_TYPE, API_RETURN_TYPE, \
INFO_FOR_SIDE_EFFECT) \ INFO_FOR_SIDE_EFFECT) \
...@@ -136,7 +138,9 @@ Handle<Object> FunctionCallbackArguments::Call(CallHandlerInfo* handler) { ...@@ -136,7 +138,9 @@ Handle<Object> FunctionCallbackArguments::Call(CallHandlerInfo* handler) {
} }
VMState<EXTERNAL> state(isolate); VMState<EXTERNAL> state(isolate);
ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
FunctionCallbackInfo<v8::Value> info(begin(), argv_, argc_); FunctionCallbackInfo<v8::Value> info(reinterpret_cast<Address*>(begin()),
reinterpret_cast<Address*>(argv_),
argc_);
f(info); f(info);
return GetReturnValue<Object>(isolate); return GetReturnValue<Object>(isolate);
} }
......
...@@ -611,13 +611,13 @@ size_t SnapshotCreator::AddTemplate(Local<Template> template_obj) { ...@@ -611,13 +611,13 @@ size_t SnapshotCreator::AddTemplate(Local<Template> template_obj) {
return AddData(template_obj); return AddData(template_obj);
} }
size_t SnapshotCreator::AddData(i::Object* object) { size_t SnapshotCreator::AddData(i::Address object) {
DCHECK_NOT_NULL(object); DCHECK_NE(object, i::kNullAddress);
SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
DCHECK(!data->created_); DCHECK(!data->created_);
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(data->isolate_); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(data->isolate_);
i::HandleScope scope(isolate); i::HandleScope scope(isolate);
i::Handle<i::Object> obj(object, isolate); i::Handle<i::Object> obj(reinterpret_cast<i::Object*>(object), isolate);
i::Handle<i::ArrayList> list; i::Handle<i::ArrayList> list;
if (!isolate->heap()->serialized_objects()->IsArrayList()) { if (!isolate->heap()->serialized_objects()->IsArrayList()) {
list = i::ArrayList::New(isolate, 1); list = i::ArrayList::New(isolate, 1);
...@@ -631,13 +631,13 @@ size_t SnapshotCreator::AddData(i::Object* object) { ...@@ -631,13 +631,13 @@ size_t SnapshotCreator::AddData(i::Object* object) {
return index; return index;
} }
size_t SnapshotCreator::AddData(Local<Context> context, i::Object* object) { size_t SnapshotCreator::AddData(Local<Context> context, i::Address object) {
DCHECK_NOT_NULL(object); DCHECK_NE(object, i::kNullAddress);
DCHECK(!SnapshotCreatorData::cast(data_)->created_); DCHECK(!SnapshotCreatorData::cast(data_)->created_);
i::Handle<i::Context> ctx = Utils::OpenHandle(*context); i::Handle<i::Context> ctx = Utils::OpenHandle(*context);
i::Isolate* isolate = ctx->GetIsolate(); i::Isolate* isolate = ctx->GetIsolate();
i::HandleScope scope(isolate); i::HandleScope scope(isolate);
i::Handle<i::Object> obj(object, isolate); i::Handle<i::Object> obj(reinterpret_cast<i::Object*>(object), isolate);
i::Handle<i::ArrayList> list; i::Handle<i::ArrayList> list;
if (!ctx->serialized_objects()->IsArrayList()) { if (!ctx->serialized_objects()->IsArrayList()) {
list = i::ArrayList::New(isolate, 1); list = i::ArrayList::New(isolate, 1);
...@@ -966,66 +966,46 @@ void SetResourceConstraints(i::Isolate* isolate, ...@@ -966,66 +966,46 @@ void SetResourceConstraints(i::Isolate* isolate,
} }
} }
i::Address* V8::GlobalizeReference(i::Isolate* isolate, i::Address* obj) {
i::Object** V8::GlobalizeReference(i::Isolate* isolate, i::Object** obj) {
LOG_API(isolate, Persistent, New); LOG_API(isolate, Persistent, New);
i::Handle<i::Object> result = isolate->global_handles()->Create(*obj); i::Handle<i::Object> result = isolate->global_handles()->Create(*obj);
#ifdef VERIFY_HEAP #ifdef VERIFY_HEAP
if (i::FLAG_verify_heap) { if (i::FLAG_verify_heap) {
(*obj)->ObjectVerify(isolate); reinterpret_cast<i::Object*>(*obj)->ObjectVerify(isolate);
} }
#endif // VERIFY_HEAP #endif // VERIFY_HEAP
return result.location(); return result.location_as_address_ptr();
} }
i::Address* V8::CopyPersistent(i::Address* obj) {
i::Object** V8::CopyPersistent(i::Object** obj) {
i::Handle<i::Object> result = i::GlobalHandles::CopyGlobal(obj); i::Handle<i::Object> result = i::GlobalHandles::CopyGlobal(obj);
return result.location(); return result.location_as_address_ptr();
} }
void V8::RegisterExternallyReferencedObject(i::Object** object, void V8::RegisterExternallyReferencedObject(i::Address* location,
i::Isolate* isolate) { i::Isolate* isolate) {
isolate->heap()->RegisterExternallyReferencedObject(object); isolate->heap()->RegisterExternallyReferencedObject(location);
}
void V8::MakeWeak(i::Object** location, void* parameter,
int embedder_field_index1, int embedder_field_index2,
WeakCallbackInfo<void>::Callback weak_callback) {
WeakCallbackType type = WeakCallbackType::kParameter;
if (embedder_field_index1 == 0) {
if (embedder_field_index2 == 1) {
type = WeakCallbackType::kInternalFields;
} else {
DCHECK_EQ(embedder_field_index2, -1);
type = WeakCallbackType::kInternalFields;
}
} else {
DCHECK_EQ(embedder_field_index1, -1);
DCHECK_EQ(embedder_field_index2, -1);
}
i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type);
} }
void V8::MakeWeak(i::Object** location, void* parameter, void V8::MakeWeak(i::Address* location, void* parameter,
WeakCallbackInfo<void>::Callback weak_callback, WeakCallbackInfo<void>::Callback weak_callback,
WeakCallbackType type) { WeakCallbackType type) {
i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type); i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type);
} }
void V8::MakeWeak(i::Object*** location_addr) { void V8::MakeWeak(i::Address** location_addr) {
i::GlobalHandles::MakeWeak(location_addr); i::GlobalHandles::MakeWeak(location_addr);
} }
void* V8::ClearWeak(i::Object** location) { void* V8::ClearWeak(i::Address* location) {
return i::GlobalHandles::ClearWeakness(location); return i::GlobalHandles::ClearWeakness(location);
} }
void V8::AnnotateStrongRetainer(i::Object** location, const char* label) { void V8::AnnotateStrongRetainer(i::Address* location, const char* label) {
i::GlobalHandles::AnnotateStrongRetainer(location, label); i::GlobalHandles::AnnotateStrongRetainer(location, label);
} }
void V8::DisposeGlobal(i::Object** location) { void V8::DisposeGlobal(i::Address* location) {
i::GlobalHandles::Destroy(location); i::GlobalHandles::Destroy(location);
} }
...@@ -1078,14 +1058,16 @@ void HandleScope::Initialize(Isolate* isolate) { ...@@ -1078,14 +1058,16 @@ void HandleScope::Initialize(Isolate* isolate) {
"Entering the V8 API without proper locking in place"); "Entering the V8 API without proper locking in place");
i::HandleScopeData* current = internal_isolate->handle_scope_data(); i::HandleScopeData* current = internal_isolate->handle_scope_data();
isolate_ = internal_isolate; isolate_ = internal_isolate;
prev_next_ = current->next; prev_next_ = reinterpret_cast<i::Address*>(current->next);
prev_limit_ = current->limit; prev_limit_ = reinterpret_cast<i::Address*>(current->limit);
current->level++; current->level++;
} }
HandleScope::~HandleScope() { HandleScope::~HandleScope() {
i::HandleScope::CloseScope(isolate_, prev_next_, prev_limit_); i::HandleScope::CloseScope(isolate_,
reinterpret_cast<i::Object**>(prev_next_),
reinterpret_cast<i::Object**>(prev_limit_));
} }
void* HandleScope::operator new(size_t) { base::OS::Abort(); } void* HandleScope::operator new(size_t) { base::OS::Abort(); }
...@@ -1098,13 +1080,12 @@ int HandleScope::NumberOfHandles(Isolate* isolate) { ...@@ -1098,13 +1080,12 @@ int HandleScope::NumberOfHandles(Isolate* isolate) {
reinterpret_cast<i::Isolate*>(isolate)); reinterpret_cast<i::Isolate*>(isolate));
} }
i::Address* HandleScope::CreateHandle(i::Isolate* isolate, i::Address value) {
i::Object** HandleScope::CreateHandle(i::Isolate* isolate, i::Object* value) {
return i::HandleScope::CreateHandle(isolate, value); return i::HandleScope::CreateHandle(isolate, value);
} }
i::Object** HandleScope::CreateHandle( i::Address* HandleScope::CreateHandle(
i::NeverReadOnlySpaceObject* writable_object, i::Object* value) { i::NeverReadOnlySpaceObject* writable_object, i::Address value) {
DCHECK(reinterpret_cast<i::HeapObject*>(writable_object)->IsHeapObject()); DCHECK(reinterpret_cast<i::HeapObject*>(writable_object)->IsHeapObject());
return i::HandleScope::CreateHandle(writable_object->GetIsolate(), value); return i::HandleScope::CreateHandle(writable_object->GetIsolate(), value);
} }
...@@ -1112,18 +1093,20 @@ i::Object** HandleScope::CreateHandle( ...@@ -1112,18 +1093,20 @@ i::Object** HandleScope::CreateHandle(
EscapableHandleScope::EscapableHandleScope(Isolate* v8_isolate) { EscapableHandleScope::EscapableHandleScope(Isolate* v8_isolate) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
escape_slot_ = escape_slot_ = CreateHandle(
CreateHandle(isolate, i::ReadOnlyRoots(isolate).the_hole_value()); isolate,
reinterpret_cast<i::Address>(i::ReadOnlyRoots(isolate).the_hole_value()));
Initialize(v8_isolate); Initialize(v8_isolate);
} }
i::Address* EscapableHandleScope::Escape(i::Address* escape_value) {
i::Object** EscapableHandleScope::Escape(i::Object** escape_value) {
i::Heap* heap = reinterpret_cast<i::Isolate*>(GetIsolate())->heap(); i::Heap* heap = reinterpret_cast<i::Isolate*>(GetIsolate())->heap();
Utils::ApiCheck((*escape_slot_)->IsTheHole(heap->isolate()), Utils::ApiCheck(
"EscapableHandleScope::Escape", "Escape value set twice"); reinterpret_cast<i::Object*>(*escape_slot_)->IsTheHole(heap->isolate()),
"EscapableHandleScope::Escape", "Escape value set twice");
if (escape_value == nullptr) { if (escape_value == nullptr) {
*escape_slot_ = i::ReadOnlyRoots(heap).undefined_value(); *escape_slot_ =
reinterpret_cast<i::Address>(i::ReadOnlyRoots(heap).undefined_value());
return nullptr; return nullptr;
} }
*escape_slot_ = *escape_value; *escape_slot_ = *escape_value;
...@@ -1140,7 +1123,7 @@ void EscapableHandleScope::operator delete[](void*, size_t) { ...@@ -1140,7 +1123,7 @@ void EscapableHandleScope::operator delete[](void*, size_t) {
SealHandleScope::SealHandleScope(Isolate* isolate) SealHandleScope::SealHandleScope(Isolate* isolate)
: isolate_(reinterpret_cast<i::Isolate*>(isolate)) { : isolate_(reinterpret_cast<i::Isolate*>(isolate)) {
i::HandleScopeData* current = isolate_->handle_scope_data(); i::HandleScopeData* current = isolate_->handle_scope_data();
prev_limit_ = current->limit; prev_limit_ = reinterpret_cast<i::Address*>(current->limit);
current->limit = current->next; current->limit = current->next;
prev_sealed_level_ = current->sealed_level; prev_sealed_level_ = current->sealed_level;
current->sealed_level = current->level; current->sealed_level = current->level;
...@@ -1150,7 +1133,7 @@ SealHandleScope::SealHandleScope(Isolate* isolate) ...@@ -1150,7 +1133,7 @@ SealHandleScope::SealHandleScope(Isolate* isolate)
SealHandleScope::~SealHandleScope() { SealHandleScope::~SealHandleScope() {
i::HandleScopeData* current = isolate_->handle_scope_data(); i::HandleScopeData* current = isolate_->handle_scope_data();
DCHECK_EQ(current->next, current->limit); DCHECK_EQ(current->next, current->limit);
current->limit = prev_limit_; current->limit = reinterpret_cast<i::Object**>(prev_limit_);
DCHECK_EQ(current->level, current->sealed_level); DCHECK_EQ(current->level, current->sealed_level);
current->sealed_level = prev_sealed_level_; current->sealed_level = prev_sealed_level_;
} }
...@@ -5685,7 +5668,6 @@ void v8::String::VerifyExternalStringResourceBase( ...@@ -5685,7 +5668,6 @@ void v8::String::VerifyExternalStringResourceBase(
String::ExternalStringResource* String::GetExternalStringResourceSlow() const { String::ExternalStringResource* String::GetExternalStringResourceSlow() const {
i::DisallowHeapAllocation no_allocation; i::DisallowHeapAllocation no_allocation;
typedef internal::Internals I; typedef internal::Internals I;
ExternalStringResource* result = nullptr;
i::String* str = *Utils::OpenHandle(this); i::String* str = *Utils::OpenHandle(this);
if (str->IsThinString()) { if (str->IsThinString()) {
...@@ -5693,10 +5675,11 @@ String::ExternalStringResource* String::GetExternalStringResourceSlow() const { ...@@ -5693,10 +5675,11 @@ String::ExternalStringResource* String::GetExternalStringResourceSlow() const {
} }
if (i::StringShape(str).IsExternalTwoByte()) { if (i::StringShape(str).IsExternalTwoByte()) {
void* value = I::ReadField<void*>(str, I::kStringResourceOffset); void* value = I::ReadField<void*>(reinterpret_cast<i::Address>(str),
result = reinterpret_cast<String::ExternalStringResource*>(value); I::kStringResourceOffset);
return reinterpret_cast<String::ExternalStringResource*>(value);
} }
return result; return nullptr;
} }
String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow( String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow(
...@@ -5710,42 +5693,30 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow( ...@@ -5710,42 +5693,30 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow(
str = i::ThinString::cast(str)->actual(); str = i::ThinString::cast(str)->actual();
} }
int type = I::GetInstanceType(str) & I::kFullStringRepresentationMask; internal::Address string = reinterpret_cast<internal::Address>(str);
int type = I::GetInstanceType(string) & I::kFullStringRepresentationMask;
*encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask); *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
if (i::StringShape(str).IsExternalOneByte() || if (i::StringShape(str).IsExternalOneByte() ||
i::StringShape(str).IsExternalTwoByte()) { i::StringShape(str).IsExternalTwoByte()) {
void* value = I::ReadField<void*>(str, I::kStringResourceOffset); void* value = I::ReadField<void*>(string, I::kStringResourceOffset);
resource = static_cast<ExternalStringResourceBase*>(value); resource = static_cast<ExternalStringResourceBase*>(value);
} }
return resource; return resource;
} }
const String::ExternalOneByteStringResource*
String::GetExternalOneByteStringResourceSlow() const {
i::DisallowHeapAllocation no_allocation;
i::String* str = *Utils::OpenHandle(this);
if (str->IsThinString()) {
str = i::ThinString::cast(str)->actual();
}
if (i::StringShape(str).IsExternalOneByte()) {
const void* resource = i::ExternalOneByteString::cast(str)->resource();
return reinterpret_cast<const ExternalOneByteStringResource*>(resource);
}
return nullptr;
}
const v8::String::ExternalOneByteStringResource* const v8::String::ExternalOneByteStringResource*
v8::String::GetExternalOneByteStringResource() const { v8::String::GetExternalOneByteStringResource() const {
i::DisallowHeapAllocation no_allocation; i::DisallowHeapAllocation no_allocation;
i::String* str = *Utils::OpenHandle(this); i::String* str = *Utils::OpenHandle(this);
if (i::StringShape(str).IsExternalOneByte()) { if (i::StringShape(str).IsExternalOneByte()) {
const void* resource = i::ExternalOneByteString::cast(str)->resource(); return i::ExternalOneByteString::cast(str)->resource();
return reinterpret_cast<const ExternalOneByteStringResource*>(resource); } else if (str->IsThinString()) {
} else { str = i::ThinString::cast(str)->actual();
return GetExternalOneByteStringResourceSlow(); if (i::StringShape(str).IsExternalOneByte()) {
return i::ExternalOneByteString::cast(str)->resource();
}
} }
return nullptr;
} }
...@@ -6295,7 +6266,7 @@ void Context::SetErrorMessageForCodeGenerationFromStrings(Local<String> error) { ...@@ -6295,7 +6266,7 @@ void Context::SetErrorMessageForCodeGenerationFromStrings(Local<String> error) {
} }
namespace { namespace {
i::Object** GetSerializedDataFromFixedArray(i::Isolate* isolate, i::Address* GetSerializedDataFromFixedArray(i::Isolate* isolate,
i::FixedArray* list, size_t index) { i::FixedArray* list, size_t index) {
if (index < static_cast<size_t>(list->length())) { if (index < static_cast<size_t>(list->length())) {
int int_index = static_cast<int>(index); int int_index = static_cast<int>(index);
...@@ -6308,14 +6279,14 @@ i::Object** GetSerializedDataFromFixedArray(i::Isolate* isolate, ...@@ -6308,14 +6279,14 @@ i::Object** GetSerializedDataFromFixedArray(i::Isolate* isolate,
int last = list->length() - 1; int last = list->length() - 1;
while (last >= 0 && list->is_the_hole(isolate, last)) last--; while (last >= 0 && list->is_the_hole(isolate, last)) last--;
if (last != -1) list->Shrink(isolate, last + 1); if (last != -1) list->Shrink(isolate, last + 1);
return i::Handle<i::Object>(object, isolate).location(); return i::Handle<i::Object>(object, isolate).location_as_address_ptr();
} }
} }
return nullptr; return nullptr;
} }
} // anonymous namespace } // anonymous namespace
i::Object** Context::GetDataFromSnapshotOnce(size_t index) { i::Address* Context::GetDataFromSnapshotOnce(size_t index) {
auto context = Utils::OpenHandle(this); auto context = Utils::OpenHandle(this);
i::Isolate* i_isolate = context->GetIsolate(); i::Isolate* i_isolate = context->GetIsolate();
i::FixedArray* list = context->serialized_objects(); i::FixedArray* list = context->serialized_objects();
...@@ -8359,7 +8330,7 @@ Isolate::SafeForTerminationScope::~SafeForTerminationScope() { ...@@ -8359,7 +8330,7 @@ Isolate::SafeForTerminationScope::~SafeForTerminationScope() {
isolate_->set_next_v8_call_is_safe_for_termination(prev_value_); isolate_->set_next_v8_call_is_safe_for_termination(prev_value_);
} }
i::Object** Isolate::GetDataFromSnapshotOnce(size_t index) { i::Address* Isolate::GetDataFromSnapshotOnce(size_t index) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
i::FixedArray* list = i_isolate->heap()->serialized_objects(); i::FixedArray* list = i_isolate->heap()->serialized_objects();
return GetSerializedDataFromFixedArray(i_isolate, list, index); return GetSerializedDataFromFixedArray(i_isolate, list, index);
...@@ -9580,8 +9551,11 @@ debug::ConsoleCallArguments::ConsoleCallArguments( ...@@ -9580,8 +9551,11 @@ debug::ConsoleCallArguments::ConsoleCallArguments(
debug::ConsoleCallArguments::ConsoleCallArguments( debug::ConsoleCallArguments::ConsoleCallArguments(
internal::BuiltinArguments& args) internal::BuiltinArguments& args)
: v8::FunctionCallbackInfo<v8::Value>(nullptr, &args[0] - 1, : v8::FunctionCallbackInfo<v8::Value>(
args.length() - 1) {} // Drop the first argument (receiver, i.e. the "console" object).
nullptr,
reinterpret_cast<i::Address*>(&args[args.length() > 1 ? 1 : 0]),
args.length() - 1) {}
int debug::GetStackFrameId(v8::Local<v8::StackFrame> frame) { int debug::GetStackFrameId(v8::Local<v8::StackFrame> frame) {
return Utils::OpenHandle(*frame)->id(); return Utils::OpenHandle(*frame)->id();
......
...@@ -537,24 +537,31 @@ Handle<Object> GlobalHandles::Create(Object* value) { ...@@ -537,24 +537,31 @@ Handle<Object> GlobalHandles::Create(Object* value) {
return result->handle(); return result->handle();
} }
Handle<Object> GlobalHandles::Create(Address value) {
return Create(reinterpret_cast<Object*>(value));
}
Handle<Object> GlobalHandles::CopyGlobal(Object** location) { Handle<Object> GlobalHandles::CopyGlobal(Address* location) {
DCHECK_NOT_NULL(location); DCHECK_NOT_NULL(location);
GlobalHandles* global_handles = GlobalHandles* global_handles =
Node::FromLocation(location)->GetGlobalHandles(); Node::FromLocation(reinterpret_cast<Object**>(location))
->GetGlobalHandles();
#ifdef VERIFY_HEAP #ifdef VERIFY_HEAP
if (i::FLAG_verify_heap) { if (i::FLAG_verify_heap) {
(*location)->ObjectVerify(global_handles->isolate()); (*reinterpret_cast<Object**>(location))
->ObjectVerify(global_handles->isolate());
} }
#endif // VERIFY_HEAP #endif // VERIFY_HEAP
return global_handles->Create(*location); return global_handles->Create(*location);
} }
void GlobalHandles::Destroy(Object** location) { void GlobalHandles::Destroy(Object** location) {
if (location != nullptr) Node::FromLocation(location)->Release(); if (location != nullptr) Node::FromLocation(location)->Release();
} }
void GlobalHandles::Destroy(Address* location) {
Destroy(reinterpret_cast<Object**>(location));
}
typedef v8::WeakCallbackInfo<void>::Callback GenericCallback; typedef v8::WeakCallbackInfo<void>::Callback GenericCallback;
...@@ -565,12 +572,24 @@ void GlobalHandles::MakeWeak(Object** location, void* parameter, ...@@ -565,12 +572,24 @@ void GlobalHandles::MakeWeak(Object** location, void* parameter,
Node::FromLocation(location)->MakeWeak(parameter, phantom_callback, type); Node::FromLocation(location)->MakeWeak(parameter, phantom_callback, type);
} }
void GlobalHandles::MakeWeak(Address* location, void* parameter,
GenericCallback phantom_callback,
v8::WeakCallbackType type) {
Node::FromLocation(reinterpret_cast<Object**>(location))
->MakeWeak(parameter, phantom_callback, type);
}
void GlobalHandles::MakeWeak(Object*** location_addr) { void GlobalHandles::MakeWeak(Object*** location_addr) {
Node::FromLocation(*location_addr)->MakeWeak(location_addr); Node::FromLocation(*location_addr)->MakeWeak(location_addr);
} }
void* GlobalHandles::ClearWeakness(Object** location) { void GlobalHandles::MakeWeak(Address** location_addr) {
return Node::FromLocation(location)->ClearWeakness(); MakeWeak(reinterpret_cast<Object***>(location_addr));
}
void* GlobalHandles::ClearWeakness(Address* location) {
return Node::FromLocation(reinterpret_cast<Object**>(location))
->ClearWeakness();
} }
void GlobalHandles::AnnotateStrongRetainer(Object** location, void GlobalHandles::AnnotateStrongRetainer(Object** location,
...@@ -578,6 +597,12 @@ void GlobalHandles::AnnotateStrongRetainer(Object** location, ...@@ -578,6 +597,12 @@ void GlobalHandles::AnnotateStrongRetainer(Object** location,
Node::FromLocation(location)->AnnotateStrongRetainer(label); Node::FromLocation(location)->AnnotateStrongRetainer(label);
} }
void GlobalHandles::AnnotateStrongRetainer(Address* location,
const char* label) {
Node::FromLocation(reinterpret_cast<Object**>(location))
->AnnotateStrongRetainer(label);
}
bool GlobalHandles::IsNearDeath(Object** location) { bool GlobalHandles::IsNearDeath(Object** location) {
return Node::FromLocation(location)->IsNearDeath(); return Node::FromLocation(location)->IsNearDeath();
} }
......
...@@ -47,6 +47,9 @@ class GlobalHandles { ...@@ -47,6 +47,9 @@ class GlobalHandles {
// Creates a new global handle that is alive until Destroy is called. // Creates a new global handle that is alive until Destroy is called.
Handle<Object> Create(Object* value); Handle<Object> Create(Object* value);
// TODO(jkummerow): This and the other Object*/Address overloads below are
// temporary. Eventually the respective Object* version should go away.
Handle<Object> Create(Address value);
template <typename T> template <typename T>
Handle<T> Create(T* value) { Handle<T> Create(T* value) {
...@@ -57,10 +60,11 @@ class GlobalHandles { ...@@ -57,10 +60,11 @@ class GlobalHandles {
} }
// Copy a global handle // Copy a global handle
static Handle<Object> CopyGlobal(Object** location); static Handle<Object> CopyGlobal(Address* location);
// Destroy a global handle. // Destroy a global handle.
static void Destroy(Object** location); static void Destroy(Object** location);
static void Destroy(Address* location);
// Make the global handle weak and set the callback parameter for the // Make the global handle weak and set the callback parameter for the
// handle. When the garbage collector recognizes that only weak global // handle. When the garbage collector recognizes that only weak global
...@@ -74,10 +78,15 @@ class GlobalHandles { ...@@ -74,10 +78,15 @@ class GlobalHandles {
static void MakeWeak(Object** location, void* parameter, static void MakeWeak(Object** location, void* parameter,
WeakCallbackInfo<void>::Callback weak_callback, WeakCallbackInfo<void>::Callback weak_callback,
v8::WeakCallbackType type); v8::WeakCallbackType type);
static void MakeWeak(Address* location, void* parameter,
WeakCallbackInfo<void>::Callback weak_callback,
v8::WeakCallbackType type);
static void MakeWeak(Object*** location_addr); static void MakeWeak(Object*** location_addr);
static void MakeWeak(Address** location_addr);
static void AnnotateStrongRetainer(Object** location, const char* label); static void AnnotateStrongRetainer(Object** location, const char* label);
static void AnnotateStrongRetainer(Address* location, const char* label);
void RecordStats(HeapStats* stats); void RecordStats(HeapStats* stats);
...@@ -97,12 +106,14 @@ class GlobalHandles { ...@@ -97,12 +106,14 @@ class GlobalHandles {
size_t NumberOfNewSpaceNodes() { return new_space_nodes_.size(); } size_t NumberOfNewSpaceNodes() { return new_space_nodes_.size(); }
// Clear the weakness of a global handle. // Clear the weakness of a global handle.
static void* ClearWeakness(Object** location); static void* ClearWeakness(Address* location);
// Tells whether global handle is near death. // Tells whether global handle is near death.
// TODO(jkummerow): This seems to be unused.
static bool IsNearDeath(Object** location); static bool IsNearDeath(Object** location);
// Tells whether global handle is weak. // Tells whether global handle is weak.
// TODO(jkummerow): This seems to be unused.
static bool IsWeak(Object** location); static bool IsWeak(Object** location);
// Process pending weak handles. // Process pending weak handles.
......
...@@ -96,8 +96,6 @@ class AllStatic { ...@@ -96,8 +96,6 @@ class AllStatic {
}; };
typedef uint8_t byte; typedef uint8_t byte;
typedef uintptr_t Address;
static const Address kNullAddress = 0;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Constants // Constants
......
...@@ -122,6 +122,22 @@ Object** HandleScope::CreateHandle(Isolate* isolate, Object* value) { ...@@ -122,6 +122,22 @@ Object** HandleScope::CreateHandle(Isolate* isolate, Object* value) {
return result; return result;
} }
Address* HandleScope::CreateHandle(Isolate* isolate, Address value_address) {
DCHECK(AllowHandleAllocation::IsAllowed());
HandleScopeData* data = isolate->handle_scope_data();
Address* result = reinterpret_cast<Address*>(data->next);
if (result == reinterpret_cast<Address*>(data->limit)) {
result = reinterpret_cast<Address*>(Extend(isolate));
}
// Update the current next field, set the value in the created handle,
// and return the result.
DCHECK_LT(reinterpret_cast<Address>(result),
reinterpret_cast<Address>(data->limit));
data->next = reinterpret_cast<Object**>(reinterpret_cast<Address>(result) +
sizeof(Address));
*result = value_address;
return result;
}
Object** HandleScope::GetHandle(Isolate* isolate, Object* value) { Object** HandleScope::GetHandle(Isolate* isolate, Object* value) {
DCHECK(AllowHandleAllocation::IsAllowed()); DCHECK(AllowHandleAllocation::IsAllowed());
......
...@@ -121,6 +121,11 @@ class Handle final : public HandleBase { ...@@ -121,6 +121,11 @@ class Handle final : public HandleBase {
V8_INLINE T** location() const { V8_INLINE T** location() const {
return reinterpret_cast<T**>(HandleBase::location()); return reinterpret_cast<T**>(HandleBase::location());
} }
// TODO(jkummerow): This is temporary; eventually location() should
// return an Address*.
V8_INLINE Address* location_as_address_ptr() const {
return reinterpret_cast<Address*>(HandleBase::location());
}
template <typename S> template <typename S>
inline static const Handle<T> cast(Handle<S> that); inline static const Handle<T> cast(Handle<S> that);
...@@ -185,6 +190,8 @@ class HandleScope { ...@@ -185,6 +190,8 @@ class HandleScope {
// Creates a new handle with the given value. // Creates a new handle with the given value.
V8_INLINE static Object** CreateHandle(Isolate* isolate, Object* value); V8_INLINE static Object** CreateHandle(Isolate* isolate, Object* value);
V8_INLINE static Address* CreateHandle(Isolate* isolate,
Address value_address);
// Deallocates any extensions used by the current scope. // Deallocates any extensions used by the current scope.
V8_EXPORT_PRIVATE static void DeleteExtensions(Isolate* isolate); V8_EXPORT_PRIVATE static void DeleteExtensions(Isolate* isolate);
......
...@@ -3652,7 +3652,7 @@ Address Heap::builtin_address(int index) { ...@@ -3652,7 +3652,7 @@ Address Heap::builtin_address(int index) {
void Heap::set_builtin(int index, HeapObject* builtin) { void Heap::set_builtin(int index, HeapObject* builtin) {
DCHECK(Builtins::IsBuiltinId(index)); DCHECK(Builtins::IsBuiltinId(index));
DCHECK(Internals::HasHeapObjectTag(builtin)); DCHECK(Internals::HasHeapObjectTag(reinterpret_cast<Address>(builtin)));
// The given builtin may be completely uninitialized thus we cannot check its // The given builtin may be completely uninitialized thus we cannot check its
// type here. // type here.
builtins_table()[index] = builtin; builtins_table()[index] = builtin;
...@@ -4490,11 +4490,12 @@ void Heap::TracePossibleWrapper(JSObject* js_object) { ...@@ -4490,11 +4490,12 @@ void Heap::TracePossibleWrapper(JSObject* js_object) {
} }
} }
void Heap::RegisterExternallyReferencedObject(Object** object) { void Heap::RegisterExternallyReferencedObject(Address* location) {
// The embedder is not aware of whether numbers are materialized as heap // The embedder is not aware of whether numbers are materialized as heap
// objects are just passed around as Smis. // objects are just passed around as Smis.
if (!(*object)->IsHeapObject()) return; Object* object = *reinterpret_cast<Object**>(location);
HeapObject* heap_object = HeapObject::cast(*object); if (!object->IsHeapObject()) return;
HeapObject* heap_object = HeapObject::cast(object);
DCHECK(Contains(heap_object)); DCHECK(Contains(heap_object));
if (FLAG_incremental_marking_wrappers && incremental_marking()->IsMarking()) { if (FLAG_incremental_marking_wrappers && incremental_marking()->IsMarking()) {
incremental_marking()->WhiteToGreyAndPush(heap_object); incremental_marking()->WhiteToGreyAndPush(heap_object);
......
...@@ -873,7 +873,7 @@ class Heap { ...@@ -873,7 +873,7 @@ class Heap {
EmbedderHeapTracer* GetEmbedderHeapTracer() const; EmbedderHeapTracer* GetEmbedderHeapTracer() const;
void TracePossibleWrapper(JSObject* js_object); void TracePossibleWrapper(JSObject* js_object);
void RegisterExternallyReferencedObject(Object** object); void RegisterExternallyReferencedObject(Address* location);
void SetEmbedderStackStateForNextFinalizaton( void SetEmbedderStackStateForNextFinalizaton(
EmbedderHeapTracer::EmbedderStackState stack_state); EmbedderHeapTracer::EmbedderStackState stack_state);
......
...@@ -1464,7 +1464,8 @@ class Object { ...@@ -1464,7 +1464,8 @@ class Object {
// In objects.h to be usable without objects-inl.h inclusion. // In objects.h to be usable without objects-inl.h inclusion.
bool Object::IsSmi() const { return HAS_SMI_TAG(this); } bool Object::IsSmi() const { return HAS_SMI_TAG(this); }
bool Object::IsHeapObject() const { bool Object::IsHeapObject() const {
DCHECK_EQ(!IsSmi(), Internals::HasHeapObjectTag(this)); DCHECK_EQ(!IsSmi(),
Internals::HasHeapObjectTag(reinterpret_cast<Address>(this)));
return !IsSmi(); return !IsSmi();
} }
...@@ -1485,7 +1486,9 @@ V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, const Brief& v); ...@@ -1485,7 +1486,9 @@ V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, const Brief& v);
class Smi: public Object { class Smi: public Object {
public: public:
// Returns the integer value. // Returns the integer value.
inline int value() const { return Internals::SmiValue(this); } inline int value() const {
return Internals::SmiValue(reinterpret_cast<Address>(this));
}
inline Smi* ToUint32Smi() { inline Smi* ToUint32Smi() {
if (value() <= 0) return Smi::kZero; if (value() <= 0) return Smi::kZero;
return Smi::FromInt(static_cast<uint32_t>(value())); return Smi::FromInt(static_cast<uint32_t>(value()));
......
...@@ -130,7 +130,7 @@ class HeapObjectReference : public MaybeObject { ...@@ -130,7 +130,7 @@ class HeapObjectReference : public MaybeObject {
static void Update(HeapObjectReference** slot, HeapObject* value) { static void Update(HeapObjectReference** slot, HeapObject* value) {
DCHECK(!HAS_SMI_TAG(*slot)); DCHECK(!HAS_SMI_TAG(*slot));
DCHECK(Internals::HasHeapObjectTag(value)); DCHECK(Internals::HasHeapObjectTag(reinterpret_cast<Address>(value)));
#ifdef DEBUG #ifdef DEBUG
bool weak_before = HasWeakHeapObjectTag(*slot); bool weak_before = HasWeakHeapObjectTag(*slot);
......
...@@ -265,7 +265,8 @@ bool TickSample::GetStackSample(Isolate* v8_isolate, RegisterState* regs, ...@@ -265,7 +265,8 @@ bool TickSample::GetStackSample(Isolate* v8_isolate, RegisterState* regs,
if (HAS_HEAP_OBJECT_TAG(bytecode_array) && HAS_SMI_TAG(bytecode_offset)) { if (HAS_HEAP_OBJECT_TAG(bytecode_array) && HAS_SMI_TAG(bytecode_offset)) {
frames[i++] = reinterpret_cast<void*>( frames[i++] = reinterpret_cast<void*>(
reinterpret_cast<i::Address>(bytecode_array) + reinterpret_cast<i::Address>(bytecode_array) +
i::Internals::SmiValue(bytecode_offset)); i::Internals::SmiValue(
reinterpret_cast<i::Address>(bytecode_offset)));
continue; continue;
} }
} }
......
...@@ -31,7 +31,7 @@ Address BuiltinDeserializerAllocator::Allocate(AllocationSpace space, ...@@ -31,7 +31,7 @@ Address BuiltinDeserializerAllocator::Allocate(AllocationSpace space,
DCHECK(Builtins::IsBuiltinId(code_object_id)); DCHECK(Builtins::IsBuiltinId(code_object_id));
Object* obj = isolate()->builtins()->builtin(code_object_id); Object* obj = isolate()->builtins()->builtin(code_object_id);
DCHECK(Internals::HasHeapObjectTag(obj)); DCHECK(Internals::HasHeapObjectTag(reinterpret_cast<Address>(obj)));
return HeapObject::cast(obj)->address(); return HeapObject::cast(obj)->address();
} }
......
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