Skip to content

Commit f34ee5c

Browse files
ofrobotsgibfahn
authored andcommitted
deps: V8: backport 14ac02c from upstream
This is the V8 6.1 specific backport for Node 8.x. Original commit message: [cpu-profiler] Clear code entries when no observers are present. Performed manual testing as well by making 20 CPU profile recordings of loading http://meduza.io page. Without the patch the page renderer memory size grows beyond 300MB. With the patch it remains below 200MB. BUG=v8:6623 Change-Id: Ifce541b84bb2aaaa5175520f8dd49dbc0cb5dd20 Reviewed-on: https://chromium-review.googlesource.com/798020 Commit-Queue: Alexei Filippov <[email protected]> Reviewed-by: Yang Guo <[email protected]> Cr-Commit-Position: refs/heads/master@{#49914} Ref: v8/v8@14ac02c PR-URL: #17512 Backport-PR-URL: #17659 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent ba73a67 commit f34ee5c

File tree

4 files changed

+46
-16
lines changed

4 files changed

+46
-16
lines changed

deps/v8/include/v8-version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define V8_MAJOR_VERSION 6
1212
#define V8_MINOR_VERSION 1
1313
#define V8_BUILD_NUMBER 534
14-
#define V8_PATCH_LEVEL 48
14+
#define V8_PATCH_LEVEL 49
1515

1616
// Use 1 for candidates and 0 otherwise.
1717
// (Boolean macro values are not supported by all preprocessors.)

deps/v8/src/profiler/profiler-listener.cc

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "src/profiler/profiler-listener.h"
66

7+
#include "src/base/template-utils.h"
78
#include "src/deoptimizer.h"
89
#include "src/objects-inl.h"
910
#include "src/profiler/cpu-profiler.h"
@@ -16,11 +17,7 @@ namespace internal {
1617
ProfilerListener::ProfilerListener(Isolate* isolate)
1718
: function_and_resource_names_(isolate->heap()) {}
1819

19-
ProfilerListener::~ProfilerListener() {
20-
for (auto code_entry : code_entries_) {
21-
delete code_entry;
22-
}
23-
}
20+
ProfilerListener::~ProfilerListener() = default;
2421

2522
void ProfilerListener::CallbackEvent(Name* name, Address entry_point) {
2623
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
@@ -286,19 +283,23 @@ CodeEntry* ProfilerListener::NewCodeEntry(
286283
CodeEventListener::LogEventsAndTags tag, const char* name,
287284
const char* name_prefix, const char* resource_name, int line_number,
288285
int column_number, JITLineInfoTable* line_info, Address instruction_start) {
289-
CodeEntry* code_entry =
290-
new CodeEntry(tag, name, name_prefix, resource_name, line_number,
291-
column_number, line_info, instruction_start);
292-
code_entries_.push_back(code_entry);
293-
return code_entry;
286+
std::unique_ptr<CodeEntry> code_entry = base::make_unique<CodeEntry>(
287+
tag, name, name_prefix, resource_name, line_number, column_number,
288+
line_info, instruction_start);
289+
CodeEntry* raw_code_entry = code_entry.get();
290+
code_entries_.push_back(std::move(code_entry));
291+
return raw_code_entry;
294292
}
295293

296294
void ProfilerListener::AddObserver(CodeEventObserver* observer) {
297295
base::LockGuard<base::Mutex> guard(&mutex_);
298-
if (std::find(observers_.begin(), observers_.end(), observer) !=
299-
observers_.end())
300-
return;
301-
observers_.push_back(observer);
296+
if (observers_.empty()) {
297+
code_entries_.clear();
298+
}
299+
if (std::find(observers_.begin(), observers_.end(), observer) ==
300+
observers_.end()) {
301+
observers_.push_back(observer);
302+
}
302303
}
303304

304305
void ProfilerListener::RemoveObserver(CodeEventObserver* observer) {

deps/v8/src/profiler/profiler-listener.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class ProfilerListener : public CodeEventListener {
7474
const char* GetFunctionName(const char* name) {
7575
return function_and_resource_names_.GetFunctionName(name);
7676
}
77+
size_t entries_count_for_test() const { return code_entries_.size(); }
7778

7879
private:
7980
void RecordInliningInfo(CodeEntry* entry, AbstractCode* abstract_code);
@@ -87,7 +88,7 @@ class ProfilerListener : public CodeEventListener {
8788
}
8889

8990
StringsStorage function_and_resource_names_;
90-
std::vector<CodeEntry*> code_entries_;
91+
std::vector<std::unique_ptr<CodeEntry>> code_entries_;
9192
std::vector<CodeEventObserver*> observers_;
9293
base::Mutex mutex_;
9394

deps/v8/test/cctest/test-cpu-profiler.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,3 +2192,31 @@ TEST(TracingCpuProfiler) {
21922192

21932193
i::V8::SetPlatformForTesting(old_platform);
21942194
}
2195+
2196+
TEST(CodeEntriesMemoryLeak) {
2197+
v8::HandleScope scope(CcTest::isolate());
2198+
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
2199+
v8::Context::Scope context_scope(env);
2200+
2201+
std::string source = "function start() {}\n";
2202+
for (int i = 0; i < 1000; ++i) {
2203+
source += "function foo" + std::to_string(i) + "() { return " +
2204+
std::to_string(i) +
2205+
"; }\n"
2206+
"foo" +
2207+
std::to_string(i) + "();\n";
2208+
}
2209+
CompileRun(source.c_str());
2210+
v8::Local<v8::Function> function = GetFunction(env, "start");
2211+
2212+
ProfilerHelper helper(env);
2213+
2214+
for (int j = 0; j < 100; ++j) {
2215+
v8::CpuProfile* profile = helper.Run(function, nullptr, 0);
2216+
profile->Delete();
2217+
}
2218+
ProfilerListener* profiler_listener =
2219+
CcTest::i_isolate()->logger()->profiler_listener();
2220+
2221+
CHECK_GE(10000ul, profiler_listener->entries_count_for_test());
2222+
}

0 commit comments

Comments
 (0)