Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0ec8f7e
deps: update V8 to 12.7.224.16
targos Jul 17, 2024
cb87c17
build: reset embedder string to "-node.0"
targos Jul 17, 2024
e1f2d3a
src: update NODE_MODULE_VERSION to 129
targos Jun 30, 2024
65381db
deps: always define V8_EXPORT_PRIVATE as no-op
targos Sep 21, 2022
714adc2
deps: disable V8 concurrent sparkplug compilation
targos Apr 6, 2023
4092105
deps: avoid compilation error with ASan
targos Jul 31, 2023
5ec28ae
deps: patch V8 to avoid duplicated zlib symbol
targos Sep 16, 2023
9957c27
deps: silence internal V8 deprecation warning
targos Mar 11, 2024
b745131
deps: patch V8 to support compilation with MSVC
StefanStojanovic Apr 21, 2024
5a387cb
deps: V8: revert CL 5331688
targos Apr 21, 2024
98d6836
deps: fix FP16 bitcasts.h
StefanStojanovic May 28, 2024
b23f333
deps: V8: cherry-pick a3cc8522a4c8
kxxt Jun 11, 2024
e8c5877
deps: V8: cherry-pick e061cf9970d9
joyeecheung Jul 7, 2024
9a1d10d
deps: V8: cherry-pick 058870cfbea6
targos Jul 17, 2024
40547b0
build: include v8-sandbox.h header in distribution
targos Apr 7, 2024
21cd02d
src: add source location to v8::TaskRunner
fdoray Apr 16, 2024
127ada7
build: disable ICF for mksnapshot
LeszekSwirski Apr 12, 2024
740edbf
test: update v8-stats test for V8 12.6
targos May 9, 2024
d0137e2
tools: update V8 gypfiles for 12.6
targos May 11, 2024
09bf343
src: remove dependency on wrapper-descriptor-based CppHeap
joyeecheung May 29, 2024
a8deb42
build: update abseil files
richardlau Jul 18, 2024
a29cf0b
fixup! deps: patch V8 to avoid duplicated zlib symbol
targos Jul 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
deps: V8: cherry-pick 058870cfbea6
Original commit message:

    [heap] Fix allocation tracker line end retrieval

    Tests in NodeJS with DCHECK enabled were failing because of two
    different problems:
    - One was that we were also disallowing heap allocations in the
    serialization stage. But NodeJS tests process the heap snapshot
    result in JS, so all those were broken.
    - But, also, the code that would retrieve from line ends would assume
    all the scripts populated line ends in the snapshot. But this was
    wrong. To fix it, this patch adds another storage of the line ends
    in the allocation tracker. This storage needs to keep weak references
    to the scripts so we do not leak the line ends data when scripts are
    disposed.

    This change keeps a weak reference to the scripts so, when they are
    freed, the line ends cache is also freed as it is not useful anymore.

    Node issue: nodejs/node-v8#282

    Change-Id: I4314d707903175f0005893e9aa06d3ae52fc57f8
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5531355
    Commit-Queue: José Dapena Paz <jdapena@igalia.com>
    Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
    Reviewed-by: Simon Zünd <szuend@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#94418}

Refs: v8/v8@058870c
  • Loading branch information
targos committed Jul 17, 2024
commit 9a1d10d941658b0565042cbb912b0a1bb0aeb8dc
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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.10',
'v8_embedder_string': '-node.11',

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

Expand Down
67 changes: 64 additions & 3 deletions deps/v8/src/profiler/allocation-tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

#include "src/profiler/allocation-tracker.h"

#include "src/api/api-inl.h"
#include "src/api/api.h"
#include "src/execution/frames-inl.h"
#include "src/handles/global-handles-inl.h"
#include "src/objects/objects-inl.h"
#include "src/profiler/heap-snapshot-generator-inl.h"
#include "src/utils/utils.h"

namespace v8 {
namespace internal {
Expand Down Expand Up @@ -96,7 +99,9 @@ AllocationTracker::FunctionInfo::FunctionInfo()
function_id(0),
script_name(""),
script_id(0),
start_position(-1) {}
start_position(-1),
line(-1),
column(-1) {}

void AddressToTraceMap::AddRange(Address start, int size,
unsigned trace_node_id) {
Expand Down Expand Up @@ -199,7 +204,7 @@ void AllocationTracker::AllocationEvent(Address addr, int size) {
SnapshotObjectId id =
ids_->FindOrAddEntry(shared.address(), shared->Size(),
HeapObjectsMap::MarkEntryAccessed::kNo);
allocation_trace_buffer_[length++] = AddFunctionInfo(shared, id);
allocation_trace_buffer_[length++] = AddFunctionInfo(shared, id, isolate);
it.Advance();
}
if (length == 0) {
Expand All @@ -220,8 +225,60 @@ static uint32_t SnapshotObjectIdHash(SnapshotObjectId id) {
return ComputeUnseededHash(static_cast<uint32_t>(id));
}

AllocationTracker::ScriptData::ScriptData(Tagged<Script> script,
Isolate* isolate,
AllocationTracker* tracker)
: script_id_(script->id()),
line_ends_(Script::GetLineEnds(isolate, handle(script, isolate))),
tracker_(tracker) {
DirectHandle<Script> script_direct_handle(script, isolate);
auto local_script = ToApiHandle<debug::Script>(script_direct_handle, isolate);
script_.Reset(local_script->GetIsolate(), local_script);
script_.SetWeak(this, &HandleWeakScript, v8::WeakCallbackType::kParameter);
}

AllocationTracker::ScriptData::~ScriptData() {
if (!script_.IsEmpty()) {
script_.ClearWeak();
}
}

void AllocationTracker::ScriptData::HandleWeakScript(
const v8::WeakCallbackInfo<ScriptData>& data) {
ScriptData* script_data = reinterpret_cast<ScriptData*>(data.GetParameter());
script_data->script_.ClearWeak();
script_data->script_.Reset();
script_data->tracker_->scripts_data_map_.erase(script_data->script_id_);
}

String::LineEndsVector& AllocationTracker::GetOrCreateLineEnds(
Tagged<Script> script, Isolate* isolate) {
auto it = scripts_data_map_.find(script->id());
if (it == scripts_data_map_.end()) {
auto inserted =
scripts_data_map_.try_emplace(script->id(), script, isolate, this);
CHECK(inserted.second);
return inserted.first->second.line_ends();
} else {
return it->second.line_ends();
}
}

Script::PositionInfo AllocationTracker::GetScriptPositionInfo(
Tagged<Script> script, Isolate* isolate, int start) {
Script::PositionInfo position_info;
if (script->has_line_ends()) {
script->GetPositionInfo(start, &position_info);
} else {
script->GetPositionInfoWithLineEnds(start, &position_info,
GetOrCreateLineEnds(script, isolate));
}
return position_info;
}

unsigned AllocationTracker::AddFunctionInfo(Tagged<SharedFunctionInfo> shared,
SnapshotObjectId id) {
SnapshotObjectId id,
Isolate* isolate) {
base::HashMap::Entry* entry = id_to_function_info_index_.LookupOrInsert(
reinterpret_cast<void*>(id), SnapshotObjectIdHash(id));
if (entry->value == nullptr) {
Expand All @@ -236,6 +293,10 @@ unsigned AllocationTracker::AddFunctionInfo(Tagged<SharedFunctionInfo> shared,
}
info->script_id = script->id();
info->start_position = shared->StartPosition();
Script::PositionInfo position_info =
GetScriptPositionInfo(script, isolate, info->start_position);
info->line = position_info.line;
info->column = position_info.column;
}
entry->value = reinterpret_cast<void*>(function_info_list_.size());
function_info_list_.push_back(info);
Expand Down
30 changes: 28 additions & 2 deletions deps/v8/src/profiler/allocation-tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
#define V8_PROFILER_ALLOCATION_TRACKER_H_

#include <map>
#include <unordered_map>
#include <vector>

#include "include/v8-persistent-handle.h"
#include "include/v8-profiler.h"
#include "include/v8-unwinder.h"
#include "src/base/hashmap.h"
#include "src/base/vector.h"
#include "src/debug/debug-interface.h"
#include "src/handles/handles.h"
#include "src/objects/script.h"
#include "src/objects/string.h"

namespace v8 {
namespace internal {
Expand Down Expand Up @@ -105,6 +109,8 @@ class AllocationTracker {
const char* script_name;
int script_id;
int start_position;
int line;
int column;
};

AllocationTracker(HeapObjectsMap* ids, StringsStorage* names);
Expand All @@ -121,8 +127,12 @@ class AllocationTracker {
AddressToTraceMap* address_to_trace() { return &address_to_trace_; }

private:
unsigned AddFunctionInfo(Tagged<SharedFunctionInfo> info,
SnapshotObjectId id);
unsigned AddFunctionInfo(Tagged<SharedFunctionInfo> info, SnapshotObjectId id,
Isolate* isolate);
String::LineEndsVector& GetOrCreateLineEnds(Tagged<Script> script,
Isolate* isolate);
Script::PositionInfo GetScriptPositionInfo(Tagged<Script> script,
Isolate* isolate, int start);
unsigned functionInfoIndexForVMState(StateTag state);

static const int kMaxAllocationTraceLength = 64;
Expand All @@ -134,6 +144,22 @@ class AllocationTracker {
base::HashMap id_to_function_info_index_;
unsigned info_index_for_other_state_;
AddressToTraceMap address_to_trace_;
using ScriptId = int;
class ScriptData {
public:
ScriptData(Tagged<Script>, Isolate*, AllocationTracker*);
~ScriptData();
String::LineEndsVector& line_ends() { return line_ends_; }

private:
static void HandleWeakScript(const v8::WeakCallbackInfo<ScriptData>&);
Global<debug::Script> script_;
ScriptId script_id_;
String::LineEndsVector line_ends_;
AllocationTracker* tracker_;
};
using ScriptsDataMap = std::unordered_map<ScriptId, ScriptData>;
ScriptsDataMap scripts_data_map_;
};

} // namespace internal
Expand Down
12 changes: 2 additions & 10 deletions deps/v8/src/profiler/heap-snapshot-generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3092,7 +3092,6 @@ bool HeapSnapshotGenerator::FillReferences() {
const int HeapSnapshotJSONSerializer::kNodeFieldsCount = 7;

void HeapSnapshotJSONSerializer::Serialize(v8::OutputStream* stream) {
DisallowHeapAllocation no_heap_allocation;
v8::base::ElapsedTimer timer;
timer.Start();
DCHECK_NULL(writer_);
Expand Down Expand Up @@ -3452,17 +3451,10 @@ void HeapSnapshotJSONSerializer::SerializeTraceNodeInfos() {
// The cast is safe because script id is a non-negative Smi.
buffer_pos =
utoa(static_cast<unsigned>(info->script_id), buffer, buffer_pos);

auto& line_ends = snapshot_->GetScriptLineEnds(info->script_id);
int line = -1;
int column = -1;
Script::GetLineColumnWithLineEnds(info->start_position, line, column,
line_ends);

buffer[buffer_pos++] = ',';
buffer_pos = SerializePosition(line, buffer, buffer_pos);
buffer_pos = SerializePosition(info->line, buffer, buffer_pos);
buffer[buffer_pos++] = ',';
buffer_pos = SerializePosition(column, buffer, buffer_pos);
buffer_pos = SerializePosition(info->column, buffer, buffer_pos);
buffer[buffer_pos++] = '\n';
buffer[buffer_pos++] = '\0';
writer_->AddString(buffer.begin());
Expand Down