Commit 0c2530ff authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[test] Create one Isolate per unit test (not test suite)

Change the unittests Isolate mixin to create one Isolate per test,
rather than one per test suite. We usually run these tests independently
in separate processes anyway, so this shouldn't affect normal test
execution, but it will avoid Isolate state leaking across tests when
running the unittests binary directly.

Take this opportunity to also clean up the mixins, changing counter
initialization and forcing pointer compression into template traits.

Bug: v8:10142
Change-Id: If92046f9c6f2056252d099faed04d97844ef7319
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2143818Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67110}
parent e8393612
......@@ -65,7 +65,7 @@ using TestWithNativeContextAndFinalizationRegistry = //
WithContextMixin< //
WithFinalizationRegistryMixin< //
WithIsolateScopeMixin< //
WithSharedIsolateMixin< //
WithIsolateMixin< //
::testing::Test>>>>>;
namespace {
......
......@@ -15,15 +15,7 @@
namespace v8 {
namespace internal {
class SpacesTest : public TestWithIsolate {
protected:
void TearDown() final {
// Clean up the heap between tests.
i_isolate()->heap()->CollectAllAvailableGarbage(
GarbageCollectionReason::kTesting);
TestWithIsolate::TearDown();
}
};
using SpacesTest = TestWithIsolate;
TEST_F(SpacesTest, CompactionSpaceMerge) {
Heap* heap = i_isolate()->heap();
......
......@@ -15,50 +15,61 @@
namespace v8 {
IsolateWrapper::IsolateWrapper(CounterLookupCallback counter_lookup_callback,
bool enforce_pointer_compression)
namespace {
// counter_lookup_callback doesn't pass through any state information about
// the current Isolate, so we have to store the current counter map somewhere.
// Fortunately tests run serially, so we can just store it in a static global.
CounterMap* kCurrentCounterMap = nullptr;
} // namespace
IsolateWrapper::IsolateWrapper(CountersMode counters_mode,
PointerCompressionMode pointer_compression_mode)
: array_buffer_allocator_(
v8::ArrayBuffer::Allocator::NewDefaultAllocator()) {
CHECK_NULL(kCurrentCounterMap);
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) {
create_params.array_buffer_allocator = array_buffer_allocator_.get();
if (counters_mode == kEnableCounters) {
counter_map_ = std::make_unique<CounterMap>();
kCurrentCounterMap = counter_map_.get();
create_params.counter_lookup_callback = [](const char* name) {
CHECK_NOT_NULL(kCurrentCounterMap);
// If the name doesn't exist in the counter map, operator[] will default
// initialize it to zero.
return &(*kCurrentCounterMap)[name];
};
} else {
create_params.counter_lookup_callback = [](const char* name) -> int* {
return nullptr;
};
}
if (pointer_compression_mode == kEnforcePointerCompression) {
isolate_ = reinterpret_cast<v8::Isolate*>(
i::Isolate::New(i::IsolateAllocationMode::kInV8Heap));
v8::Isolate::Initialize(isolate_, create_params);
v8::Isolate::Initialize(isolate(), create_params);
} else {
isolate_ = v8::Isolate::New(create_params);
}
CHECK_NOT_NULL(isolate_);
CHECK_NOT_NULL(isolate());
}
IsolateWrapper::~IsolateWrapper() {
v8::Platform* platform = internal::V8::GetCurrentPlatform();
CHECK_NOT_NULL(platform);
while (platform::PumpMessageLoop(platform, isolate_)) continue;
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);
if (counter_map_) {
CHECK_EQ(kCurrentCounterMap, counter_map_.get());
kCurrentCounterMap = nullptr;
} else {
CHECK_NULL(kCurrentCounterMap);
}
return &counter_map_->at(name);
}
// static
v8::IsolateWrapper* SharedIsolateAndCountersHolder::isolate_wrapper_ = nullptr;
// static
CounterMap* SharedIsolateAndCountersHolder::counter_map_ = nullptr;
namespace internal {
SaveFlags::SaveFlags() {
......
This diff is collapsed.
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