Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v8.x backport] http: do not rely on the 'agentRemove' event #21734

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 2
#define V8_BUILD_NUMBER 414
#define V8_PATCH_LEVEL 60
#define V8_PATCH_LEVEL 61

// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Expand Down
12 changes: 2 additions & 10 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8419,7 +8419,7 @@ HeapProfiler* Isolate::GetHeapProfiler() {

CpuProfiler* Isolate::GetCpuProfiler() {
i::CpuProfiler* cpu_profiler =
reinterpret_cast<i::Isolate*>(this)->cpu_profiler();
reinterpret_cast<i::Isolate*>(this)->EnsureCpuProfiler();
return reinterpret_cast<CpuProfiler*>(cpu_profiler);
}

Expand Down Expand Up @@ -10139,15 +10139,7 @@ Local<String> CpuProfileNode::GetFunctionName() const {
const i::CodeEntry* entry = node->entry();
i::Handle<i::String> name =
isolate->factory()->InternalizeUtf8String(entry->name());
if (!entry->has_name_prefix()) {
return ToApiHandle<String>(name);
} else {
// We do not expect this to fail. Change this if it does.
i::Handle<i::String> cons = isolate->factory()->NewConsString(
isolate->factory()->InternalizeUtf8String(entry->name_prefix()),
name).ToHandleChecked();
return ToApiHandle<String>(cons);
}
return ToApiHandle<String>(name);
}

int debug::Coverage::BlockData::StartOffset() const { return block_->start; }
Expand Down
8 changes: 7 additions & 1 deletion deps/v8/src/isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2689,7 +2689,6 @@ bool Isolate::Init(StartupDeserializer* des) {
call_descriptor_data_ =
new CallInterfaceDescriptorData[CallDescriptors::NUMBER_OF_DESCRIPTORS];
access_compiler_data_ = new AccessCompilerData();
cpu_profiler_ = new CpuProfiler(this);
heap_profiler_ = new HeapProfiler(heap());
interpreter_ = new interpreter::Interpreter(this);
compiler_dispatcher_ =
Expand Down Expand Up @@ -3686,6 +3685,13 @@ void Isolate::PrintWithTimestamp(const char* format, ...) {
va_end(arguments);
}

CpuProfiler* Isolate::EnsureCpuProfiler() {
if (!cpu_profiler_) {
cpu_profiler_ = new CpuProfiler(this);
}
return cpu_profiler_;
}

bool StackLimitCheck::JsHasOverflowed(uintptr_t gap) const {
StackGuard* stack_guard = isolate_->stack_guard();
#ifdef USE_SIMULATOR
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ class Isolate {

// TODO(alph): Remove along with the deprecated GetCpuProfiler().
friend v8::CpuProfiler* v8::Isolate::GetCpuProfiler();
CpuProfiler* cpu_profiler() const { return cpu_profiler_; }
CpuProfiler* EnsureCpuProfiler();

base::Atomic32 id_;
EntryStackItem* entry_stack_;
Expand Down
21 changes: 0 additions & 21 deletions deps/v8/src/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "src/log-utils.h"
#include "src/macro-assembler.h"
#include "src/perf-jit.h"
#include "src/profiler/profiler-listener.h"
#include "src/profiler/tick-sample.h"
#include "src/runtime-profiler.h"
#include "src/source-position-table.h"
Expand Down Expand Up @@ -739,7 +738,6 @@ Logger::Logger(Isolate* isolate)
perf_jit_logger_(NULL),
ll_logger_(NULL),
jit_logger_(NULL),
listeners_(5),
is_initialized_(false) {}

Logger::~Logger() {
Expand Down Expand Up @@ -1876,8 +1874,6 @@ bool Logger::SetUp(Isolate* isolate) {
profiler_->Engage();
}

profiler_listener_.reset();

if (is_logging_) {
addCodeEventListener(this);
}
Expand Down Expand Up @@ -1905,19 +1901,6 @@ void Logger::SetCodeEventHandler(uint32_t options,
}
}

void Logger::SetUpProfilerListener() {
if (!is_initialized_) return;
if (profiler_listener_.get() == nullptr) {
profiler_listener_.reset(new ProfilerListener(isolate_));
}
addCodeEventListener(profiler_listener_.get());
}

void Logger::TearDownProfilerListener() {
if (profiler_listener_->HasObservers()) return;
removeCodeEventListener(profiler_listener_.get());
}

sampler::Sampler* Logger::sampler() {
return ticker_;
}
Expand Down Expand Up @@ -1961,10 +1944,6 @@ FILE* Logger::TearDown() {
jit_logger_ = NULL;
}

if (profiler_listener_.get() != nullptr) {
removeCodeEventListener(profiler_listener_.get());
}

return log_->Close();
}

Expand Down
11 changes: 0 additions & 11 deletions deps/v8/src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class LowLevelLogger;
class PerfBasicLogger;
class PerfJitLogger;
class Profiler;
class ProfilerListener;
class RuntimeCallTimer;
class Ticker;

Expand Down Expand Up @@ -102,16 +101,8 @@ class Logger : public CodeEventListener {
void SetCodeEventHandler(uint32_t options,
JitCodeEventHandler event_handler);

// Sets up ProfilerListener.
void SetUpProfilerListener();

// Tear down ProfilerListener if it has no observers.
void TearDownProfilerListener();

sampler::Sampler* sampler();

ProfilerListener* profiler_listener() { return profiler_listener_.get(); }

// Frees resources acquired in SetUp.
// When a temporary file is used for the log, returns its stream descriptor,
// leaving the file open.
Expand Down Expand Up @@ -316,8 +307,6 @@ class Logger : public CodeEventListener {
PerfJitLogger* perf_jit_logger_;
LowLevelLogger* ll_logger_;
JitLogger* jit_logger_;
std::unique_ptr<ProfilerListener> profiler_listener_;
List<CodeEventListener*> listeners_;
std::set<int> logged_source_code_;
uint32_t next_source_info_id_ = 0;

Expand Down
6 changes: 5 additions & 1 deletion deps/v8/src/profiler/cpu-profiler-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ void CodeDisableOptEventRecord::UpdateCodeMap(CodeMap* code_map) {

void CodeDeoptEventRecord::UpdateCodeMap(CodeMap* code_map) {
CodeEntry* entry = code_map->FindEntry(start);
if (entry != NULL) entry->set_deopt_info(deopt_reason, deopt_id);
if (entry == nullptr) return;
std::vector<CpuProfileDeoptFrame> frames_vector(
deopt_frames, deopt_frames + deopt_frame_count);
entry->set_deopt_info(deopt_reason, deopt_id, std::move(frames_vector));
delete[] deopt_frames;
}


Expand Down
36 changes: 21 additions & 15 deletions deps/v8/src/profiler/cpu-profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

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

#include <unordered_map>
#include <utility>

#include "src/base/lazy-instance.h"
#include "src/base/platform/mutex.h"
#include "src/base/template-utils.h"
#include "src/debug/debug.h"
#include "src/deoptimizer.h"
#include "src/frames-inl.h"
Expand Down Expand Up @@ -275,20 +281,19 @@ void CpuProfiler::set_sampling_interval(base::TimeDelta value) {
void CpuProfiler::ResetProfiles() {
profiles_.reset(new CpuProfilesCollection(isolate_));
profiles_->set_cpu_profiler(this);
profiler_listener_.reset();
generator_.reset();
}

void CpuProfiler::CreateEntriesForRuntimeCallStats() {
static_entries_.clear();
RuntimeCallStats* rcs = isolate_->counters()->runtime_call_stats();
CodeMap* code_map = generator_->code_map();
for (int i = 0; i < RuntimeCallStats::counters_count; ++i) {
RuntimeCallCounter* counter = &(rcs->*(RuntimeCallStats::counters[i]));
DCHECK(counter->name());
std::unique_ptr<CodeEntry> entry(
new CodeEntry(CodeEventListener::FUNCTION_TAG, counter->name(),
CodeEntry::kEmptyNamePrefix, "native V8Runtime"));
code_map->AddCode(reinterpret_cast<Address>(counter), entry.get(), 1);
static_entries_.push_back(std::move(entry));
auto entry = new CodeEntry(CodeEventListener::FUNCTION_TAG, counter->name(),
"native V8Runtime");
code_map->AddCode(reinterpret_cast<Address>(counter), entry, 1);
}
}

Expand Down Expand Up @@ -321,13 +326,17 @@ void CpuProfiler::StartProcessorIfNotStarted() {
// Disable logging when using the new implementation.
saved_is_logging_ = logger->is_logging_;
logger->is_logging_ = false;
generator_.reset(new ProfileGenerator(profiles_.get()));
if (!generator_) {
generator_.reset(new ProfileGenerator(profiles_.get()));
CreateEntriesForRuntimeCallStats();
}
processor_.reset(new ProfilerEventsProcessor(isolate_, generator_.get(),
sampling_interval_));
CreateEntriesForRuntimeCallStats();
logger->SetUpProfilerListener();
ProfilerListener* profiler_listener = logger->profiler_listener();
profiler_listener->AddObserver(this);
if (!profiler_listener_) {
profiler_listener_.reset(new ProfilerListener(isolate_, this));
}
logger->addCodeEventListener(profiler_listener_.get());

is_profiling_ = true;
isolate_->set_is_profiling(true);
// Enumerate stuff we already have in the heap.
Expand Down Expand Up @@ -362,12 +371,9 @@ void CpuProfiler::StopProcessor() {
Logger* logger = isolate_->logger();
is_profiling_ = false;
isolate_->set_is_profiling(false);
ProfilerListener* profiler_listener = logger->profiler_listener();
profiler_listener->RemoveObserver(this);
logger->removeCodeEventListener(profiler_listener_.get());
processor_->StopSynchronously();
logger->TearDownProfilerListener();
processor_.reset();
generator_.reset();
logger->is_logging_ = saved_is_logging_;
}

Expand Down
9 changes: 7 additions & 2 deletions deps/v8/src/profiler/cpu-profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class CodeDeoptEventRecord : public CodeEventRecord {
int deopt_id;
void* pc;
int fp_to_sp_delta;
CpuProfileDeoptFrame* deopt_frames;
int deopt_frame_count;

INLINE(void UpdateCodeMap(CodeMap* code_map));
};
Expand Down Expand Up @@ -214,6 +216,10 @@ class CpuProfiler : public CodeEventObserver {
ProfilerEventsProcessor* processor() const { return processor_.get(); }
Isolate* isolate() const { return isolate_; }

ProfilerListener* profiler_listener_for_test() {
return profiler_listener_.get();
}

private:
void StartProcessorIfNotStarted();
void StopProcessorIfLastProfile(const char* title);
Expand All @@ -227,7 +233,7 @@ class CpuProfiler : public CodeEventObserver {
std::unique_ptr<CpuProfilesCollection> profiles_;
std::unique_ptr<ProfileGenerator> generator_;
std::unique_ptr<ProfilerEventsProcessor> processor_;
std::vector<std::unique_ptr<CodeEntry>> static_entries_;
std::unique_ptr<ProfilerListener> profiler_listener_;
bool saved_is_logging_;
bool is_profiling_;

Expand All @@ -237,5 +243,4 @@ class CpuProfiler : public CodeEventObserver {
} // namespace internal
} // namespace v8


#endif // V8_PROFILER_CPU_PROFILER_H_
4 changes: 2 additions & 2 deletions deps/v8/src/profiler/heap-profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace internal {

HeapProfiler::HeapProfiler(Heap* heap)
: ids_(new HeapObjectsMap(heap)),
names_(new StringsStorage(heap)),
names_(new StringsStorage(heap->HashSeed())),
is_tracking_object_moves_(false),
get_retainer_infos_callback_(nullptr) {}

Expand All @@ -34,7 +34,7 @@ HeapProfiler::~HeapProfiler() {
void HeapProfiler::DeleteAllSnapshots() {
snapshots_.Iterate(DeleteHeapSnapshot);
snapshots_.Clear();
names_.reset(new StringsStorage(heap()));
names_.reset(new StringsStorage(heap()->HashSeed()));
}


Expand Down
23 changes: 12 additions & 11 deletions deps/v8/src/profiler/profile-generator-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,34 @@ namespace v8 {
namespace internal {

CodeEntry::CodeEntry(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)
const char* resource_name, int line_number,
int column_number,
std::unique_ptr<SourcePositionTable> line_info,
Address instruction_start)
: bit_field_(TagField::encode(tag) |
BuiltinIdField::encode(Builtins::builtin_count)),
name_prefix_(name_prefix),
name_(name),
resource_name_(resource_name),
line_number_(line_number),
column_number_(column_number),
script_id_(v8::UnboundScript::kNoScriptId),
position_(0),
bailout_reason_(kEmptyBailoutReason),
deopt_reason_(kNoDeoptReason),
deopt_id_(kNoDeoptimizationId),
line_info_(line_info),
line_info_(std::move(line_info)),
instruction_start_(instruction_start) {}

inline CodeEntry* ProfileGenerator::FindEntry(Address address) {
CodeEntry* entry = code_map_.FindEntry(address);
if (entry) entry->mark_used();
return entry;
}

ProfileNode::ProfileNode(ProfileTree* tree, CodeEntry* entry,
ProfileNode* parent)
: tree_(tree),
entry_(entry),
self_ticks_(0),
children_(CodeEntriesMatch),
parent_(parent),
id_(tree->next_node_id()),
line_ticks_(LineTickMatch) {
id_(tree->next_node_id()) {
tree_->EnqueueNode(this);
}

Expand Down
Loading