2014-09-04 08:44:03 +00:00
|
|
|
// 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.
|
|
|
|
|
2014-10-01 08:34:25 +00:00
|
|
|
#include "test/unittests/test-utils.h"
|
2014-09-04 08:44:03 +00:00
|
|
|
|
2015-07-15 12:26:06 +00:00
|
|
|
#include "include/libplatform/libplatform.h"
|
2021-08-23 13:01:06 +00:00
|
|
|
#include "include/v8-isolate.h"
|
2019-05-17 12:13:44 +00:00
|
|
|
#include "src/api/api-inl.h"
|
2014-10-06 12:27:24 +00:00
|
|
|
#include "src/base/platform/time.h"
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/execution/isolate.h"
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/flags/flags.h"
|
2022-12-19 23:16:30 +00:00
|
|
|
#include "src/heap/cppgc-js/cpp-heap.h"
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/init/v8.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2022-12-19 23:16:30 +00:00
|
|
|
#include "test/unittests/heap/heap-utils.h"
|
2014-09-04 08:44:03 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
|
2020-04-14 08:56:19 +00:00
|
|
|
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
|
|
|
|
|
2022-08-26 22:07:04 +00:00
|
|
|
IsolateWrapper::IsolateWrapper(CountersMode counters_mode)
|
2018-10-29 20:49:54 +00:00
|
|
|
: array_buffer_allocator_(
|
|
|
|
v8::ArrayBuffer::Allocator::NewDefaultAllocator()) {
|
2020-04-14 08:56:19 +00:00
|
|
|
CHECK_NULL(kCurrentCounterMap);
|
|
|
|
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
2020-04-14 08:56:19 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-26 22:07:04 +00:00
|
|
|
isolate_ = v8::Isolate::New(create_params);
|
2020-04-14 08:56:19 +00:00
|
|
|
CHECK_NOT_NULL(isolate());
|
2014-09-04 08:44:03 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 20:49:54 +00:00
|
|
|
IsolateWrapper::~IsolateWrapper() {
|
2015-07-15 12:26:06 +00:00
|
|
|
v8::Platform* platform = internal::V8::GetCurrentPlatform();
|
2018-10-29 20:49:54 +00:00
|
|
|
CHECK_NOT_NULL(platform);
|
2022-11-14 10:46:08 +00:00
|
|
|
isolate_->Enter();
|
2020-04-14 08:56:19 +00:00
|
|
|
while (platform::PumpMessageLoop(platform, isolate())) continue;
|
2022-11-14 10:46:08 +00:00
|
|
|
isolate_->Exit();
|
2014-09-04 08:44:03 +00:00
|
|
|
isolate_->Dispose();
|
2020-04-14 08:56:19 +00:00
|
|
|
if (counter_map_) {
|
|
|
|
CHECK_EQ(kCurrentCounterMap, counter_map_.get());
|
|
|
|
kCurrentCounterMap = nullptr;
|
|
|
|
} else {
|
|
|
|
CHECK_NULL(kCurrentCounterMap);
|
2019-03-28 12:37:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
namespace internal {
|
|
|
|
|
2019-03-19 14:57:50 +00:00
|
|
|
SaveFlags::SaveFlags() {
|
|
|
|
// For each flag, save the current flag value.
|
2022-06-03 08:35:58 +00:00
|
|
|
#define FLAG_MODE_APPLY(ftype, ctype, nam, def, cmt) \
|
2022-09-15 16:52:15 +00:00
|
|
|
SAVED_##nam = v8_flags.nam.value();
|
2021-04-29 16:54:13 +00:00
|
|
|
#include "src/flags/flag-definitions.h"
|
2019-03-19 14:57:50 +00:00
|
|
|
#undef FLAG_MODE_APPLY
|
|
|
|
}
|
2017-03-14 13:33:13 +00:00
|
|
|
|
|
|
|
SaveFlags::~SaveFlags() {
|
2019-03-19 14:57:50 +00:00
|
|
|
// 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) \
|
2022-09-15 16:52:15 +00:00
|
|
|
if (SAVED_##nam != v8_flags.nam.value()) { \
|
|
|
|
v8_flags.nam = SAVED_##nam; \
|
2017-03-14 13:33:13 +00:00
|
|
|
}
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/flags/flag-definitions.h" // NOLINT
|
2019-03-19 14:57:50 +00:00
|
|
|
#undef FLAG_MODE_APPLY
|
2017-03-14 13:33:13 +00:00
|
|
|
}
|
|
|
|
|
2022-04-07 17:40:52 +00:00
|
|
|
ManualGCScope::ManualGCScope(i::Isolate* isolate) {
|
|
|
|
// Some tests run threaded (back-to-back) and thus the GC may already be
|
|
|
|
// running by the time a ManualGCScope is created. Finalizing existing marking
|
|
|
|
// prevents any undefined/unexpected behavior.
|
2022-12-19 23:16:30 +00:00
|
|
|
FinalizeGCIfRunning(isolate);
|
2022-04-07 17:40:52 +00:00
|
|
|
|
2022-09-15 16:52:15 +00:00
|
|
|
i::v8_flags.concurrent_marking = false;
|
|
|
|
i::v8_flags.concurrent_sweeping = false;
|
2022-10-04 08:43:52 +00:00
|
|
|
i::v8_flags.concurrent_minor_mc_marking = false;
|
2022-09-15 16:52:15 +00:00
|
|
|
i::v8_flags.stress_incremental_marking = false;
|
|
|
|
i::v8_flags.stress_concurrent_allocation = false;
|
2022-04-07 17:40:52 +00:00
|
|
|
// Parallel marking has a dependency on concurrent marking.
|
2022-09-15 16:52:15 +00:00
|
|
|
i::v8_flags.parallel_marking = false;
|
|
|
|
i::v8_flags.detect_ineffective_gcs_near_heap_limit = false;
|
2022-12-19 23:16:30 +00:00
|
|
|
// CppHeap concurrent marking has a dependency on concurrent marking.
|
|
|
|
i::v8_flags.cppheap_concurrent_marking = false;
|
|
|
|
|
|
|
|
if (isolate && isolate->heap()->cpp_heap()) {
|
|
|
|
CppHeap::From(isolate->heap()->cpp_heap())
|
|
|
|
->ReduceGCCapabilitiesFromFlagsForTesting();
|
|
|
|
}
|
2022-04-07 17:40:52 +00:00
|
|
|
}
|
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|