Revert "Global handles: Remove independent handle infrastructure"

This reverts 0944553ee8.

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: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53498}
This commit is contained in:
Ulan Degenbaev 2018-06-01 15:06:30 +02:00 committed by Commit Bot
parent f34937caef
commit 0c5096130b
3 changed files with 44 additions and 4 deletions

View File

@ -9190,6 +9190,7 @@ class Internals {
static const int kNodeStateIsWeakValue = 2;
static const int kNodeStateIsPendingValue = 3;
static const int kNodeStateIsNearDeathValue = 4;
static const int kNodeIsIndependentShift = 3;
static const int kNodeIsActiveShift = 4;
static const int kFirstNonstringType = 0x80;
@ -9413,7 +9414,10 @@ void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
template <class T>
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>
@ -9502,7 +9506,12 @@ void PersistentBase<T>::RegisterExternalReference(Isolate* isolate) const {
}
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>
void PersistentBase<T>::MarkActive() {

View File

@ -41,6 +41,8 @@ class GlobalHandles::Node {
STATIC_ASSERT(WEAK == Internals::kNodeStateIsWeakValue);
STATIC_ASSERT(PENDING == Internals::kNodeStateIsPendingValue);
STATIC_ASSERT(NEAR_DEATH == Internals::kNodeStateIsNearDeathValue);
STATIC_ASSERT(static_cast<int>(IsIndependent::kShift) ==
Internals::kNodeIsIndependentShift);
STATIC_ASSERT(static_cast<int>(IsActive::kShift) ==
Internals::kNodeIsActiveShift);
}
@ -52,6 +54,7 @@ class GlobalHandles::Node {
object_ = reinterpret_cast<Object*>(kGlobalHandleZapValue);
class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId;
index_ = 0;
set_independent(false);
set_active(false);
set_in_new_space_list(false);
data_.next_free = nullptr;
@ -73,6 +76,7 @@ class GlobalHandles::Node {
DCHECK(state() == FREE);
object_ = object;
class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId;
set_independent(false);
set_active(false);
set_state(NORMAL);
data_.parameter = nullptr;
@ -92,6 +96,7 @@ class GlobalHandles::Node {
// Zap the values for eager trapping.
object_ = reinterpret_cast<Object*>(kGlobalHandleZapValue);
class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId;
set_independent(false);
set_active(false);
weak_callback_ = nullptr;
DecreaseBlockUses();
@ -119,6 +124,9 @@ class GlobalHandles::Node {
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() {
return IsActive::decode(flags_);
}
@ -183,6 +191,12 @@ class GlobalHandles::Node {
set_state(PENDING);
}
// Independent flag accessors.
void MarkIndependent() {
DCHECK(IsInUse());
set_independent(true);
}
// Callback parameter accessors.
void set_parameter(void* parameter) {
DCHECK(IsInUse());
@ -330,7 +344,7 @@ class GlobalHandles::Node {
// Placed first to avoid offset computation.
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.
// Wrapper class ID.
@ -339,7 +353,10 @@ class GlobalHandles::Node {
// Index in the containing handle block.
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 IsIndependent : public BitField<bool, 3, 1> {};
// The following two fields are mutually exclusive
class IsActive : public BitField<bool, 4, 1> {};
class IsInNewSpaceList : public BitField<bool, 5, 1> {};
@ -591,6 +608,14 @@ void GlobalHandles::AnnotateStrongRetainer(Object** location,
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) {
return Node::FromLocation(location)->IsNearDeath();
}

View File

@ -99,6 +99,11 @@ class GlobalHandles {
// Clear the weakness of a global handle.
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.
static bool IsNearDeath(Object** location);
@ -155,7 +160,8 @@ class GlobalHandles {
void MarkNewSpaceWeakUnmodifiedObjectsPending(
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 IterateNewSpaceWeakUnmodifiedRootsForPhantomHandles(
RootVisitor* v, WeakSlotCallbackWithHeap should_reset_handle);