Skip to content

Commit

Permalink
deps: V8: cherry-pick 6 commits
Browse files Browse the repository at this point in the history
Cherry-pick ad49f12.
Original commit message:

    [cleanup] Move Compressed[XXX]Slot definitions to separate header

    ... and fix header includes to please the respective bot.

    Drive-by-fix: decompression implementation is now MSVC friendly.

    Bug: v8:7703, v8:8834
    Change-Id: Iaf589138e5bafb32b0d9feab5cf074b71f241a3c
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1505579
    Commit-Queue: Igor Sheludko <ishell@chromium.org>
    Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#60074}

Refs: v8/v8@ad49f12

Cherry-pick 14f07a8.
Original commit message:

    [ptr-compr] Define kTaggedPayloadOffset correctly on Big Endian

    smi size is sill 8 bytes when V8_COMPRESS_POINTERS is undefined.

    Bug: v8:7703
    Change-Id: I0d1e757e42e8b1e6b10960420135245e24553175
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1508572
    Commit-Queue: Junliang Yan <jyan@ca.ibm.com>
    Auto-Submit: Junliang Yan <jyan@ca.ibm.com>
    Reviewed-by: Igor Sheludko <ishell@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#60097}

Refs: v8/v8@14f07a8

Cherry-pick 676014b.
Original commit message:

    [ptr-compr] Fix MSVC build

    ... which complained about truncating uintptr_t constant to uint32_t.

    Bug: v8:7703
    Change-Id: I6fae2bf1e5de79e6131479b84a8d8aa5b9de909f
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1508672
    Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
    Commit-Queue: Igor Sheludko <ishell@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#60100}

Refs: v8/v8@676014b

Cherry-pick 4e6a1a7.
Original commit message:

    [heap] Clean-up some weak map entries in scavenger

    This change enables clean-up of weak map entries in the
    scavenger of the weak map is in the young generation.
    With this change, the scavenger treats keys in ephemerons as
    weak instead of strong, but does not implement full ephemeron
    semantics: Values are treated always as strong, independently
    of whether the key is live or not.

    This approach ensures that no value is cleaned up accidentally.
    After scavenging, all entries with dead keys are removed from
    weak maps. After that, some values that are not referenced anywhere
    anymore might still be in the heap, and those can be cleaned up
    in the next scavenge.

    What the scavenger does, amounts to one iteration of the
    fixed-point algorithm required to implement ephemeron semantics.
    We hope that this is a reasonable trade-off between time spent
    tracing and cleaned-up entries.

    This change does not affect weak maps that reside in old space.

    Bug: v8:8557
    Change-Id: Ic5618b3b863ad8c314c87449571150e756fecbf0
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1467182
    Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
    Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#60101}

Refs: v8/v8@4e6a1a7

Cherry-pick afbfd75.
Original commit message:

    [ptr-compr] Fix ptr-compr broken by 4e6a1a75

    (https://chromium-review.googlesource.com/c/v8/v8/+/1467182)

    Bug: v8:7703
    Change-Id: Ia6b74b985735af67bde56b30e4a709247eb591be
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1508674
    Commit-Queue: Igor Sheludko <ishell@chromium.org>
    Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
    Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#60102}

Refs: v8/v8@afbfd75

Cherry-pick f792eb8.
Original commit message:

    [ptr-compr][arm64] Update pointer compression arm64's implementation

    Since kTaggedSize got shrinked and we are actually compressing
    the pointers (as oppposed to zeroing their upper bits),
    we need to update the arm64 codebase to accommodate this change.

    Cq-Include-Trybots: luci.v8.try:v8_linux64_arm64_pointer_compression_rel_ng
    Bug: v8:7703
    Change-Id: I890f3ab8c046f47232e80f85830f9ae8f4dbced4
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1499498
    Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
    Reviewed-by: Igor Sheludko <ishell@chromium.org>
    Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
    Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#60172}

Refs: v8/v8@f792eb8

PR-URL: #26685
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
targos authored and refack committed Mar 28, 2019
1 parent 8181811 commit b1015e0
Show file tree
Hide file tree
Showing 37 changed files with 478 additions and 359 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.9',
'v8_embedder_string': '-node.10',

##### V8 defaults for Node.js #####

Expand Down
2 changes: 2 additions & 0 deletions deps/v8/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,8 @@ v8_source_set("v8_base") {
"src/objects/code.h",
"src/objects/compilation-cache-inl.h",
"src/objects/compilation-cache.h",
"src/objects/compressed-slots-inl.h",
"src/objects/compressed-slots.h",
"src/objects/data-handler.h",
"src/objects/debug-objects-inl.h",
"src/objects/debug-objects.cc",
Expand Down
4 changes: 4 additions & 0 deletions deps/v8/src/arm64/macro-assembler-arm64-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,11 @@ void TurboAssembler::SmiUntag(Register dst, const MemOperand& src) {
}
} else {
DCHECK(SmiValuesAre31Bits());
#ifdef V8_COMPRESS_POINTERS
Ldrsw(dst, src);
#else
Ldr(dst, src);
#endif
SmiUntag(dst);
}
}
Expand Down
20 changes: 6 additions & 14 deletions deps/v8/src/arm64/macro-assembler-arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2813,11 +2813,7 @@ void TurboAssembler::StoreTaggedField(const Register& value,
const MemOperand& dst_field_operand) {
#ifdef V8_COMPRESS_POINTERS
RecordComment("[ StoreTagged");
// Use temporary register to zero out and don't trash value register
UseScratchRegisterScope temps(this);
Register compressed_value = temps.AcquireX();
Uxtw(compressed_value, value);
Str(compressed_value, dst_field_operand);
Str(value.W(), dst_field_operand);
RecordComment("]");
#else
Str(value, dst_field_operand);
Expand All @@ -2827,27 +2823,23 @@ void TurboAssembler::StoreTaggedField(const Register& value,
void TurboAssembler::DecompressTaggedSigned(const Register& destination,
const MemOperand& field_operand) {
RecordComment("[ DecompressTaggedSigned");
// TODO(solanes): use Ldrsw instead of Ldr,SXTW once kTaggedSize is shrinked
Ldr(destination, field_operand);
Sxtw(destination, destination);
Ldrsw(destination, field_operand);
RecordComment("]");
}

void TurboAssembler::DecompressTaggedPointer(const Register& destination,
const MemOperand& field_operand) {
RecordComment("[ DecompressTaggedPointer");
// TODO(solanes): use Ldrsw instead of Ldr,SXTW once kTaggedSize is shrinked
Ldr(destination, field_operand);
Add(destination, kRootRegister, Operand(destination, SXTW));
Ldrsw(destination, field_operand);
Add(destination, kRootRegister, destination);
RecordComment("]");
}

void TurboAssembler::DecompressAnyTagged(const Register& destination,
const MemOperand& field_operand) {
RecordComment("[ DecompressAnyTagged");
UseScratchRegisterScope temps(this);
// TODO(solanes): use Ldrsw instead of Ldr,SXTW once kTaggedSize is shrinked
Ldr(destination, field_operand);
Ldrsw(destination, field_operand);
// Branchlessly compute |masked_root|:
// masked_root = HAS_SMI_TAG(destination) ? 0 : kRootRegister;
STATIC_ASSERT((kSmiTagSize == 1) && (kSmiTag == 0));
Expand All @@ -2857,7 +2849,7 @@ void TurboAssembler::DecompressAnyTagged(const Register& destination,
And(masked_root, masked_root, kRootRegister);
// Now this add operation will either leave the value unchanged if it is a smi
// or add the isolate root if it is a heap object.
Add(destination, masked_root, Operand(destination, SXTW));
Add(destination, masked_root, destination);
RecordComment("]");
}

Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/base/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ V8_INLINE A implicit_cast(A x) {
#define V8PRIdPTR V8_PTR_PREFIX "d"
#define V8PRIuPTR V8_PTR_PREFIX "u"

#ifdef V8_TARGET_ARCH_64_BIT
#if V8_TARGET_ARCH_64_BIT
#define V8_PTR_HEX_DIGITS 12
#define V8PRIxPTR_FMT "0x%012" V8PRIxPTR
#else
Expand Down
1 change: 0 additions & 1 deletion deps/v8/src/bootstrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "src/heap/factory.h"
#include "src/objects/fixed-array.h"
#include "src/objects/shared-function-info.h"
#include "src/objects/slots.h"
#include "src/snapshot/natives.h"
#include "src/visitors.h"

Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/builtins/arm64/builtins-arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2555,7 +2555,7 @@ void Generate_PushBoundArguments(MacroAssembler* masm) {
__ SlotAddress(copy_to, argc);
__ Add(argc, argc,
bound_argc); // Update argc to include bound arguments.
__ Lsl(counter, bound_argc, kSystemPointerSizeLog2);
__ Lsl(counter, bound_argc, kTaggedSizeLog2);
__ Bind(&loop);
__ Sub(counter, counter, kTaggedSize);
__ LoadAnyTaggedField(scratch, MemOperand(bound_argv, counter));
Expand Down
1 change: 1 addition & 0 deletions deps/v8/src/heap/heap-write-barrier-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// elsewhere.
#include "src/isolate.h"
#include "src/objects/code.h"
#include "src/objects/compressed-slots-inl.h"
#include "src/objects/fixed-array.h"
#include "src/objects/heap-object.h"
#include "src/objects/maybe-object-inl.h"
Expand Down
14 changes: 14 additions & 0 deletions deps/v8/src/heap/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,20 @@ class HeapObjectAllocationTracker {
virtual ~HeapObjectAllocationTracker() = default;
};

template <typename T>
T ForwardingAddress(T heap_obj) {
MapWord map_word = heap_obj->map_word();

if (map_word.IsForwardingAddress()) {
return T::cast(map_word.ToForwardingAddress());
} else if (Heap::InFromPage(heap_obj)) {
return T();
} else {
// TODO(ulan): Support minor mark-compactor here.
return heap_obj;
}
}

} // namespace internal
} // namespace v8

Expand Down
16 changes: 0 additions & 16 deletions deps/v8/src/heap/incremental-marking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -609,22 +609,6 @@ void IncrementalMarking::UpdateMarkingWorklistAfterScavenge() {
UpdateWeakReferencesAfterScavenge();
}

namespace {
template <typename T>
T ForwardingAddress(T heap_obj) {
MapWord map_word = heap_obj->map_word();

if (map_word.IsForwardingAddress()) {
return T::cast(map_word.ToForwardingAddress());
} else if (Heap::InFromPage(heap_obj)) {
return T();
} else {
// TODO(ulan): Support minor mark-compactor here.
return heap_obj;
}
}
} // namespace

void IncrementalMarking::UpdateWeakReferencesAfterScavenge() {
weak_objects_->weak_references.Update(
[](std::pair<HeapObject, HeapObjectSlot> slot_in,
Expand Down
15 changes: 15 additions & 0 deletions deps/v8/src/heap/scavenger-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,21 @@ void ScavengeVisitor::VisitPointersImpl(HeapObject host, TSlot start,
}
}

int ScavengeVisitor::VisitEphemeronHashTable(Map map,
EphemeronHashTable table) {
// Register table with the scavenger, so it can take care of the weak keys
// later. This allows to only iterate the tables' values, which are treated
// as strong independetly of whether the key is live.
scavenger_->AddEphemeronHashTable(table);
for (int i = 0; i < table->Capacity(); i++) {
ObjectSlot value_slot =
table->RawFieldOfElementAt(EphemeronHashTable::EntryToValueIndex(i));
VisitPointer(table, value_slot);
}

return table->SizeFromMap(map);
}

} // namespace internal
} // namespace v8

Expand Down
66 changes: 57 additions & 9 deletions deps/v8/src/heap/scavenger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,25 @@ class IterateAndScavengePromotedObjectsVisitor final : public ObjectVisitor {
const bool record_slots_;
};

static bool IsUnscavengedHeapObject(Heap* heap, FullObjectSlot p) {
return Heap::InFromPage(*p) &&
!HeapObject::cast(*p)->map_word().IsForwardingAddress();
namespace {

V8_INLINE bool IsUnscavengedHeapObject(Heap* heap, Object object) {
return Heap::InFromPage(object) &&
!HeapObject::cast(object)->map_word().IsForwardingAddress();
}

// Same as IsUnscavengedHeapObject() above but specialized for HeapObjects.
V8_INLINE bool IsUnscavengedHeapObject(Heap* heap, HeapObject heap_object) {
return Heap::InFromPage(heap_object) &&
!heap_object->map_word().IsForwardingAddress();
}

bool IsUnscavengedHeapObjectSlot(Heap* heap, FullObjectSlot p) {
return IsUnscavengedHeapObject(heap, *p);
}

} // namespace

class ScavengeWeakObjectRetainer : public WeakObjectRetainer {
public:
Object RetainAs(Object object) override {
Expand Down Expand Up @@ -185,9 +199,10 @@ void ScavengerCollector::CollectGarbage() {
OneshotBarrier barrier(base::TimeDelta::FromMilliseconds(kMaxWaitTimeMs));
Scavenger::CopiedList copied_list(num_scavenge_tasks);
Scavenger::PromotionList promotion_list(num_scavenge_tasks);
EphemeronTableList ephemeron_table_list(num_scavenge_tasks);
for (int i = 0; i < num_scavenge_tasks; i++) {
scavengers[i] = new Scavenger(this, heap_, is_logging, &copied_list,
&promotion_list, i);
&promotion_list, &ephemeron_table_list, i);
job.AddTask(new ScavengingTask(heap_, scavengers[i], &barrier));
}

Expand Down Expand Up @@ -235,7 +250,7 @@ void ScavengerCollector::CollectGarbage() {
TRACE_GC(heap_->tracer(),
GCTracer::Scope::SCAVENGER_SCAVENGE_WEAK_GLOBAL_HANDLES_PROCESS);
isolate_->global_handles()->MarkYoungWeakUnmodifiedObjectsPending(
&IsUnscavengedHeapObject);
&IsUnscavengedHeapObjectSlot);
isolate_->global_handles()->IterateYoungWeakUnmodifiedRootsForFinalizers(
&root_scavenge_visitor);
scavengers[kMainThreadId]->Process();
Expand All @@ -244,7 +259,7 @@ void ScavengerCollector::CollectGarbage() {
DCHECK(promotion_list.IsEmpty());
isolate_->global_handles()
->IterateYoungWeakUnmodifiedRootsForPhantomHandles(
&root_scavenge_visitor, &IsUnscavengedHeapObject);
&root_scavenge_visitor, &IsUnscavengedHeapObjectSlot);
}

{
Expand Down Expand Up @@ -280,8 +295,7 @@ void ScavengerCollector::CollectGarbage() {
}
}

ScavengeWeakObjectRetainer weak_object_retainer;
heap_->ProcessYoungWeakReferences(&weak_object_retainer);
ProcessWeakReferences(&ephemeron_table_list);

// Set age mark.
heap_->new_space_->set_age_mark(heap_->new_space()->top());
Expand Down Expand Up @@ -349,11 +363,12 @@ int ScavengerCollector::NumberOfScavengeTasks() {

Scavenger::Scavenger(ScavengerCollector* collector, Heap* heap, bool is_logging,
CopiedList* copied_list, PromotionList* promotion_list,
int task_id)
EphemeronTableList* ephemeron_table_list, int task_id)
: collector_(collector),
heap_(heap),
promotion_list_(promotion_list, task_id),
copied_list_(copied_list, task_id),
ephemeron_table_list_(ephemeron_table_list, task_id),
local_pretenuring_feedback_(kInitialLocalPretenuringFeedbackCapacity),
copied_size_(0),
promoted_size_(0),
Expand Down Expand Up @@ -440,12 +455,45 @@ void Scavenger::Process(OneshotBarrier* barrier) {
} while (!done);
}

void ScavengerCollector::ProcessWeakReferences(
EphemeronTableList* ephemeron_table_list) {
ScavengeWeakObjectRetainer weak_object_retainer;
heap_->ProcessYoungWeakReferences(&weak_object_retainer);
ClearYoungEphemerons(ephemeron_table_list);
}

// Clears ephemerons contained in {EphemeronHashTable}s in young generation.
void ScavengerCollector::ClearYoungEphemerons(
EphemeronTableList* ephemeron_table_list) {
ephemeron_table_list->Iterate([this](EphemeronHashTable table) {
for (int i = 0; i < table->Capacity(); i++) {
ObjectSlot key_slot =
table->RawFieldOfElementAt(EphemeronHashTable::EntryToIndex(i));
Object key = *key_slot;
if (key->IsHeapObject()) {
if (IsUnscavengedHeapObject(heap_, HeapObject::cast(key))) {
table->RemoveEntry(i);
} else {
HeapObject forwarded = ForwardingAddress(HeapObject::cast(key));
HeapObjectReference::Update(HeapObjectSlot(key_slot), forwarded);
}
}
}
});
ephemeron_table_list->Clear();
}

void Scavenger::Finalize() {
heap()->MergeAllocationSitePretenuringFeedback(local_pretenuring_feedback_);
heap()->IncrementSemiSpaceCopiedObjectSize(copied_size_);
heap()->IncrementPromotedObjectsSize(promoted_size_);
collector_->MergeSurvivingNewLargeObjects(surviving_new_large_objects_);
allocator_.Finalize();
ephemeron_table_list_.FlushToGlobal();
}

void Scavenger::AddEphemeronHashTable(EphemeronHashTable table) {
ephemeron_table_list_.Push(table);
}

void RootScavengeVisitor::VisitRootPointer(Root root, const char* description,
Expand Down
13 changes: 11 additions & 2 deletions deps/v8/src/heap/scavenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ using SurvivingNewLargeObjectsMap =
std::unordered_map<HeapObject, Map, Object::Hasher>;
using SurvivingNewLargeObjectMapEntry = std::pair<HeapObject, Map>;

constexpr int kEphemeronTableListSegmentSize = 128;
using EphemeronTableList =
Worklist<EphemeronHashTable, kEphemeronTableListSegmentSize>;

class ScavengerCollector {
public:
static const int kMaxScavengerTasks = 8;
Expand All @@ -42,6 +46,8 @@ class ScavengerCollector {

int NumberOfScavengeTasks();

void ProcessWeakReferences(EphemeronTableList* ephemeron_table_list);
void ClearYoungEphemerons(EphemeronTableList* ephemeron_table_list);
void HandleSurvivingNewLargeObjects();

Isolate* const isolate_;
Expand Down Expand Up @@ -109,10 +115,9 @@ class Scavenger {
static const int kCopiedListSegmentSize = 256;

using CopiedList = Worklist<ObjectAndSize, kCopiedListSegmentSize>;

Scavenger(ScavengerCollector* collector, Heap* heap, bool is_logging,
CopiedList* copied_list, PromotionList* promotion_list,
int task_id);
EphemeronTableList* ephemeron_table_list, int task_id);

// Entry point for scavenging an old generation page. For scavenging single
// objects see RootScavengingVisitor and ScavengeVisitor below.
Expand All @@ -125,6 +130,8 @@ class Scavenger {
// Finalize the Scavenger. Needs to be called from the main thread.
void Finalize();

void AddEphemeronHashTable(EphemeronHashTable table);

size_t bytes_copied() const { return copied_size_; }
size_t bytes_promoted() const { return promoted_size_; }

Expand Down Expand Up @@ -199,6 +206,7 @@ class Scavenger {
Heap* const heap_;
PromotionList::View promotion_list_;
CopiedList::View copied_list_;
EphemeronTableList::View ephemeron_table_list_;
Heap::PretenuringFeedbackMap local_pretenuring_feedback_;
size_t copied_size_;
size_t promoted_size_;
Expand Down Expand Up @@ -242,6 +250,7 @@ class ScavengeVisitor final : public NewSpaceVisitor<ScavengeVisitor> {

V8_INLINE void VisitCodeTarget(Code host, RelocInfo* rinfo) final;
V8_INLINE void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) final;
V8_INLINE int VisitEphemeronHashTable(Map map, EphemeronHashTable object);

private:
template <typename TSlot>
Expand Down
5 changes: 1 addition & 4 deletions deps/v8/src/heap/slot-set.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
#include "src/allocation.h"
#include "src/base/atomic-utils.h"
#include "src/base/bits.h"
#include "src/objects/compressed-slots.h"
#include "src/objects/slots.h"
#include "src/utils.h"

#ifdef V8_COMPRESS_POINTERS
#include "src/ptr-compr.h"
#endif

namespace v8 {
namespace internal {

Expand Down
2 changes: 2 additions & 0 deletions deps/v8/src/heap/worklist.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class Worklist {
return worklist_->LocalPushSegmentSize(task_id_);
}

void FlushToGlobal() { worklist_->FlushToGlobal(task_id_); }

private:
Worklist<EntryType, SEGMENT_SIZE>* worklist_;
int task_id_;
Expand Down
Loading

0 comments on commit b1015e0

Please sign in to comment.