v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
simulator-base.cc
Go to the documentation of this file.
1// Copyright 2017 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
6
9
10#if defined(USE_SIMULATOR)
11
12namespace v8 {
13namespace internal {
14
15// static
16base::Mutex* SimulatorBase::redirection_mutex_ = nullptr;
17
18// static
19Redirection* SimulatorBase::redirection_ = nullptr;
20
21// static
22base::Mutex* SimulatorBase::i_cache_mutex_ = nullptr;
23
24// static
25base::CustomMatcherHashMap* SimulatorBase::i_cache_ = nullptr;
26
27// static
28void SimulatorBase::InitializeOncePerProcess() {
29 DCHECK_NULL(redirection_mutex_);
30 redirection_mutex_ = new base::Mutex();
31
32 DCHECK_NULL(i_cache_mutex_);
33 i_cache_mutex_ = new base::Mutex();
34
35 DCHECK_NULL(i_cache_);
36 i_cache_ = new base::CustomMatcherHashMap(&Simulator::ICacheMatch);
37}
38
39// static
40void SimulatorBase::GlobalTearDown() {
41 delete redirection_mutex_;
42 redirection_mutex_ = nullptr;
43
44 Redirection::DeleteChain(redirection_);
45 redirection_ = nullptr;
46
47 delete i_cache_mutex_;
48 i_cache_mutex_ = nullptr;
49
50 if (i_cache_ != nullptr) {
51 for (base::HashMap::Entry* entry = i_cache_->Start(); entry != nullptr;
52 entry = i_cache_->Next(entry)) {
53 delete static_cast<CachePage*>(entry->value);
54 }
55 }
56 delete i_cache_;
57 i_cache_ = nullptr;
58}
59
60// static
61Address SimulatorBase::RedirectExternalReference(Address external_function,
63 base::MutexGuard lock_guard(Simulator::redirection_mutex());
64 Redirection* redirection = Redirection::Get(external_function, type);
65 return redirection->address_of_instruction();
66}
67
68// static
69Address SimulatorBase::UnwrapRedirection(Address redirection_trampoline) {
70 return reinterpret_cast<Address>(
71 Redirection::UnwrapRedirection(redirection_trampoline));
72}
73
74Redirection::Redirection(Address external_function,
76 : external_function_(external_function), type_(type), next_(nullptr) {
77 next_ = Simulator::redirection();
78 base::MutexGuard lock_guard(Simulator::i_cache_mutex());
79 Simulator::SetRedirectInstruction(
80 reinterpret_cast<Instruction*>(address_of_instruction()));
81 Simulator::FlushICache(Simulator::i_cache(),
82 reinterpret_cast<void*>(&instruction_),
83 sizeof(instruction_));
84 Simulator::set_redirection(this);
85#if ABI_USES_FUNCTION_DESCRIPTORS
86 function_descriptor_[0] = reinterpret_cast<intptr_t>(&instruction_);
87 function_descriptor_[1] = 0;
88 function_descriptor_[2] = 0;
89#endif
90}
91
92// static
93Redirection* Redirection::Get(Address external_function,
94 ExternalReference::Type type) {
95 Redirection* current = Simulator::redirection();
96 for (; current != nullptr; current = current->next_) {
97 if (current->external_function_ == external_function &&
98 current->type_ == type) {
99 return current;
100 }
101 }
102 return new Redirection(external_function, type);
103}
104
105void SimulatorData::RegisterFunctionsAndSignatures(
106 Address* c_functions, const CFunctionInfo* const* c_signatures,
107 unsigned num_functions) {
108 base::MutexGuard guard(&signature_map_mutex_);
109 for (unsigned i = 0; i < num_functions; ++i) {
110 EncodedCSignature sig(c_signatures[i]);
111 AddSignatureForTarget(c_functions[i], sig);
112 }
113}
114
115const EncodedCSignature& SimulatorData::GetSignatureForTarget(Address target) {
116 base::MutexGuard guard(&signature_map_mutex_);
117 auto entry = target_to_signature_table_.find(target);
118 if (entry != target_to_signature_table_.end()) {
119 const EncodedCSignature& sig = entry->second;
120 return sig;
121 }
122 return EncodedCSignature::Invalid();
123}
124
125} // namespace internal
126} // namespace v8
127
128#endif // defined(USE_SIMULATOR)
const ObjectRef type_
LineAndColumn current
CustomMatcherTemplateHashMapImpl< DefaultAllocationPolicy > CustomMatcherHashMap
Definition hashmap.h:480
LockGuard< Mutex > MutexGuard
Definition mutex.h:219
kWasmInternalFunctionIndirectPointerTag kProtectedInstanceDataOffset sig
#define DCHECK_NULL(val)
Definition logging.h:491