Commit 0c509613 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

Revert "Global handles: Remove independent handle infrastructure"

This reverts 0944553e.

This is a short-term fix for NodeJS regression caused by Scavenger
not collecting weak handles that are marked as independent.

Bug: chromium:847863, chromium:780749
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: Ibd5224893c64baef1aaaecd18af94f29e2e74487
Reviewed-on: https://chromium-review.googlesource.com/1082439
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53498}
parent f34937ca
...@@ -9190,6 +9190,7 @@ class Internals { ...@@ -9190,6 +9190,7 @@ class Internals {
static const int kNodeStateIsWeakValue = 2; static const int kNodeStateIsWeakValue = 2;
static const int kNodeStateIsPendingValue = 3; static const int kNodeStateIsPendingValue = 3;
static const int kNodeStateIsNearDeathValue = 4; static const int kNodeStateIsNearDeathValue = 4;
static const int kNodeIsIndependentShift = 3;
static const int kNodeIsActiveShift = 4; static const int kNodeIsActiveShift = 4;
static const int kFirstNonstringType = 0x80; static const int kFirstNonstringType = 0x80;
...@@ -9413,7 +9414,10 @@ void Persistent<T, M>::Copy(const Persistent<S, M2>& that) { ...@@ -9413,7 +9414,10 @@ void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
template <class T> template <class T>
bool PersistentBase<T>::IsIndependent() const { bool PersistentBase<T>::IsIndependent() const {
return true; typedef internal::Internals I;
if (this->IsEmpty()) return false;
return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
I::kNodeIsIndependentShift);
} }
template <class T> template <class T>
...@@ -9502,7 +9506,12 @@ void PersistentBase<T>::RegisterExternalReference(Isolate* isolate) const { ...@@ -9502,7 +9506,12 @@ void PersistentBase<T>::RegisterExternalReference(Isolate* isolate) const {
} }
template <class T> template <class T>
void PersistentBase<T>::MarkIndependent() {} void PersistentBase<T>::MarkIndependent() {
typedef internal::Internals I;
if (this->IsEmpty()) return;
I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), true,
I::kNodeIsIndependentShift);
}
template <class T> template <class T>
void PersistentBase<T>::MarkActive() { void PersistentBase<T>::MarkActive() {
......
...@@ -41,6 +41,8 @@ class GlobalHandles::Node { ...@@ -41,6 +41,8 @@ class GlobalHandles::Node {
STATIC_ASSERT(WEAK == Internals::kNodeStateIsWeakValue); STATIC_ASSERT(WEAK == Internals::kNodeStateIsWeakValue);
STATIC_ASSERT(PENDING == Internals::kNodeStateIsPendingValue); STATIC_ASSERT(PENDING == Internals::kNodeStateIsPendingValue);
STATIC_ASSERT(NEAR_DEATH == Internals::kNodeStateIsNearDeathValue); STATIC_ASSERT(NEAR_DEATH == Internals::kNodeStateIsNearDeathValue);
STATIC_ASSERT(static_cast<int>(IsIndependent::kShift) ==
Internals::kNodeIsIndependentShift);
STATIC_ASSERT(static_cast<int>(IsActive::kShift) == STATIC_ASSERT(static_cast<int>(IsActive::kShift) ==
Internals::kNodeIsActiveShift); Internals::kNodeIsActiveShift);
} }
...@@ -52,6 +54,7 @@ class GlobalHandles::Node { ...@@ -52,6 +54,7 @@ class GlobalHandles::Node {
object_ = reinterpret_cast<Object*>(kGlobalHandleZapValue); object_ = reinterpret_cast<Object*>(kGlobalHandleZapValue);
class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId;
index_ = 0; index_ = 0;
set_independent(false);
set_active(false); set_active(false);
set_in_new_space_list(false); set_in_new_space_list(false);
data_.next_free = nullptr; data_.next_free = nullptr;
...@@ -73,6 +76,7 @@ class GlobalHandles::Node { ...@@ -73,6 +76,7 @@ class GlobalHandles::Node {
DCHECK(state() == FREE); DCHECK(state() == FREE);
object_ = object; object_ = object;
class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId;
set_independent(false);
set_active(false); set_active(false);
set_state(NORMAL); set_state(NORMAL);
data_.parameter = nullptr; data_.parameter = nullptr;
...@@ -92,6 +96,7 @@ class GlobalHandles::Node { ...@@ -92,6 +96,7 @@ class GlobalHandles::Node {
// Zap the values for eager trapping. // Zap the values for eager trapping.
object_ = reinterpret_cast<Object*>(kGlobalHandleZapValue); object_ = reinterpret_cast<Object*>(kGlobalHandleZapValue);
class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId;
set_independent(false);
set_active(false); set_active(false);
weak_callback_ = nullptr; weak_callback_ = nullptr;
DecreaseBlockUses(); DecreaseBlockUses();
...@@ -119,6 +124,9 @@ class GlobalHandles::Node { ...@@ -119,6 +124,9 @@ class GlobalHandles::Node {
flags_ = NodeState::update(flags_, state); flags_ = NodeState::update(flags_, state);
} }
bool is_independent() { return IsIndependent::decode(flags_); }
void set_independent(bool v) { flags_ = IsIndependent::update(flags_, v); }
bool is_active() { bool is_active() {
return IsActive::decode(flags_); return IsActive::decode(flags_);
} }
...@@ -183,6 +191,12 @@ class GlobalHandles::Node { ...@@ -183,6 +191,12 @@ class GlobalHandles::Node {
set_state(PENDING); set_state(PENDING);
} }
// Independent flag accessors.
void MarkIndependent() {
DCHECK(IsInUse());
set_independent(true);
}
// Callback parameter accessors. // Callback parameter accessors.
void set_parameter(void* parameter) { void set_parameter(void* parameter) {
DCHECK(IsInUse()); DCHECK(IsInUse());
...@@ -330,7 +344,7 @@ class GlobalHandles::Node { ...@@ -330,7 +344,7 @@ class GlobalHandles::Node {
// Placed first to avoid offset computation. // Placed first to avoid offset computation.
Object* object_; Object* object_;
// Next word stores class_id, index, and state. // Next word stores class_id, index, state, and independent.
// Note: the most aligned fields should go first. // Note: the most aligned fields should go first.
// Wrapper class ID. // Wrapper class ID.
...@@ -339,7 +353,10 @@ class GlobalHandles::Node { ...@@ -339,7 +353,10 @@ class GlobalHandles::Node {
// Index in the containing handle block. // Index in the containing handle block.
uint8_t index_; uint8_t index_;
// This stores three flags (independent, partially_dependent and
// in_new_space_list) and a State.
class NodeState : public BitField<State, 0, 3> {}; class NodeState : public BitField<State, 0, 3> {};
class IsIndependent : public BitField<bool, 3, 1> {};
// The following two fields are mutually exclusive // The following two fields are mutually exclusive
class IsActive : public BitField<bool, 4, 1> {}; class IsActive : public BitField<bool, 4, 1> {};
class IsInNewSpaceList : public BitField<bool, 5, 1> {}; class IsInNewSpaceList : public BitField<bool, 5, 1> {};
...@@ -591,6 +608,14 @@ void GlobalHandles::AnnotateStrongRetainer(Object** location, ...@@ -591,6 +608,14 @@ void GlobalHandles::AnnotateStrongRetainer(Object** location,
Node::FromLocation(location)->AnnotateStrongRetainer(label); Node::FromLocation(location)->AnnotateStrongRetainer(label);
} }
void GlobalHandles::MarkIndependent(Object** location) {
Node::FromLocation(location)->MarkIndependent();
}
bool GlobalHandles::IsIndependent(Object** location) {
return Node::FromLocation(location)->is_independent();
}
bool GlobalHandles::IsNearDeath(Object** location) { bool GlobalHandles::IsNearDeath(Object** location) {
return Node::FromLocation(location)->IsNearDeath(); return Node::FromLocation(location)->IsNearDeath();
} }
......
...@@ -99,6 +99,11 @@ class GlobalHandles { ...@@ -99,6 +99,11 @@ class GlobalHandles {
// Clear the weakness of a global handle. // Clear the weakness of a global handle.
static void* ClearWeakness(Object** location); static void* ClearWeakness(Object** location);
// Mark the reference to this object independent.
static void MarkIndependent(Object** location);
static bool IsIndependent(Object** location);
// Tells whether global handle is near death. // Tells whether global handle is near death.
static bool IsNearDeath(Object** location); static bool IsNearDeath(Object** location);
...@@ -155,7 +160,8 @@ class GlobalHandles { ...@@ -155,7 +160,8 @@ class GlobalHandles {
void MarkNewSpaceWeakUnmodifiedObjectsPending( void MarkNewSpaceWeakUnmodifiedObjectsPending(
WeakSlotCallbackWithHeap is_dead); WeakSlotCallbackWithHeap is_dead);
// Iterates over weak unmodified handles. See the note above. // Iterates over weak independent or unmodified handles.
// See the note above.
void IterateNewSpaceWeakUnmodifiedRootsForFinalizers(RootVisitor* v); void IterateNewSpaceWeakUnmodifiedRootsForFinalizers(RootVisitor* v);
void IterateNewSpaceWeakUnmodifiedRootsForPhantomHandles( void IterateNewSpaceWeakUnmodifiedRootsForPhantomHandles(
RootVisitor* v, WeakSlotCallbackWithHeap should_reset_handle); RootVisitor* v, WeakSlotCallbackWithHeap should_reset_handle);
......
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