Commit 79e6f35e authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[in-place weak refs] Move weak object tag away from v8.h.

Exposing it inside Internals was a hack. The downside of this CL is that heap
object tagging is in two places now (v8.h and globals.h).

BUG=v8:7308

Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: Ic7115ab20d67109dd2b62c772d52eeb84fa7d9f7
Reviewed-on: https://chromium-review.googlesource.com/968423Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52093}
parent 68bdf6a7
......@@ -145,9 +145,7 @@ class Arguments;
class DeferredHandles;
class Heap;
class HeapObject;
class HeapObjectReference;
class Isolate;
class MaybeObject;
class Object;
struct ScriptStreamingData;
template<typename T> class CustomArguments;
......@@ -8869,9 +8867,6 @@ const int kWeakHeapObjectTag = 3;
const int kHeapObjectTagSize = 2;
const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
const intptr_t kWeakHeapObjectMask = 1 << 1;
const intptr_t kClearedWeakHeapObject = 3;
// Tag information for Smi.
const int kSmiTag = 0;
const int kSmiTagSize = 1;
......@@ -9013,41 +9008,6 @@ class Internals {
kHeapObjectTag);
}
V8_INLINE static bool HasWeakHeapObjectTag(
const internal::MaybeObject* value) {
return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
kWeakHeapObjectTag);
}
// Object* should never have the weak tag; this variant is for overzealous
// checking.
V8_INLINE static bool HasWeakHeapObjectTag(const internal::Object* value) {
return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
kWeakHeapObjectTag);
}
V8_INLINE static bool IsClearedWeakHeapObject(internal::MaybeObject* value) {
return reinterpret_cast<intptr_t>(value) == kClearedWeakHeapObject;
}
V8_INLINE static internal::HeapObject* RemoveWeakHeapObjectMask(
internal::HeapObjectReference* value) {
return reinterpret_cast<HeapObject*>(reinterpret_cast<intptr_t>(value) &
~kWeakHeapObjectMask);
}
V8_INLINE static internal::HeapObjectReference* AddWeakHeapObjectMask(
internal::HeapObject* value) {
return reinterpret_cast<HeapObjectReference*>(
reinterpret_cast<intptr_t>(value) | kWeakHeapObjectMask);
}
V8_INLINE static internal::MaybeObject* AddWeakHeapObjectMask(
internal::MaybeObject* value) {
return reinterpret_cast<MaybeObject*>(reinterpret_cast<intptr_t>(value) |
kWeakHeapObjectMask);
}
V8_INLINE static int SmiValue(const internal::Object* value) {
return PlatformSmiTagging::SmiToInt(value);
}
......
......@@ -11,6 +11,7 @@
#include <limits>
#include <ostream>
#include "include/v8.h"
#include "src/base/build_config.h"
#include "src/base/flags.h"
#include "src/base/logging.h"
......@@ -413,10 +414,8 @@ constexpr int kCodeAlignmentBits = 5;
constexpr intptr_t kCodeAlignment = 1 << kCodeAlignmentBits;
constexpr intptr_t kCodeAlignmentMask = kCodeAlignment - 1;
// Weak references are tagged using the second bit in a pointer.
constexpr int kWeakReferenceTag = 3;
constexpr int kWeakReferenceTagSize = 2;
constexpr intptr_t kWeakReferenceTagMask = (1 << kWeakReferenceTagSize) - 1;
const intptr_t kWeakHeapObjectMask = 1 << 1;
const intptr_t kClearedWeakHeapObject = 3;
// Zap-value: The value used for zapping dead objects.
// Should be a recognizable hex value tagged as a failure.
......@@ -477,6 +476,7 @@ template <typename T> class MaybeHandle;
template <typename T> class Handle;
class Heap;
class HeapObject;
class HeapObjectReference;
class IC;
class InterceptorInfo;
class Isolate;
......@@ -489,6 +489,7 @@ class MacroAssembler;
class Map;
class MapSpace;
class MarkCompactCollector;
class MaybeObject;
class NewSpace;
class Object;
class OldSpace;
......@@ -1472,6 +1473,38 @@ enum IsolateAddressId {
kIsolateAddressCount
};
V8_INLINE static bool HasWeakHeapObjectTag(const internal::MaybeObject* value) {
return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
kWeakHeapObjectTag);
}
// Object* should never have the weak tag; this variant is for overzealous
// checking.
V8_INLINE static bool HasWeakHeapObjectTag(const Object* value) {
return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
kWeakHeapObjectTag);
}
V8_INLINE static bool IsClearedWeakHeapObject(MaybeObject* value) {
return reinterpret_cast<intptr_t>(value) == kClearedWeakHeapObject;
}
V8_INLINE static HeapObject* RemoveWeakHeapObjectMask(
HeapObjectReference* value) {
return reinterpret_cast<HeapObject*>(reinterpret_cast<intptr_t>(value) &
~kWeakHeapObjectMask);
}
V8_INLINE static HeapObjectReference* AddWeakHeapObjectMask(HeapObject* value) {
return reinterpret_cast<HeapObjectReference*>(
reinterpret_cast<intptr_t>(value) | kWeakHeapObjectMask);
}
V8_INLINE static MaybeObject* AddWeakHeapObjectMask(MaybeObject* value) {
return reinterpret_cast<MaybeObject*>(reinterpret_cast<intptr_t>(value) |
kWeakHeapObjectMask);
}
enum class HeapObjectReferenceType {
WEAK,
STRONG,
......
......@@ -129,7 +129,7 @@ class ConcurrentMarkingVisitor final
void VisitPointers(HeapObject* host, Object** start, Object** end) override {
for (Object** slot = start; slot < end; slot++) {
Object* object = base::AsAtomicPointer::Relaxed_Load(slot);
DCHECK(!Internals::HasWeakHeapObjectTag(object));
DCHECK(!HasWeakHeapObjectTag(object));
if (object->IsHeapObject()) {
ProcessStrongHeapObject(host, slot, HeapObject::cast(object));
}
......@@ -158,7 +158,7 @@ class ConcurrentMarkingVisitor final
for (int i = 0; i < snapshot.number_of_slots(); i++) {
Object** slot = snapshot.slot(i);
Object* object = snapshot.value(i);
DCHECK(!Internals::HasWeakHeapObjectTag(object));
DCHECK(!HasWeakHeapObjectTag(object));
if (!object->IsHeapObject()) continue;
MarkObject(HeapObject::cast(object));
MarkCompactCollector::RecordSlot(host, slot, object);
......
......@@ -461,17 +461,17 @@ void Heap::FinalizeExternalString(String* string) {
Address Heap::NewSpaceTop() { return new_space_->top(); }
bool Heap::InNewSpace(Object* object) {
DCHECK(!Internals::HasWeakHeapObjectTag(object));
DCHECK(!HasWeakHeapObjectTag(object));
return InNewSpace(MaybeObject::FromObject(object));
}
bool Heap::InFromSpace(Object* object) {
DCHECK(!Internals::HasWeakHeapObjectTag(object));
DCHECK(!HasWeakHeapObjectTag(object));
return InFromSpace(MaybeObject::FromObject(object));
}
bool Heap::InToSpace(Object* object) {
DCHECK(!Internals::HasWeakHeapObjectTag(object));
DCHECK(!HasWeakHeapObjectTag(object));
return InToSpace(MaybeObject::FromObject(object));
}
......@@ -518,8 +518,8 @@ bool Heap::ShouldBePromoted(Address old_address) {
}
void Heap::RecordWrite(Object* object, Object** slot, Object* value) {
DCHECK(!Internals::HasWeakHeapObjectTag(*slot));
DCHECK(!Internals::HasWeakHeapObjectTag(value));
DCHECK(!HasWeakHeapObjectTag(*slot));
DCHECK(!HasWeakHeapObjectTag(value));
RecordWrite(object, reinterpret_cast<MaybeObject**>(slot),
reinterpret_cast<MaybeObject*>(value));
}
......
......@@ -1450,7 +1450,7 @@ class StringTableVerifier : public ObjectVisitor {
void VisitPointers(HeapObject* host, Object** start, Object** end) override {
// Visit all HeapObject pointers in [start, end).
for (Object** p = start; p < end; p++) {
DCHECK(!Internals::HasWeakHeapObjectTag(*p));
DCHECK(!HasWeakHeapObjectTag(*p));
if ((*p)->IsHeapObject()) {
HeapObject* object = HeapObject::cast(*p);
Isolate* isolate = object->GetIsolate();
......@@ -4919,7 +4919,7 @@ class SlotVerifyingVisitor : public ObjectVisitor {
void VisitPointers(HeapObject* host, Object** start, Object** end) override {
#ifdef DEBUG
for (Object** slot = start; slot < end; slot++) {
DCHECK(!Internals::HasWeakHeapObjectTag(*slot));
DCHECK(!HasWeakHeapObjectTag(*slot));
}
#endif // DEBUG
VisitPointers(host, reinterpret_cast<MaybeObject**>(start),
......
......@@ -15,8 +15,8 @@ namespace internal {
void IncrementalMarking::RecordWrite(HeapObject* obj, Object** slot,
Object* value) {
DCHECK_IMPLIES(slot != nullptr, !Internals::HasWeakHeapObjectTag(*slot));
DCHECK(!Internals::HasWeakHeapObjectTag(value));
DCHECK_IMPLIES(slot != nullptr, !HasWeakHeapObjectTag(*slot));
DCHECK(!HasWeakHeapObjectTag(value));
RecordMaybeWeakWrite(obj, reinterpret_cast<MaybeObject**>(slot),
reinterpret_cast<MaybeObject*>(value));
}
......
......@@ -235,7 +235,7 @@ class YoungGenerationMarkingVerifier : public MarkingVerifier {
void VerifyPointers(Object** start, Object** end) override {
for (Object** current = start; current < end; current++) {
DCHECK(!Internals::HasWeakHeapObjectTag(*current));
DCHECK(!HasWeakHeapObjectTag(*current));
if ((*current)->IsHeapObject()) {
HeapObject* object = HeapObject::cast(*current);
if (!heap_->InNewSpace(object)) return;
......@@ -1061,7 +1061,7 @@ class MarkCompactCollector::CustomRootBodyMarkingVisitor final
void VisitPointers(HeapObject* host, Object** start, Object** end) final {
for (Object** p = start; p < end; p++) {
DCHECK(!Internals::HasWeakHeapObjectTag(*p));
DCHECK(!HasWeakHeapObjectTag(*p));
MarkObject(host, *p);
}
}
......@@ -1255,7 +1255,7 @@ class RecordMigratedSlotVisitor : public ObjectVisitor {
: collector_(collector) {}
inline void VisitPointer(HeapObject* host, Object** p) final {
DCHECK(!Internals::HasWeakHeapObjectTag(*p));
DCHECK(!HasWeakHeapObjectTag(*p));
RecordMigratedSlot(host, reinterpret_cast<MaybeObject*>(*p),
reinterpret_cast<Address>(p));
}
......@@ -1829,7 +1829,7 @@ class YoungGenerationMarkingVisitor final
V8_INLINE void VisitPointer(HeapObject* host, Object** slot) final {
Object* target = *slot;
DCHECK(!Internals::HasWeakHeapObjectTag(target));
DCHECK(!HasWeakHeapObjectTag(target));
if (heap_->InNewSpace(target)) {
HeapObject* target_object = HeapObject::cast(target);
MarkObjectViaMarkingWorklist(target_object);
......@@ -3005,7 +3005,7 @@ class PointersUpdatingVisitor : public ObjectVisitor, public RootVisitor {
}
static inline SlotCallbackResult UpdateStrongSlotInternal(Object** slot) {
DCHECK(!Internals::HasWeakHeapObjectTag(*slot));
DCHECK(!HasWeakHeapObjectTag(*slot));
return UpdateStrongSlot<AccessMode::NON_ATOMIC>(
reinterpret_cast<MaybeObject**>(slot));
}
......
......@@ -282,7 +282,7 @@ class UpdateTypedSlotHelper {
Object* old_code = code;
SlotCallbackResult result =
callback(reinterpret_cast<MaybeObject**>(&code));
DCHECK(!Internals::HasWeakHeapObjectTag(code));
DCHECK(!HasWeakHeapObjectTag(code));
if (code != old_code) {
Memory::Address_at(entry_address) =
reinterpret_cast<Code*>(code)->entry();
......@@ -300,7 +300,7 @@ class UpdateTypedSlotHelper {
Object* new_target = old_target;
SlotCallbackResult result =
callback(reinterpret_cast<MaybeObject**>(&new_target));
DCHECK(!Internals::HasWeakHeapObjectTag(new_target));
DCHECK(!HasWeakHeapObjectTag(new_target));
if (new_target != old_target) {
rinfo->set_target_address(Code::cast(new_target)->instruction_start());
}
......@@ -317,7 +317,7 @@ class UpdateTypedSlotHelper {
Object* new_target = old_target;
SlotCallbackResult result =
callback(reinterpret_cast<MaybeObject**>(&new_target));
DCHECK(!Internals::HasWeakHeapObjectTag(new_target));
DCHECK(!HasWeakHeapObjectTag(new_target));
if (new_target != old_target) {
rinfo->set_target_object(HeapObject::cast(new_target));
}
......
......@@ -25,7 +25,7 @@ class IterateAndScavengePromotedObjectsVisitor final : public ObjectVisitor {
Object** end) final {
for (Object** slot = start; slot < end; ++slot) {
Object* target = *slot;
DCHECK(!Internals::HasWeakHeapObjectTag(target));
DCHECK(!HasWeakHeapObjectTag(target));
if (target->IsHeapObject()) {
HandleSlot(host, reinterpret_cast<Address>(slot),
HeapObject::cast(target));
......@@ -183,7 +183,7 @@ void Scavenger::Finalize() {
void RootScavengeVisitor::VisitRootPointer(Root root, const char* description,
Object** p) {
DCHECK(!Internals::HasWeakHeapObjectTag(*p));
DCHECK(!HasWeakHeapObjectTag(*p));
ScavengePointer(p);
}
......@@ -195,7 +195,7 @@ void RootScavengeVisitor::VisitRootPointers(Root root, const char* description,
void RootScavengeVisitor::ScavengePointer(Object** p) {
Object* object = *p;
DCHECK(!Internals::HasWeakHeapObjectTag(object));
DCHECK(!HasWeakHeapObjectTag(object));
if (!heap_->InNewSpace(object)) return;
scavenger_->ScavengeObject(reinterpret_cast<HeapObjectReference**>(p),
......
......@@ -39,7 +39,7 @@ bool MaybeObject::ToStrongOrWeakHeapObject(
if (IsSmi() || IsClearedWeakHeapObject()) {
return false;
}
*reference_type = Internals::HasWeakHeapObjectTag(this)
*reference_type = HasWeakHeapObjectTag(this)
? HeapObjectReferenceType::WEAK
: HeapObjectReferenceType::STRONG;
*result = GetHeapObject();
......@@ -47,11 +47,11 @@ bool MaybeObject::ToStrongOrWeakHeapObject(
}
bool MaybeObject::IsStrongHeapObject() {
return !Internals::HasWeakHeapObjectTag(this) && !IsSmi();
return !HasWeakHeapObjectTag(this) && !IsSmi();
}
bool MaybeObject::ToStrongHeapObject(HeapObject** result) {
if (!Internals::HasWeakHeapObjectTag(this) && !IsSmi()) {
if (!HasWeakHeapObjectTag(this) && !IsSmi()) {
*result = reinterpret_cast<HeapObject*>(this);
return true;
}
......@@ -59,11 +59,11 @@ bool MaybeObject::ToStrongHeapObject(HeapObject** result) {
}
bool MaybeObject::IsWeakHeapObject() {
return Internals::HasWeakHeapObjectTag(this) && !IsClearedWeakHeapObject();
return HasWeakHeapObjectTag(this) && !IsClearedWeakHeapObject();
}
bool MaybeObject::ToWeakHeapObject(HeapObject** result) {
if (Internals::HasWeakHeapObjectTag(this) && !IsClearedWeakHeapObject()) {
if (HasWeakHeapObjectTag(this) && !IsClearedWeakHeapObject()) {
*result = GetHeapObject();
return true;
}
......@@ -73,8 +73,7 @@ bool MaybeObject::ToWeakHeapObject(HeapObject** result) {
HeapObject* MaybeObject::GetHeapObject() {
DCHECK(!IsSmi());
DCHECK(!IsClearedWeakHeapObject());
return Internals::RemoveWeakHeapObjectMask(
reinterpret_cast<HeapObjectReference*>(this));
return RemoveWeakHeapObjectMask(reinterpret_cast<HeapObjectReference*>(this));
}
} // namespace internal
......
......@@ -23,7 +23,7 @@ class MaybeObject {
inline bool IsSmi(Smi** value);
bool IsClearedWeakHeapObject() {
return Internals::IsClearedWeakHeapObject(this);
return ::v8::internal::IsClearedWeakHeapObject(this);
}
inline bool IsStrongOrWeakHeapObject();
......@@ -43,13 +43,13 @@ class MaybeObject {
}
static MaybeObject* FromObject(Object* object) {
DCHECK(!Internals::HasWeakHeapObjectTag(object));
DCHECK(!HasWeakHeapObjectTag(object));
return reinterpret_cast<MaybeObject*>(object);
}
static MaybeObject* MakeWeak(MaybeObject* object) {
DCHECK(object->IsStrongOrWeakHeapObject());
return Internals::AddWeakHeapObjectMask(object);
return AddWeakHeapObjectMask(object);
}
#ifdef VERIFY_HEAP
......@@ -65,13 +65,13 @@ class MaybeObject {
class HeapObjectReference : public MaybeObject {
public:
static HeapObjectReference* Strong(HeapObject* object) {
DCHECK(!Internals::HasWeakHeapObjectTag(object));
DCHECK(!HasWeakHeapObjectTag(object));
return reinterpret_cast<HeapObjectReference*>(object);
}
static HeapObjectReference* Weak(HeapObject* object) {
DCHECK(!Internals::HasWeakHeapObjectTag(object));
return Internals::AddWeakHeapObjectMask(object);
DCHECK(!HasWeakHeapObjectTag(object));
return AddWeakHeapObjectMask(object);
}
static HeapObjectReference* ClearedValue() {
......@@ -83,7 +83,7 @@ class HeapObjectReference : public MaybeObject {
DCHECK(Internals::HasHeapObjectTag(value));
#ifdef DEBUG
bool weak_before = Internals::HasWeakHeapObjectTag(*slot);
bool weak_before = HasWeakHeapObjectTag(*slot);
#endif
*slot = reinterpret_cast<HeapObjectReference*>(
......@@ -91,7 +91,7 @@ class HeapObjectReference : public MaybeObject {
(reinterpret_cast<intptr_t>(*slot) & kWeakHeapObjectMask));
#ifdef DEBUG
bool weak_after = Internals::HasWeakHeapObjectTag(*slot);
bool weak_after = HasWeakHeapObjectTag(*slot);
DCHECK_EQ(weak_before, weak_after);
#endif
}
......
......@@ -292,7 +292,7 @@ HeapObject* Deserializer<AllocatorT>::GetBackReferencedObject(int space) {
}
hot_objects_.Add(obj);
DCHECK(!Internals::HasWeakHeapObjectTag(obj));
DCHECK(!HasWeakHeapObjectTag(obj));
return obj;
}
......
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