1 // Copyright 2020 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 "src/execution/local-isolate.h"
6
7 #include "src/bigint/bigint.h"
8 #include "src/execution/isolate.h"
9 #include "src/execution/thread-id.h"
10 #include "src/handles/handles-inl.h"
11 #include "src/logging/local-logger.h"
12 #include "src/logging/runtime-call-stats-scope.h"
13
14 namespace v8 {
15 namespace internal {
16
LocalIsolate(Isolate* isolate, ThreadKind kind)17 LocalIsolate::LocalIsolate(Isolate* isolate, ThreadKind kind)
18 : HiddenLocalFactory(isolate),
19 heap_(isolate->heap(), kind),
20 isolate_(isolate),
21 logger_(new LocalLogger(isolate)),
22 thread_id_(ThreadId::Current()),
23 stack_limit_(kind == ThreadKind::kMain
24 ? isolate->stack_guard()->real_climit()
25 : GetCurrentStackPosition() - FLAG_stack_size * KB)
26 #ifdef V8_INTL_SUPPORT
27 ,
28 default_locale_(isolate->DefaultLocale())
29 #endif
30 {
31 #ifdef V8_RUNTIME_CALL_STATS
32 if (kind == ThreadKind::kMain) {
33 runtime_call_stats_ = isolate->counters()->runtime_call_stats();
34 } else {
35 rcs_scope_.emplace(isolate->counters()->worker_thread_runtime_call_stats());
36 runtime_call_stats_ = rcs_scope_->Get();
37 }
38 #endif
39 }
40
~LocalIsolate()41 LocalIsolate::~LocalIsolate() {
42 if (bigint_processor_) bigint_processor_->Destroy();
43 }
44
RegisterDeserializerStarted()45 void LocalIsolate::RegisterDeserializerStarted() {
46 return isolate_->RegisterDeserializerStarted();
47 }
RegisterDeserializerFinished()48 void LocalIsolate::RegisterDeserializerFinished() {
49 return isolate_->RegisterDeserializerFinished();
50 }
51
GetNextScriptId()52 int LocalIsolate::GetNextScriptId() { return isolate_->GetNextScriptId(); }
53
54 #if V8_SFI_HAS_UNIQUE_ID
GetNextUniqueSharedFunctionInfoId()55 int LocalIsolate::GetNextUniqueSharedFunctionInfoId() {
56 return isolate_->GetNextUniqueSharedFunctionInfoId();
57 }
58 #endif // V8_SFI_HAS_UNIQUE_ID
59
is_collecting_type_profile() const60 bool LocalIsolate::is_collecting_type_profile() const {
61 // TODO(leszeks): Figure out if it makes sense to check this asynchronously.
62 return isolate_->is_collecting_type_profile();
63 }
64
65 // Used for lazy initialization, based on an assumption that most
66 // LocalIsolates won't be used to parse any BigInt literals.
InitializeBigIntProcessor()67 void LocalIsolate::InitializeBigIntProcessor() {
68 bigint_processor_ = bigint::Processor::New(new bigint::Platform());
69 }
70
71 // static
HasOverflowed(LocalIsolate* local_isolate)72 bool StackLimitCheck::HasOverflowed(LocalIsolate* local_isolate) {
73 return GetCurrentStackPosition() < local_isolate->stack_limit();
74 }
75
76 #ifdef V8_INTL_SUPPORT
77 // WARNING: This might be out-of-sync with the main-thread.
DefaultLocale()78 const std::string& LocalIsolate::DefaultLocale() {
79 const std::string& res =
80 is_main_thread() ? isolate_->DefaultLocale() : default_locale_;
81 DCHECK(!res.empty());
82 return res;
83 }
84 #endif
85
86 } // namespace internal
87 } // namespace v8
88