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"
|
2017-11-13 12:04:57 +00:00
|
|
|
#include "include/v8.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"
|
2014-10-06 12:27:24 +00:00
|
|
|
#include "src/flags.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2015-07-15 12:26:06 +00:00
|
|
|
#include "src/v8.h"
|
2014-09-04 08:44:03 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
|
2019-03-28 12:37:29 +00:00
|
|
|
IsolateWrapper::IsolateWrapper(CounterLookupCallback counter_lookup_callback,
|
|
|
|
bool enforce_pointer_compression)
|
2018-10-29 20:49:54 +00:00
|
|
|
: array_buffer_allocator_(
|
|
|
|
v8::ArrayBuffer::Allocator::NewDefaultAllocator()) {
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = array_buffer_allocator_;
|
2019-03-28 12:37:29 +00:00
|
|
|
create_params.counter_lookup_callback = counter_lookup_callback;
|
2018-10-30 12:48:12 +00:00
|
|
|
if (enforce_pointer_compression) {
|
|
|
|
isolate_ = reinterpret_cast<v8::Isolate*>(
|
2018-11-07 09:05:38 +00:00
|
|
|
i::Isolate::New(i::IsolateAllocationMode::kInV8Heap));
|
2018-10-30 12:48:12 +00:00
|
|
|
v8::Isolate::Initialize(isolate_, create_params);
|
|
|
|
} else {
|
|
|
|
isolate_ = v8::Isolate::New(create_params);
|
|
|
|
}
|
2018-10-29 20:49:54 +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);
|
2015-07-15 12:26:06 +00:00
|
|
|
while (platform::PumpMessageLoop(platform, isolate_)) continue;
|
2014-09-04 08:44:03 +00:00
|
|
|
isolate_->Dispose();
|
2015-04-29 09:54:34 +00:00
|
|
|
delete array_buffer_allocator_;
|
2018-08-13 15:35:29 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 20:49:54 +00:00
|
|
|
// static
|
|
|
|
v8::IsolateWrapper* SharedIsolateHolder::isolate_wrapper_ = nullptr;
|
2017-11-14 09:15:41 +00:00
|
|
|
|
2019-03-28 12:37:29 +00:00
|
|
|
// 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;
|
|
|
|
|
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.
|
|
|
|
#define FLAG_MODE_APPLY(ftype, ctype, nam, def, cmt) SAVED_##nam = FLAG_##nam;
|
|
|
|
#include "src/flag-definitions.h" // NOLINT
|
|
|
|
#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) \
|
|
|
|
if (SAVED_##nam != FLAG_##nam) { \
|
|
|
|
FLAG_##nam = SAVED_##nam; \
|
2017-03-14 13:33:13 +00:00
|
|
|
}
|
2019-03-19 14:57:50 +00:00
|
|
|
#include "src/flag-definitions.h" // NOLINT
|
|
|
|
#undef FLAG_MODE_APPLY
|
2017-03-14 13:33:13 +00:00
|
|
|
}
|
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|