a7fa1ae2e1
This is a reland of 93716b9e71
Original change's description:
> [snapshot] Add support for native counters.
>
> Counters in generated code, as enabled with --native-code-counters, do not work
> in the snapshot. This adds a `v8_enable_snapshot_code_counters` build option
> enabled by defaut in debug mode that allows code from the snapshot to increment
> the current isolate's set of counters.
>
> For this to work, we need to add native code counters in the external reference
> table.
>
> To keep the no snapshot configuration similar, we've also enabled the
> --native-code-counters flag by default for debug builds.
>
> Change-Id: I4478b79858c9b04f57e06e7ec67449e9e3a76f53
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1528998
> Commit-Queue: Pierre Langlois <pierre.langlois@arm.com>
> Reviewed-by: Peter Marshall <petermarshall@chromium.org>
> Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#60495}
Change-Id: Ib6427caf068ca196a032e3f3b97d9f9219e0fe60
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1543349
Reviewed-by: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Commit-Queue: Pierre Langlois <pierre.langlois@arm.com>
Cr-Commit-Position: refs/heads/master@{#60507}
84 lines
2.6 KiB
C++
84 lines
2.6 KiB
C++
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
#include "include/libplatform/libplatform.h"
|
|
#include "include/v8.h"
|
|
#include "src/api-inl.h"
|
|
#include "src/base/platform/time.h"
|
|
#include "src/flags.h"
|
|
#include "src/isolate.h"
|
|
#include "src/objects-inl.h"
|
|
#include "src/v8.h"
|
|
|
|
namespace v8 {
|
|
|
|
IsolateWrapper::IsolateWrapper(CounterLookupCallback counter_lookup_callback,
|
|
bool enforce_pointer_compression)
|
|
: array_buffer_allocator_(
|
|
v8::ArrayBuffer::Allocator::NewDefaultAllocator()) {
|
|
v8::Isolate::CreateParams create_params;
|
|
create_params.array_buffer_allocator = array_buffer_allocator_;
|
|
create_params.counter_lookup_callback = counter_lookup_callback;
|
|
if (enforce_pointer_compression) {
|
|
isolate_ = reinterpret_cast<v8::Isolate*>(
|
|
i::Isolate::New(i::IsolateAllocationMode::kInV8Heap));
|
|
v8::Isolate::Initialize(isolate_, create_params);
|
|
} else {
|
|
isolate_ = v8::Isolate::New(create_params);
|
|
}
|
|
CHECK_NOT_NULL(isolate_);
|
|
}
|
|
|
|
IsolateWrapper::~IsolateWrapper() {
|
|
v8::Platform* platform = internal::V8::GetCurrentPlatform();
|
|
CHECK_NOT_NULL(platform);
|
|
while (platform::PumpMessageLoop(platform, isolate_)) continue;
|
|
isolate_->Dispose();
|
|
delete array_buffer_allocator_;
|
|
}
|
|
|
|
// static
|
|
v8::IsolateWrapper* SharedIsolateHolder::isolate_wrapper_ = nullptr;
|
|
|
|
// static
|
|
int* SharedIsolateAndCountersHolder::LookupCounter(const char* name) {
|
|
DCHECK_NOT_NULL(counter_map_);
|
|
auto map_entry = counter_map_->find(name);
|
|
if (map_entry == counter_map_->end()) {
|
|
counter_map_->emplace(name, 0);
|
|
}
|
|
return &counter_map_->at(name);
|
|
}
|
|
|
|
// static
|
|
v8::IsolateWrapper* SharedIsolateAndCountersHolder::isolate_wrapper_ = nullptr;
|
|
|
|
// static
|
|
CounterMap* SharedIsolateAndCountersHolder::counter_map_ = nullptr;
|
|
|
|
namespace internal {
|
|
|
|
SaveFlags::SaveFlags() {
|
|
// For each flag, save the current flag value.
|
|
#define FLAG_MODE_APPLY(ftype, ctype, nam, def, cmt) SAVED_##nam = FLAG_##nam;
|
|
#include "src/flag-definitions.h" // NOLINT
|
|
#undef FLAG_MODE_APPLY
|
|
}
|
|
|
|
SaveFlags::~SaveFlags() {
|
|
// For each flag, set back the old flag value if it changed (don't write the
|
|
// flag if it didn't change, to keep TSAN happy).
|
|
#define FLAG_MODE_APPLY(ftype, ctype, nam, def, cmt) \
|
|
if (SAVED_##nam != FLAG_##nam) { \
|
|
FLAG_##nam = SAVED_##nam; \
|
|
}
|
|
#include "src/flag-definitions.h" // NOLINT
|
|
#undef FLAG_MODE_APPLY
|
|
}
|
|
|
|
} // namespace internal
|
|
} // namespace v8
|