Skip to content

Commit

Permalink
deps: V8: backport 14ac02c from upstream
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ofrobots authored and gibfahn committed Dec 19, 2017
1 parent ba73a67 commit f34ee5c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion deps/v8/include/v8-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define V8_MAJOR_VERSION 6
#define V8_MINOR_VERSION 1
#define V8_BUILD_NUMBER 534
#define V8_PATCH_LEVEL 48
#define V8_PATCH_LEVEL 49

// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Expand Down
29 changes: 15 additions & 14 deletions deps/v8/src/profiler/profiler-listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

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

ProfilerListener::~ProfilerListener() {
for (auto code_entry : code_entries_) {
delete code_entry;
}
}
ProfilerListener::~ProfilerListener() = default;

void ProfilerListener::CallbackEvent(Name* name, Address entry_point) {
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
Expand Down Expand Up @@ -286,19 +283,23 @@ CodeEntry* ProfilerListener::NewCodeEntry(
CodeEventListener::LogEventsAndTags tag, const char* name,
const char* name_prefix, const char* resource_name, int line_number,
int column_number, JITLineInfoTable* line_info, Address instruction_start) {
CodeEntry* code_entry =
new CodeEntry(tag, name, name_prefix, resource_name, line_number,
column_number, line_info, instruction_start);
code_entries_.push_back(code_entry);
return code_entry;
std::unique_ptr<CodeEntry> code_entry = base::make_unique<CodeEntry>(
tag, name, name_prefix, resource_name, line_number, column_number,
line_info, instruction_start);
CodeEntry* raw_code_entry = code_entry.get();
code_entries_.push_back(std::move(code_entry));
return raw_code_entry;
}

void ProfilerListener::AddObserver(CodeEventObserver* observer) {
base::LockGuard<base::Mutex> guard(&mutex_);
if (std::find(observers_.begin(), observers_.end(), observer) !=
observers_.end())
return;
observers_.push_back(observer);
if (observers_.empty()) {
code_entries_.clear();
}
if (std::find(observers_.begin(), observers_.end(), observer) ==
observers_.end()) {
observers_.push_back(observer);
}
}

void ProfilerListener::RemoveObserver(CodeEventObserver* observer) {
Expand Down
3 changes: 2 additions & 1 deletion deps/v8/src/profiler/profiler-listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class ProfilerListener : public CodeEventListener {
const char* GetFunctionName(const char* name) {
return function_and_resource_names_.GetFunctionName(name);
}
size_t entries_count_for_test() const { return code_entries_.size(); }

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

StringsStorage function_and_resource_names_;
std::vector<CodeEntry*> code_entries_;
std::vector<std::unique_ptr<CodeEntry>> code_entries_;
std::vector<CodeEventObserver*> observers_;
base::Mutex mutex_;

Expand Down
28 changes: 28 additions & 0 deletions deps/v8/test/cctest/test-cpu-profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2192,3 +2192,31 @@ TEST(TracingCpuProfiler) {

i::V8::SetPlatformForTesting(old_platform);
}

TEST(CodeEntriesMemoryLeak) {
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
v8::Context::Scope context_scope(env);

std::string source = "function start() {}\n";
for (int i = 0; i < 1000; ++i) {
source += "function foo" + std::to_string(i) + "() { return " +
std::to_string(i) +
"; }\n"
"foo" +
std::to_string(i) + "();\n";
}
CompileRun(source.c_str());
v8::Local<v8::Function> function = GetFunction(env, "start");

ProfilerHelper helper(env);

for (int j = 0; j < 100; ++j) {
v8::CpuProfile* profile = helper.Run(function, nullptr, 0);
profile->Delete();
}
ProfilerListener* profiler_listener =
CcTest::i_isolate()->logger()->profiler_listener();

CHECK_GE(10000ul, profiler_listener->entries_count_for_test());
}

0 comments on commit f34ee5c

Please sign in to comment.