Line data Source code
1 : // Copyright 2014 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "test/unittests/test-utils.h"
6 :
7 : #include "include/libplatform/libplatform.h"
8 : #include "include/v8.h"
9 : #include "src/api-inl.h"
10 : #include "src/base/platform/time.h"
11 : #include "src/flags.h"
12 : #include "src/isolate.h"
13 : #include "src/objects-inl.h"
14 : #include "src/v8.h"
15 :
16 : namespace v8 {
17 :
18 1271 : IsolateWrapper::IsolateWrapper(CounterLookupCallback counter_lookup_callback,
19 : bool enforce_pointer_compression)
20 : : array_buffer_allocator_(
21 1271 : v8::ArrayBuffer::Allocator::NewDefaultAllocator()) {
22 : v8::Isolate::CreateParams create_params;
23 1271 : create_params.array_buffer_allocator = array_buffer_allocator_;
24 1271 : create_params.counter_lookup_callback = counter_lookup_callback;
25 1271 : if (enforce_pointer_compression) {
26 : isolate_ = reinterpret_cast<v8::Isolate*>(
27 1 : i::Isolate::New(i::IsolateAllocationMode::kInV8Heap));
28 1 : v8::Isolate::Initialize(isolate_, create_params);
29 : } else {
30 1270 : isolate_ = v8::Isolate::New(create_params);
31 : }
32 1271 : CHECK_NOT_NULL(isolate_);
33 1271 : }
34 :
35 2542 : IsolateWrapper::~IsolateWrapper() {
36 1271 : v8::Platform* platform = internal::V8::GetCurrentPlatform();
37 1271 : CHECK_NOT_NULL(platform);
38 1275 : while (platform::PumpMessageLoop(platform, isolate_)) continue;
39 1271 : isolate_->Dispose();
40 1271 : delete array_buffer_allocator_;
41 1271 : }
42 :
43 : // static
44 : v8::IsolateWrapper* SharedIsolateHolder::isolate_wrapper_ = nullptr;
45 :
46 : // static
47 78 : int* SharedIsolateAndCountersHolder::LookupCounter(const char* name) {
48 : DCHECK_NOT_NULL(counter_map_);
49 156 : auto map_entry = counter_map_->find(name);
50 156 : if (map_entry == counter_map_->end()) {
51 156 : counter_map_->emplace(name, 0);
52 : }
53 156 : return &counter_map_->at(name);
54 : }
55 :
56 : // static
57 : v8::IsolateWrapper* SharedIsolateAndCountersHolder::isolate_wrapper_ = nullptr;
58 :
59 : // static
60 : CounterMap* SharedIsolateAndCountersHolder::counter_map_ = nullptr;
61 :
62 : namespace internal {
63 :
64 45 : SaveFlags::SaveFlags() {
65 : // For each flag, save the current flag value.
66 : #define FLAG_MODE_APPLY(ftype, ctype, nam, def, cmt) SAVED_##nam = FLAG_##nam;
67 : #include "src/flag-definitions.h" // NOLINT
68 : #undef FLAG_MODE_APPLY
69 45 : }
70 :
71 90 : SaveFlags::~SaveFlags() {
72 : // For each flag, set back the old flag value if it changed (don't write the
73 : // flag if it didn't change, to keep TSAN happy).
74 : #define FLAG_MODE_APPLY(ftype, ctype, nam, def, cmt) \
75 : if (SAVED_##nam != FLAG_##nam) { \
76 : FLAG_##nam = SAVED_##nam; \
77 : }
78 : #include "src/flag-definitions.h" // NOLINT
79 : #undef FLAG_MODE_APPLY
80 45 : }
81 :
82 : } // namespace internal
83 6176 : } // namespace v8
|