[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/1036612
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56705}
This commit is contained in:
Jakob Kummerow 2018-10-11 16:23:33 -07:00 committed by Commit Bot
parent db6db6ed8f
commit a2f1824839
16 changed files with 291 additions and 260 deletions

View File

@ -20,7 +20,8 @@ class Isolate;
namespace internal {
class Object;
typedef uintptr_t Address;
static const Address kNullAddress = 0;
/**
* Configuration of tagging scheme.
@ -45,11 +46,11 @@ template <size_t tagged_ptr_size>
struct SmiTagging;
template <int kSmiShiftSize>
V8_INLINE internal::Object* IntToSmi(int value) {
V8_INLINE internal::Address IntToSmi(int value) {
int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
intptr_t tagged_value =
(static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag;
return reinterpret_cast<internal::Object*>(tagged_value);
uintptr_t tagged_value =
(static_cast<uintptr_t>(value) << smi_shift_bits) | kSmiTag;
return static_cast<internal::Address>(tagged_value);
}
// Smi constants for systems where tagged pointer is a 32-bit value.
@ -58,19 +59,19 @@ struct SmiTagging<4> {
enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
static int SmiShiftSize() { return kSmiShiftSize; }
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;
// Throw away top 32 bits and shift down (requires >> to be sign extending).
return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
// Shift down (requires >> to be sign extending).
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);
}
V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
// To be representable as an tagged small integer, the two
// most-significant bits of 'value' must be either 00 or 11 due to
// 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:
// bool result = ((value + 0x40000000) & 0x80000000) == 0;
@ -88,12 +89,12 @@ struct SmiTagging<8> {
enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
static int SmiShiftSize() { return kSmiShiftSize; }
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;
// 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);
}
V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
@ -191,16 +192,15 @@ class Internals {
#endif
}
V8_INLINE static bool HasHeapObjectTag(const internal::Object* value) {
return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
kHeapObjectTag);
V8_INLINE static bool HasHeapObjectTag(const internal::Address value) {
return (value & kHeapObjectTagMask) == static_cast<Address>(kHeapObjectTag);
}
V8_INLINE static int SmiValue(const internal::Object* value) {
V8_INLINE static int SmiValue(const internal::Address 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);
}
@ -208,15 +208,14 @@ class Internals {
return PlatformSmiTagging::IsValidSmi(value);
}
V8_INLINE static int GetInstanceType(const internal::Object* obj) {
typedef internal::Object O;
O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
V8_INLINE static int GetInstanceType(const internal::Address obj) {
typedef internal::Address A;
A map = ReadField<A>(obj, kHeapObjectMapOffset);
return ReadField<uint16_t>(map, kMapInstanceTypeOffset);
}
V8_INLINE static int GetOddballKind(const internal::Object* obj) {
typedef internal::Object O;
return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
V8_INLINE static int GetOddballKind(const internal::Address obj) {
return SmiValue(ReadField<internal::Address>(obj, kOddballKindOffset));
}
V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
@ -224,63 +223,66 @@ class Internals {
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;
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) {
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
uint8_t mask = static_cast<uint8_t>(1U << 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;
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;
*addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
}
V8_INLINE static void SetEmbedderData(v8::Isolate* isolate, uint32_t slot,
void* data) {
uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
kIsolateEmbedderDataOffset + slot * kApiPointerSize;
internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
kIsolateEmbedderDataOffset +
slot * kApiPointerSize;
*reinterpret_cast<void**>(addr) = data;
}
V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
uint32_t slot) {
const uint8_t* addr = reinterpret_cast<const uint8_t*>(isolate) +
kIsolateEmbedderDataOffset + slot * kApiPointerSize;
internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
kIsolateEmbedderDataOffset +
slot * kApiPointerSize;
return *reinterpret_cast<void* const*>(addr);
}
V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate, int index) {
uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
V8_INLINE static internal::Address* GetRoot(v8::Isolate* isolate, int index) {
internal::Address addr =
reinterpret_cast<internal::Address>(isolate) + kIsolateRootsOffset;
return reinterpret_cast<internal::Address*>(addr + index * kApiPointerSize);
}
template <typename T>
V8_INLINE static T ReadField(const internal::Object* ptr, int offset) {
const uint8_t* addr =
reinterpret_cast<const uint8_t*>(ptr) + offset - kHeapObjectTag;
V8_INLINE static T ReadField(const internal::Address heap_object_ptr,
int offset) {
internal::Address addr = heap_object_ptr + offset - kHeapObjectTag;
return *reinterpret_cast<const T*>(addr);
}
template <typename T>
V8_INLINE static T ReadEmbedderData(const v8::Context* context, int index) {
typedef internal::Object O;
typedef internal::Address A;
typedef internal::Internals I;
O* ctx = *reinterpret_cast<O* const*>(context);
A ctx = *reinterpret_cast<const A*>(context);
int embedder_data_offset =
I::kContextHeaderSize +
(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 =
I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
return I::ReadField<T>(embedder_data, value_offset);

View File

@ -29,9 +29,8 @@ enum PersistentContainerCallbackType {
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.
*
* Users will have to implement their own weak callbacks & dispose traits.
@ -203,7 +202,7 @@ class PersistentValueMapBase {
void RegisterExternallyReferencedObject(K& key) {
assert(Contains(key));
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()));
}
@ -340,7 +339,7 @@ class PersistentValueMapBase {
bool hasValue = value != kPersistentContainerNotFound;
if (hasValue) {
returnValue->SetInternal(
*reinterpret_cast<internal::Object**>(FromVal(value)));
*reinterpret_cast<internal::Address*>(FromVal(value)));
}
return hasValue;
}

View File

@ -118,7 +118,6 @@ class HeapObject;
class Isolate;
class LocalEmbedderHeapTracer;
class NeverReadOnlySpaceObject;
class Object;
struct ScriptStreamingData;
template<typename T> class CustomArguments;
class PropertyCallbackArguments;
@ -212,8 +211,8 @@ class Local {
*/
template <class S>
V8_INLINE bool operator==(const Local<S>& that) const {
internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
if (a == nullptr) return b == nullptr;
if (b == nullptr) return false;
return *a == *b;
@ -221,8 +220,8 @@ class Local {
template <class S> V8_INLINE bool operator==(
const PersistentBase<S>& that) const {
internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
if (a == nullptr) return b == nullptr;
if (b == nullptr) return false;
return *a == *b;
@ -477,8 +476,8 @@ template <class T> class PersistentBase {
template <class S>
V8_INLINE bool operator==(const PersistentBase<S>& that) const {
internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
if (a == nullptr) return b == nullptr;
if (b == nullptr) return false;
return *a == *b;
@ -486,8 +485,8 @@ template <class T> class PersistentBase {
template <class S>
V8_INLINE bool operator==(const Local<S>& that) const {
internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
internal::Address* a = reinterpret_cast<internal::Address*>(this->val_);
internal::Address* b = reinterpret_cast<internal::Address*>(that.val_);
if (a == nullptr) return b == nullptr;
if (b == nullptr) return false;
return *a == *b;
@ -859,8 +858,8 @@ class V8_EXPORT HandleScope {
void Initialize(Isolate* isolate);
static internal::Object** CreateHandle(internal::Isolate* isolate,
internal::Object* value);
static internal::Address* CreateHandle(internal::Isolate* isolate,
internal::Address value);
private:
// Declaring operator new and delete as deleted is not spec compliant.
@ -871,12 +870,12 @@ class V8_EXPORT HandleScope {
void operator delete[](void*, size_t);
// Uses heap_object to obtain the current Isolate.
static internal::Object** CreateHandle(
internal::NeverReadOnlySpaceObject* heap_object, internal::Object* value);
static internal::Address* CreateHandle(
internal::NeverReadOnlySpaceObject* heap_object, internal::Address value);
internal::Isolate* isolate_;
internal::Object** prev_next_;
internal::Object** prev_limit_;
internal::Address* prev_next_;
internal::Address* prev_limit_;
// Local::New uses CreateHandle with an Isolate* parameter.
template<class F> friend class Local;
@ -903,8 +902,8 @@ class V8_EXPORT EscapableHandleScope : public HandleScope {
*/
template <class T>
V8_INLINE Local<T> Escape(Local<T> value) {
internal::Object** slot =
Escape(reinterpret_cast<internal::Object**>(*value));
internal::Address* slot =
Escape(reinterpret_cast<internal::Address*>(*value));
return Local<T>(reinterpret_cast<T*>(slot));
}
@ -924,8 +923,8 @@ class V8_EXPORT EscapableHandleScope : public HandleScope {
void operator delete(void*, size_t);
void operator delete[](void*, size_t);
internal::Object** Escape(internal::Object** escape_value);
internal::Object** escape_slot_;
internal::Address* Escape(internal::Address* escape_value);
internal::Address* escape_slot_;
};
/**
@ -950,7 +949,7 @@ class V8_EXPORT SealHandleScope {
void operator delete[](void*, size_t);
internal::Isolate* const isolate_;
internal::Object** prev_limit_;
internal::Address* prev_limit_;
int prev_sealed_level_;
};
@ -2925,8 +2924,6 @@ class V8_EXPORT String : public Name {
ExternalStringResource* GetExternalStringResourceSlow() const;
ExternalStringResourceBase* GetExternalStringResourceBaseSlow(
String::Encoding* encoding_out) const;
const ExternalOneByteStringResource* GetExternalOneByteStringResourceSlow()
const;
static void CheckCast(v8::Value* obj);
};
@ -3797,10 +3794,10 @@ class ReturnValue {
template<class F> friend class PropertyCallbackInfo;
template <class F, class G, class H>
friend class PersistentValueMapBase;
V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
V8_INLINE internal::Object* GetDefaultValue();
V8_INLINE explicit ReturnValue(internal::Object** slot);
internal::Object** value_;
V8_INLINE void SetInternal(internal::Address value) { *value_ = value; }
V8_INLINE internal::Address GetDefaultValue();
V8_INLINE explicit ReturnValue(internal::Address* slot);
internal::Address* value_;
};
@ -3854,10 +3851,10 @@ class FunctionCallbackInfo {
static const int kDataIndex = 4;
static const int kNewTargetIndex = 5;
V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args,
internal::Object** values, int length);
internal::Object** implicit_args_;
internal::Object** values_;
V8_INLINE FunctionCallbackInfo(internal::Address* implicit_args,
internal::Address* values, int length);
internal::Address* implicit_args_;
internal::Address* values_;
int length_;
};
@ -3969,8 +3966,8 @@ class PropertyCallbackInfo {
static const int kDataIndex = 5;
static const int kThisIndex = 6;
V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {}
internal::Object** args_;
V8_INLINE PropertyCallbackInfo(internal::Address* args) : args_(args) {}
internal::Address* args_;
};
@ -8275,7 +8272,7 @@ class V8_EXPORT Isolate {
template <class K, class V, class Traits>
friend class PersistentValueMapBase;
internal::Object** GetDataFromSnapshotOnce(size_t index);
internal::Address* GetDataFromSnapshotOnce(size_t index);
void ReportExternalAllocationLimitReached();
void CheckMemoryPressure();
};
@ -8478,26 +8475,20 @@ class V8_EXPORT V8 {
private:
V8();
static internal::Object** GlobalizeReference(internal::Isolate* isolate,
internal::Object** handle);
static internal::Object** CopyPersistent(internal::Object** handle);
static void DisposeGlobal(internal::Object** global_handle);
static void MakeWeak(internal::Object** location, void* data,
static internal::Address* GlobalizeReference(internal::Isolate* isolate,
internal::Address* handle);
static internal::Address* CopyPersistent(internal::Address* handle);
static void DisposeGlobal(internal::Address* global_handle);
static void MakeWeak(internal::Address* location, void* data,
WeakCallbackInfo<void>::Callback weak_callback,
WeakCallbackType type);
static void MakeWeak(internal::Object** location, void* data,
// Must be 0 or -1.
int internal_field_index1,
// 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,
static void MakeWeak(internal::Address** location_addr);
static void* ClearWeak(internal::Address* location);
static void AnnotateStrongRetainer(internal::Address* location,
const char* label);
static Value* Eternalize(Isolate* isolate, Value* handle);
static void RegisterExternallyReferencedObject(internal::Object** object,
static void RegisterExternallyReferencedObject(internal::Address* location,
internal::Isolate* isolate);
template <class K, class V, class T>
@ -8618,8 +8609,8 @@ class V8_EXPORT SnapshotCreator {
void operator=(const SnapshotCreator&) = delete;
private:
size_t AddData(Local<Context> context, internal::Object* object);
size_t AddData(internal::Object* object);
size_t AddData(Local<Context> context, internal::Address object);
size_t AddData(internal::Address object);
void* data_;
};
@ -9162,7 +9153,7 @@ class V8_EXPORT Context {
friend class Object;
friend class Function;
internal::Object** GetDataFromSnapshotOnce(size_t index);
internal::Address* GetDataFromSnapshotOnce(size_t index);
Local<Value> SlowGetEmbedderData(int index);
void* SlowGetAlignedPointerFromEmbedderData(int index);
};
@ -9309,7 +9300,7 @@ template <class T>
Local<T> Local<T>::New(Isolate* isolate, T* that) {
if (that == nullptr) return Local<T>();
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(
reinterpret_cast<internal::Isolate*>(isolate), *p)));
}
@ -9352,7 +9343,7 @@ void* WeakCallbackInfo<T>::GetInternalField(int index) const {
template <class T>
T* PersistentBase<T>::New(Isolate* isolate, T* that) {
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*>(
V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
p));
@ -9365,7 +9356,7 @@ void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
TYPE_CHECK(T, S);
this->Reset();
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));
M::Copy(that, this);
}
@ -9374,7 +9365,7 @@ template <class T>
bool PersistentBase<T>::IsIndependent() const {
typedef internal::Internals I;
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);
}
@ -9383,7 +9374,7 @@ bool PersistentBase<T>::IsNearDeath() const {
typedef internal::Internals I;
if (this->IsEmpty()) return false;
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 ||
node_state == I::kNodeStateIsPendingValue;
}
@ -9393,7 +9384,7 @@ template <class T>
bool PersistentBase<T>::IsWeak() const {
typedef internal::Internals I;
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;
}
@ -9401,7 +9392,7 @@ bool PersistentBase<T>::IsWeak() const {
template <class T>
void PersistentBase<T>::Reset() {
if (this->IsEmpty()) return;
V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_));
V8::DisposeGlobal(reinterpret_cast<internal::Address*>(this->val_));
val_ = nullptr;
}
@ -9433,25 +9424,25 @@ V8_INLINE void PersistentBase<T>::SetWeak(
P* parameter, typename WeakCallbackInfo<P>::Callback callback,
WeakCallbackType type) {
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);
}
template <class T>
void PersistentBase<T>::SetWeak() {
V8::MakeWeak(reinterpret_cast<internal::Object***>(&this->val_));
V8::MakeWeak(reinterpret_cast<internal::Address**>(&this->val_));
}
template <class T>
template <typename P>
P* PersistentBase<T>::ClearWeak() {
return reinterpret_cast<P*>(
V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)));
V8::ClearWeak(reinterpret_cast<internal::Address*>(this->val_)));
}
template <class T>
void PersistentBase<T>::AnnotateStrongRetainer(const char* label) {
V8::AnnotateStrongRetainer(reinterpret_cast<internal::Object**>(this->val_),
V8::AnnotateStrongRetainer(reinterpret_cast<internal::Address*>(this->val_),
label);
}
@ -9459,7 +9450,7 @@ template <class T>
void PersistentBase<T>::RegisterExternalReference(Isolate* isolate) const {
if (IsEmpty()) return;
V8::RegisterExternallyReferencedObject(
reinterpret_cast<internal::Object**>(this->val_),
reinterpret_cast<internal::Address*>(this->val_),
reinterpret_cast<internal::Isolate*>(isolate));
}
@ -9467,7 +9458,7 @@ template <class T>
void PersistentBase<T>::MarkIndependent() {
typedef internal::Internals I;
if (this->IsEmpty()) return;
I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), true,
I::UpdateNodeFlag(reinterpret_cast<internal::Address*>(this->val_), true,
I::kNodeIsIndependentShift);
}
@ -9475,7 +9466,7 @@ template <class T>
void PersistentBase<T>::MarkActive() {
typedef internal::Internals I;
if (this->IsEmpty()) return;
I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), true,
I::UpdateNodeFlag(reinterpret_cast<internal::Address*>(this->val_), true,
I::kNodeIsActiveShift);
}
@ -9484,7 +9475,7 @@ template <class T>
void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) {
typedef internal::Internals I;
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;
*reinterpret_cast<uint16_t*>(addr) = class_id;
}
@ -9494,14 +9485,13 @@ template <class T>
uint16_t PersistentBase<T>::WrapperClassId() const {
typedef internal::Internals I;
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;
return *reinterpret_cast<uint16_t*>(addr);
}
template<typename T>
ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {}
template <typename T>
ReturnValue<T>::ReturnValue(internal::Address* slot) : value_(slot) {}
template<typename T>
template<typename S>
@ -9510,7 +9500,7 @@ void ReturnValue<T>::Set(const Persistent<S>& handle) {
if (V8_UNLIKELY(handle.IsEmpty())) {
*value_ = GetDefaultValue();
} 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) {
if (V8_UNLIKELY(handle.IsEmpty())) {
*value_ = GetDefaultValue();
} 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) {
if (V8_UNLIKELY(handle.IsEmpty())) {
*value_ = GetDefaultValue();
} else {
*value_ = *reinterpret_cast<internal::Object**>(*handle);
*value_ = *reinterpret_cast<internal::Address*>(*handle);
}
}
@ -9620,15 +9610,15 @@ void ReturnValue<T>::Set(S* whatever) {
TYPE_CHECK(S*, Primitive);
}
template<typename T>
internal::Object* ReturnValue<T>::GetDefaultValue() {
template <typename T>
internal::Address ReturnValue<T>::GetDefaultValue() {
// Default value is always the pointer below value_ on the stack.
return value_[-1];
}
template <typename T>
FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Object** implicit_args,
internal::Object** values,
FunctionCallbackInfo<T>::FunctionCallbackInfo(internal::Address* implicit_args,
internal::Address* values,
int length)
: implicit_args_(implicit_args), values_(values), length_(length) {}
@ -9798,9 +9788,9 @@ AccessorSignature* AccessorSignature::Cast(Data* data) {
Local<Value> Object::GetInternalField(int index) {
#ifndef V8_ENABLE_CHECKS
typedef internal::Object O;
typedef internal::Address A;
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
// know where to find the internal fields and can return the value directly.
auto instance_type = I::GetInstanceType(obj);
@ -9808,8 +9798,8 @@ Local<Value> Object::GetInternalField(int index) {
instance_type == I::kJSApiObjectType ||
instance_type == I::kJSSpecialApiObjectType) {
int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
O* value = I::ReadField<O*>(obj, offset);
O** result = HandleScope::CreateHandle(
A value = I::ReadField<A>(obj, offset);
A* result = HandleScope::CreateHandle(
reinterpret_cast<internal::NeverReadOnlySpaceObject*>(obj), value);
return Local<Value>(reinterpret_cast<Value*>(result));
}
@ -9820,9 +9810,9 @@ Local<Value> Object::GetInternalField(int index) {
void* Object::GetAlignedPointerFromInternalField(int index) {
#ifndef V8_ENABLE_CHECKS
typedef internal::Object O;
typedef internal::Address A;
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
// know where to find the internal fields and can return the value directly.
auto instance_type = I::GetInstanceType(obj);
@ -9845,7 +9835,7 @@ String* String::Cast(v8::Value* value) {
Local<String> String::Empty(Isolate* isolate) {
typedef internal::Object* S;
typedef internal::Address S;
typedef internal::Internals I;
I::CheckInitialized(isolate);
S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
@ -9854,9 +9844,9 @@ Local<String> String::Empty(Isolate* isolate) {
String::ExternalStringResource* String::GetExternalStringResource() const {
typedef internal::Object O;
typedef internal::Address A;
typedef internal::Internals I;
O* obj = *reinterpret_cast<O* const*>(this);
A obj = *reinterpret_cast<const A*>(this);
ExternalStringResource* result;
if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
@ -9874,9 +9864,9 @@ String::ExternalStringResource* String::GetExternalStringResource() const {
String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
String::Encoding* encoding_out) const {
typedef internal::Object O;
typedef internal::Address A;
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;
*encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
ExternalStringResourceBase* resource;
@ -9903,9 +9893,9 @@ bool Value::IsUndefined() const {
}
bool Value::QuickIsUndefined() const {
typedef internal::Object O;
typedef internal::Address A;
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::GetInstanceType(obj) != I::kOddballType) return false;
return (I::GetOddballKind(obj) == I::kUndefinedOddballKind);
@ -9921,9 +9911,9 @@ bool Value::IsNull() const {
}
bool Value::QuickIsNull() const {
typedef internal::Object O;
typedef internal::Address A;
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::GetInstanceType(obj) != I::kOddballType) return false;
return (I::GetOddballKind(obj) == I::kNullOddballKind);
@ -9938,9 +9928,9 @@ bool Value::IsNullOrUndefined() const {
}
bool Value::QuickIsNullOrUndefined() const {
typedef internal::Object O;
typedef internal::Address A;
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::GetInstanceType(obj) != I::kOddballType) return false;
int kind = I::GetOddballKind(obj);
@ -9956,9 +9946,9 @@ bool Value::IsString() const {
}
bool Value::QuickIsString() const {
typedef internal::Object O;
typedef internal::Address A;
typedef internal::Internals I;
O* obj = *reinterpret_cast<O* const*>(this);
A obj = *reinterpret_cast<const A*>(this);
if (!I::HasHeapObjectTag(obj)) return false;
return (I::GetInstanceType(obj) < I::kFirstNonstringType);
}
@ -10333,7 +10323,7 @@ bool PropertyCallbackInfo<T>::ShouldThrowOnError() const {
Local<Primitive> Undefined(Isolate* isolate) {
typedef internal::Object* S;
typedef internal::Address S;
typedef internal::Internals I;
I::CheckInitialized(isolate);
S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
@ -10342,7 +10332,7 @@ Local<Primitive> Undefined(Isolate* isolate) {
Local<Primitive> Null(Isolate* isolate) {
typedef internal::Object* S;
typedef internal::Address S;
typedef internal::Internals I;
I::CheckInitialized(isolate);
S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
@ -10351,7 +10341,7 @@ Local<Primitive> Null(Isolate* isolate) {
Local<Boolean> True(Isolate* isolate) {
typedef internal::Object* S;
typedef internal::Address S;
typedef internal::Internals I;
I::CheckInitialized(isolate);
S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
@ -10360,7 +10350,7 @@ Local<Boolean> True(Isolate* isolate) {
Local<Boolean> False(Isolate* isolate) {
typedef internal::Object* S;
typedef internal::Address S;
typedef internal::Internals I;
I::CheckInitialized(isolate);
S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
@ -10428,11 +10418,11 @@ int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
Local<Value> Context::GetEmbedderData(int index) {
#ifndef V8_ENABLE_CHECKS
typedef internal::Object O;
typedef internal::Address A;
typedef internal::Internals I;
auto* context = *reinterpret_cast<internal::NeverReadOnlySpaceObject**>(this);
O** result =
HandleScope::CreateHandle(context, I::ReadEmbedderData<O*>(this, index));
A* result =
HandleScope::CreateHandle(context, I::ReadEmbedderData<A>(this, index));
return Local<Value>(reinterpret_cast<Value*>(result));
#else
return SlowGetEmbedderData(index);
@ -10459,14 +10449,14 @@ MaybeLocal<T> Context::GetDataFromSnapshotOnce(size_t index) {
template <class T>
size_t SnapshotCreator::AddData(Local<Context> context, Local<T> 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);
}
template <class T>
size_t SnapshotCreator::AddData(Local<T> 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);
}

View File

@ -61,7 +61,8 @@ inline JSObject* FunctionCallbackArguments::holder() {
} \
VMState<EXTERNAL> state(ISOLATE); \
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, \
API_RETURN_TYPE) \
@ -70,7 +71,8 @@ inline JSObject* FunctionCallbackArguments::holder() {
} \
VMState<EXTERNAL> state(ISOLATE); \
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, \
INFO_FOR_SIDE_EFFECT) \
@ -136,7 +138,9 @@ Handle<Object> FunctionCallbackArguments::Call(CallHandlerInfo* handler) {
}
VMState<EXTERNAL> state(isolate);
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);
return GetReturnValue<Object>(isolate);
}

View File

@ -611,13 +611,13 @@ size_t SnapshotCreator::AddTemplate(Local<Template> template_obj) {
return AddData(template_obj);
}
size_t SnapshotCreator::AddData(i::Object* object) {
DCHECK_NOT_NULL(object);
size_t SnapshotCreator::AddData(i::Address object) {
DCHECK_NE(object, i::kNullAddress);
SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
DCHECK(!data->created_);
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(data->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;
if (!isolate->heap()->serialized_objects()->IsArrayList()) {
list = i::ArrayList::New(isolate, 1);
@ -631,13 +631,13 @@ size_t SnapshotCreator::AddData(i::Object* object) {
return index;
}
size_t SnapshotCreator::AddData(Local<Context> context, i::Object* object) {
DCHECK_NOT_NULL(object);
size_t SnapshotCreator::AddData(Local<Context> context, i::Address object) {
DCHECK_NE(object, i::kNullAddress);
DCHECK(!SnapshotCreatorData::cast(data_)->created_);
i::Handle<i::Context> ctx = Utils::OpenHandle(*context);
i::Isolate* isolate = ctx->GetIsolate();
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;
if (!ctx->serialized_objects()->IsArrayList()) {
list = i::ArrayList::New(isolate, 1);
@ -966,66 +966,46 @@ void SetResourceConstraints(i::Isolate* isolate,
}
}
i::Object** V8::GlobalizeReference(i::Isolate* isolate, i::Object** obj) {
i::Address* V8::GlobalizeReference(i::Isolate* isolate, i::Address* obj) {
LOG_API(isolate, Persistent, New);
i::Handle<i::Object> result = isolate->global_handles()->Create(*obj);
#ifdef VERIFY_HEAP
if (i::FLAG_verify_heap) {
(*obj)->ObjectVerify(isolate);
reinterpret_cast<i::Object*>(*obj)->ObjectVerify(isolate);
}
#endif // VERIFY_HEAP
return result.location();
return result.location_as_address_ptr();
}
i::Object** V8::CopyPersistent(i::Object** obj) {
i::Address* V8::CopyPersistent(i::Address* 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) {
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,
WeakCallbackType 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);
}
void* V8::ClearWeak(i::Object** location) {
void* V8::ClearWeak(i::Address* 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);
}
void V8::DisposeGlobal(i::Object** location) {
void V8::DisposeGlobal(i::Address* location) {
i::GlobalHandles::Destroy(location);
}
@ -1078,14 +1058,16 @@ void HandleScope::Initialize(Isolate* isolate) {
"Entering the V8 API without proper locking in place");
i::HandleScopeData* current = internal_isolate->handle_scope_data();
isolate_ = internal_isolate;
prev_next_ = current->next;
prev_limit_ = current->limit;
prev_next_ = reinterpret_cast<i::Address*>(current->next);
prev_limit_ = reinterpret_cast<i::Address*>(current->limit);
current->level++;
}
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(); }
@ -1098,13 +1080,12 @@ int HandleScope::NumberOfHandles(Isolate* isolate) {
reinterpret_cast<i::Isolate*>(isolate));
}
i::Object** HandleScope::CreateHandle(i::Isolate* isolate, i::Object* value) {
i::Address* HandleScope::CreateHandle(i::Isolate* isolate, i::Address value) {
return i::HandleScope::CreateHandle(isolate, value);
}
i::Object** HandleScope::CreateHandle(
i::NeverReadOnlySpaceObject* writable_object, i::Object* value) {
i::Address* HandleScope::CreateHandle(
i::NeverReadOnlySpaceObject* writable_object, i::Address value) {
DCHECK(reinterpret_cast<i::HeapObject*>(writable_object)->IsHeapObject());
return i::HandleScope::CreateHandle(writable_object->GetIsolate(), value);
}
@ -1112,18 +1093,20 @@ i::Object** HandleScope::CreateHandle(
EscapableHandleScope::EscapableHandleScope(Isolate* v8_isolate) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
escape_slot_ =
CreateHandle(isolate, i::ReadOnlyRoots(isolate).the_hole_value());
escape_slot_ = CreateHandle(
isolate,
reinterpret_cast<i::Address>(i::ReadOnlyRoots(isolate).the_hole_value()));
Initialize(v8_isolate);
}
i::Object** EscapableHandleScope::Escape(i::Object** escape_value) {
i::Address* EscapableHandleScope::Escape(i::Address* escape_value) {
i::Heap* heap = reinterpret_cast<i::Isolate*>(GetIsolate())->heap();
Utils::ApiCheck((*escape_slot_)->IsTheHole(heap->isolate()),
Utils::ApiCheck(
reinterpret_cast<i::Object*>(*escape_slot_)->IsTheHole(heap->isolate()),
"EscapableHandleScope::Escape", "Escape value set twice");
if (escape_value == nullptr) {
*escape_slot_ = i::ReadOnlyRoots(heap).undefined_value();
*escape_slot_ =
reinterpret_cast<i::Address>(i::ReadOnlyRoots(heap).undefined_value());
return nullptr;
}
*escape_slot_ = *escape_value;
@ -1140,7 +1123,7 @@ void EscapableHandleScope::operator delete[](void*, size_t) {
SealHandleScope::SealHandleScope(Isolate* isolate)
: isolate_(reinterpret_cast<i::Isolate*>(isolate)) {
i::HandleScopeData* current = isolate_->handle_scope_data();
prev_limit_ = current->limit;
prev_limit_ = reinterpret_cast<i::Address*>(current->limit);
current->limit = current->next;
prev_sealed_level_ = current->sealed_level;
current->sealed_level = current->level;
@ -1150,7 +1133,7 @@ SealHandleScope::SealHandleScope(Isolate* isolate)
SealHandleScope::~SealHandleScope() {
i::HandleScopeData* current = isolate_->handle_scope_data();
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);
current->sealed_level = prev_sealed_level_;
}
@ -5685,7 +5668,6 @@ void v8::String::VerifyExternalStringResourceBase(
String::ExternalStringResource* String::GetExternalStringResourceSlow() const {
i::DisallowHeapAllocation no_allocation;
typedef internal::Internals I;
ExternalStringResource* result = nullptr;
i::String* str = *Utils::OpenHandle(this);
if (str->IsThinString()) {
@ -5693,10 +5675,11 @@ String::ExternalStringResource* String::GetExternalStringResourceSlow() const {
}
if (i::StringShape(str).IsExternalTwoByte()) {
void* value = I::ReadField<void*>(str, I::kStringResourceOffset);
result = reinterpret_cast<String::ExternalStringResource*>(value);
void* value = I::ReadField<void*>(reinterpret_cast<i::Address>(str),
I::kStringResourceOffset);
return reinterpret_cast<String::ExternalStringResource*>(value);
}
return result;
return nullptr;
}
String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow(
@ -5710,42 +5693,30 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow(
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);
if (i::StringShape(str).IsExternalOneByte() ||
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);
}
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*
v8::String::GetExternalOneByteStringResource() const {
i::DisallowHeapAllocation no_allocation;
i::String* str = *Utils::OpenHandle(this);
if (i::StringShape(str).IsExternalOneByte()) {
const void* resource = i::ExternalOneByteString::cast(str)->resource();
return reinterpret_cast<const ExternalOneByteStringResource*>(resource);
} else {
return GetExternalOneByteStringResourceSlow();
return i::ExternalOneByteString::cast(str)->resource();
} else if (str->IsThinString()) {
str = i::ThinString::cast(str)->actual();
if (i::StringShape(str).IsExternalOneByte()) {
return i::ExternalOneByteString::cast(str)->resource();
}
}
return nullptr;
}
@ -6295,7 +6266,7 @@ void Context::SetErrorMessageForCodeGenerationFromStrings(Local<String> error) {
}
namespace {
i::Object** GetSerializedDataFromFixedArray(i::Isolate* isolate,
i::Address* GetSerializedDataFromFixedArray(i::Isolate* isolate,
i::FixedArray* list, size_t index) {
if (index < static_cast<size_t>(list->length())) {
int int_index = static_cast<int>(index);
@ -6308,14 +6279,14 @@ i::Object** GetSerializedDataFromFixedArray(i::Isolate* isolate,
int last = list->length() - 1;
while (last >= 0 && list->is_the_hole(isolate, last)) last--;
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;
}
} // anonymous namespace
i::Object** Context::GetDataFromSnapshotOnce(size_t index) {
i::Address* Context::GetDataFromSnapshotOnce(size_t index) {
auto context = Utils::OpenHandle(this);
i::Isolate* i_isolate = context->GetIsolate();
i::FixedArray* list = context->serialized_objects();
@ -8359,7 +8330,7 @@ Isolate::SafeForTerminationScope::~SafeForTerminationScope() {
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::FixedArray* list = i_isolate->heap()->serialized_objects();
return GetSerializedDataFromFixedArray(i_isolate, list, index);
@ -9580,7 +9551,10 @@ debug::ConsoleCallArguments::ConsoleCallArguments(
debug::ConsoleCallArguments::ConsoleCallArguments(
internal::BuiltinArguments& args)
: v8::FunctionCallbackInfo<v8::Value>(nullptr, &args[0] - 1,
: v8::FunctionCallbackInfo<v8::Value>(
// 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) {

View File

@ -537,24 +537,31 @@ Handle<Object> GlobalHandles::Create(Object* value) {
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);
GlobalHandles* global_handles =
Node::FromLocation(location)->GetGlobalHandles();
Node::FromLocation(reinterpret_cast<Object**>(location))
->GetGlobalHandles();
#ifdef VERIFY_HEAP
if (i::FLAG_verify_heap) {
(*location)->ObjectVerify(global_handles->isolate());
(*reinterpret_cast<Object**>(location))
->ObjectVerify(global_handles->isolate());
}
#endif // VERIFY_HEAP
return global_handles->Create(*location);
}
void GlobalHandles::Destroy(Object** location) {
if (location != nullptr) Node::FromLocation(location)->Release();
}
void GlobalHandles::Destroy(Address* location) {
Destroy(reinterpret_cast<Object**>(location));
}
typedef v8::WeakCallbackInfo<void>::Callback GenericCallback;
@ -565,12 +572,24 @@ void GlobalHandles::MakeWeak(Object** location, void* parameter,
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) {
Node::FromLocation(*location_addr)->MakeWeak(location_addr);
}
void* GlobalHandles::ClearWeakness(Object** location) {
return Node::FromLocation(location)->ClearWeakness();
void GlobalHandles::MakeWeak(Address** location_addr) {
MakeWeak(reinterpret_cast<Object***>(location_addr));
}
void* GlobalHandles::ClearWeakness(Address* location) {
return Node::FromLocation(reinterpret_cast<Object**>(location))
->ClearWeakness();
}
void GlobalHandles::AnnotateStrongRetainer(Object** location,
@ -578,6 +597,12 @@ void GlobalHandles::AnnotateStrongRetainer(Object** location,
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) {
return Node::FromLocation(location)->IsNearDeath();
}

View File

@ -47,6 +47,9 @@ class GlobalHandles {
// Creates a new global handle that is alive until Destroy is called.
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>
Handle<T> Create(T* value) {
@ -57,10 +60,11 @@ class GlobalHandles {
}
// Copy a global handle
static Handle<Object> CopyGlobal(Object** location);
static Handle<Object> CopyGlobal(Address* location);
// Destroy a global handle.
static void Destroy(Object** location);
static void Destroy(Address* location);
// Make the global handle weak and set the callback parameter for the
// handle. When the garbage collector recognizes that only weak global
@ -74,10 +78,15 @@ class GlobalHandles {
static void MakeWeak(Object** location, void* parameter,
WeakCallbackInfo<void>::Callback weak_callback,
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(Address** location_addr);
static void AnnotateStrongRetainer(Object** location, const char* label);
static void AnnotateStrongRetainer(Address* location, const char* label);
void RecordStats(HeapStats* stats);
@ -97,12 +106,14 @@ class GlobalHandles {
size_t NumberOfNewSpaceNodes() { return new_space_nodes_.size(); }
// Clear the weakness of a global handle.
static void* ClearWeakness(Object** location);
static void* ClearWeakness(Address* location);
// Tells whether global handle is near death.
// TODO(jkummerow): This seems to be unused.
static bool IsNearDeath(Object** location);
// Tells whether global handle is weak.
// TODO(jkummerow): This seems to be unused.
static bool IsWeak(Object** location);
// Process pending weak handles.

View File

@ -96,8 +96,6 @@ class AllStatic {
};
typedef uint8_t byte;
typedef uintptr_t Address;
static const Address kNullAddress = 0;
// -----------------------------------------------------------------------------
// Constants

View File

@ -122,6 +122,22 @@ Object** HandleScope::CreateHandle(Isolate* isolate, Object* value) {
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) {
DCHECK(AllowHandleAllocation::IsAllowed());

View File

@ -121,6 +121,11 @@ class Handle final : public HandleBase {
V8_INLINE T** location() const {
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>
inline static const Handle<T> cast(Handle<S> that);
@ -185,6 +190,8 @@ class HandleScope {
// Creates a new handle with the given 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.
V8_EXPORT_PRIVATE static void DeleteExtensions(Isolate* isolate);

View File

@ -3652,7 +3652,7 @@ Address Heap::builtin_address(int index) {
void Heap::set_builtin(int index, HeapObject* builtin) {
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
// type here.
builtins_table()[index] = builtin;
@ -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
// objects are just passed around as Smis.
if (!(*object)->IsHeapObject()) return;
HeapObject* heap_object = HeapObject::cast(*object);
Object* object = *reinterpret_cast<Object**>(location);
if (!object->IsHeapObject()) return;
HeapObject* heap_object = HeapObject::cast(object);
DCHECK(Contains(heap_object));
if (FLAG_incremental_marking_wrappers && incremental_marking()->IsMarking()) {
incremental_marking()->WhiteToGreyAndPush(heap_object);

View File

@ -873,7 +873,7 @@ class Heap {
EmbedderHeapTracer* GetEmbedderHeapTracer() const;
void TracePossibleWrapper(JSObject* js_object);
void RegisterExternallyReferencedObject(Object** object);
void RegisterExternallyReferencedObject(Address* location);
void SetEmbedderStackStateForNextFinalizaton(
EmbedderHeapTracer::EmbedderStackState stack_state);

View File

@ -1464,7 +1464,8 @@ class Object {
// In objects.h to be usable without objects-inl.h inclusion.
bool Object::IsSmi() const { return HAS_SMI_TAG(this); }
bool Object::IsHeapObject() const {
DCHECK_EQ(!IsSmi(), Internals::HasHeapObjectTag(this));
DCHECK_EQ(!IsSmi(),
Internals::HasHeapObjectTag(reinterpret_cast<Address>(this)));
return !IsSmi();
}
@ -1485,7 +1486,9 @@ V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, const Brief& v);
class Smi: public Object {
public:
// 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() {
if (value() <= 0) return Smi::kZero;
return Smi::FromInt(static_cast<uint32_t>(value()));

View File

@ -130,7 +130,7 @@ class HeapObjectReference : public MaybeObject {
static void Update(HeapObjectReference** slot, HeapObject* value) {
DCHECK(!HAS_SMI_TAG(*slot));
DCHECK(Internals::HasHeapObjectTag(value));
DCHECK(Internals::HasHeapObjectTag(reinterpret_cast<Address>(value)));
#ifdef DEBUG
bool weak_before = HasWeakHeapObjectTag(*slot);

View File

@ -265,7 +265,8 @@ bool TickSample::GetStackSample(Isolate* v8_isolate, RegisterState* regs,
if (HAS_HEAP_OBJECT_TAG(bytecode_array) && HAS_SMI_TAG(bytecode_offset)) {
frames[i++] = reinterpret_cast<void*>(
reinterpret_cast<i::Address>(bytecode_array) +
i::Internals::SmiValue(bytecode_offset));
i::Internals::SmiValue(
reinterpret_cast<i::Address>(bytecode_offset)));
continue;
}
}

View File

@ -31,7 +31,7 @@ Address BuiltinDeserializerAllocator::Allocate(AllocationSpace space,
DCHECK(Builtins::IsBuiltinId(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();
}