Commit ad06f37c authored by Stephan Herhut's avatar Stephan Herhut Committed by Commit Bot

[wasm] Share BasicBlockProfiler instance in process

This is a first step to make basic block profiling work in wasm. More
is needed, including eventually making the profiler thread safe.

Change-Id: Ic216c881a4ab5a633e147e5538bb405c32e687cd
Reviewed-on: https://chromium-review.googlesource.com/1150234
Commit-Queue: Stephan Herhut <herhut@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54728}
parent c3473dcb
......@@ -6,9 +6,20 @@
#include <sstream>
#include "src/base/lazy-instance.h"
namespace v8 {
namespace internal {
namespace {
base::LazyInstance<BasicBlockProfiler>::type kBasicBlockProfiler =
LAZY_INSTANCE_INITIALIZER;
}
BasicBlockProfiler* BasicBlockProfiler::Get() {
return kBasicBlockProfiler.Pointer();
}
BasicBlockProfiler::Data::Data(size_t n_blocks)
: n_blocks_(n_blocks), block_ids_(n_blocks_), counts_(n_blocks_, 0) {}
......
......@@ -53,6 +53,7 @@ class BasicBlockProfiler {
BasicBlockProfiler();
~BasicBlockProfiler();
V8_EXPORT_PRIVATE static BasicBlockProfiler* Get();
Data* NewData(size_t n_blocks);
void ResetCounts();
......
......@@ -53,8 +53,7 @@ BasicBlockProfiler::Data* BasicBlockInstrumentor::Instrument(
// Skip the exit block in profiles, since the register allocator can't handle
// it and entry into it means falling off the end of the function anyway.
size_t n_blocks = static_cast<size_t>(schedule->RpoBlockCount()) - 1;
BasicBlockProfiler::Data* data =
isolate->GetOrCreateBasicBlockProfiler()->NewData(n_blocks);
BasicBlockProfiler::Data* data = BasicBlockProfiler::Get()->NewData(n_blocks);
// Set the function name.
if (info->has_shared_info()) {
std::ostringstream os;
......
......@@ -2087,8 +2087,8 @@ void Shell::WriteLcovData(v8::Isolate* isolate, const char* file) {
void Shell::OnExit(v8::Isolate* isolate) {
// Dump basic block profiling data.
if (i::BasicBlockProfiler* profiler =
reinterpret_cast<i::Isolate*>(isolate)->basic_block_profiler()) {
if (i::FLAG_turbo_profiling) {
i::BasicBlockProfiler* profiler = i::BasicBlockProfiler::Get();
i::StdoutStream{} << *profiler;
}
isolate->Dispose();
......
......@@ -20,7 +20,6 @@
#include "src/base/platform/platform.h"
#include "src/base/sys-info.h"
#include "src/base/utils/random-number-generator.h"
#include "src/basic-block-profiler.h"
#include "src/bootstrapper.h"
#include "src/builtins/constants-table-builder.h"
#include "src/cancelable-task.h"
......@@ -2507,7 +2506,6 @@ Isolate::Isolate()
#endif
is_running_microtasks_(false),
use_counter_callback_(nullptr),
basic_block_profiler_(nullptr),
cancelable_task_manager_(new CancelableTaskManager()),
abort_on_uncaught_exception_callback_(nullptr),
total_regexp_code_generated_(0) {
......@@ -2648,9 +2646,6 @@ void Isolate::Deinit() {
runtime_profiler_ = nullptr;
}
delete basic_block_profiler_;
basic_block_profiler_ = nullptr;
delete heap_profiler_;
heap_profiler_ = nullptr;
......@@ -3987,15 +3982,6 @@ void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) {
}
}
BasicBlockProfiler* Isolate::GetOrCreateBasicBlockProfiler() {
if (basic_block_profiler_ == nullptr) {
basic_block_profiler_ = new BasicBlockProfiler();
}
return basic_block_profiler_;
}
std::string Isolate::GetTurboCfgFileName() {
if (FLAG_trace_turbo_cfg_file == nullptr) {
std::ostringstream os;
......
......@@ -61,7 +61,6 @@ class HeapTester;
class AccessCompilerData;
class AddressToIndexHashMap;
class AstStringConstants;
class BasicBlockProfiler;
class Bootstrapper;
class BuiltinsConstantsTableBuilder;
class CancelableTaskManager;
......@@ -1285,9 +1284,6 @@ class Isolate : private HiddenFactory {
void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback);
void CountUsage(v8::Isolate::UseCounterFeature feature);
BasicBlockProfiler* GetOrCreateBasicBlockProfiler();
BasicBlockProfiler* basic_block_profiler() { return basic_block_profiler_; }
std::string GetTurboCfgFileName();
#if V8_SFI_HAS_UNIQUE_ID
......@@ -1720,7 +1716,6 @@ class Isolate : private HiddenFactory {
bool is_running_microtasks_;
v8::Isolate::UseCounterCallback use_counter_callback_;
BasicBlockProfiler* basic_block_profiler_;
std::vector<Object*> partial_snapshot_cache_;
......
......@@ -18,12 +18,11 @@ class BasicBlockProfilerTest : public RawMachineAssemblerTester<int32_t> {
FLAG_turbo_profiling = true;
}
void ResetCounts() { isolate()->basic_block_profiler()->ResetCounts(); }
void ResetCounts() { BasicBlockProfiler::Get()->ResetCounts(); }
void Expect(size_t size, uint32_t* expected) {
CHECK(isolate()->basic_block_profiler());
const BasicBlockProfiler::DataList* l =
isolate()->basic_block_profiler()->data_list();
BasicBlockProfiler::Get()->data_list();
CHECK_NE(0, static_cast<int>(l->size()));
const BasicBlockProfiler::Data* data = l->back();
CHECK_EQ(static_cast<int>(size), static_cast<int>(data->n_blocks()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment