OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/snapshot/serializer-common.h" | 5 #include "src/snapshot/serializer-common.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/external-reference-table.h" |
8 #include "src/assembler.h" | |
9 #include "src/counters.h" | |
10 #include "src/deoptimizer.h" | |
11 #include "src/ic/stub-cache.h" | 8 #include "src/ic/stub-cache.h" |
12 #include "src/list-inl.h" | 9 #include "src/list-inl.h" |
13 | 10 |
14 namespace v8 { | 11 namespace v8 { |
15 namespace internal { | 12 namespace internal { |
16 | 13 |
17 ExternalReferenceTable* ExternalReferenceTable::instance(Isolate* isolate) { | |
18 ExternalReferenceTable* external_reference_table = | |
19 isolate->external_reference_table(); | |
20 if (external_reference_table == NULL) { | |
21 external_reference_table = new ExternalReferenceTable(isolate); | |
22 isolate->set_external_reference_table(external_reference_table); | |
23 } | |
24 return external_reference_table; | |
25 } | |
26 | |
27 ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) { | |
28 // Miscellaneous | |
29 Add(ExternalReference::roots_array_start(isolate).address(), | |
30 "Heap::roots_array_start()"); | |
31 Add(ExternalReference::address_of_stack_limit(isolate).address(), | |
32 "StackGuard::address_of_jslimit()"); | |
33 Add(ExternalReference::address_of_real_stack_limit(isolate).address(), | |
34 "StackGuard::address_of_real_jslimit()"); | |
35 Add(ExternalReference::new_space_start(isolate).address(), | |
36 "Heap::NewSpaceStart()"); | |
37 Add(ExternalReference::new_space_allocation_limit_address(isolate).address(), | |
38 "Heap::NewSpaceAllocationLimitAddress()"); | |
39 Add(ExternalReference::new_space_allocation_top_address(isolate).address(), | |
40 "Heap::NewSpaceAllocationTopAddress()"); | |
41 Add(ExternalReference::mod_two_doubles_operation(isolate).address(), | |
42 "mod_two_doubles"); | |
43 // Keyed lookup cache. | |
44 Add(ExternalReference::keyed_lookup_cache_keys(isolate).address(), | |
45 "KeyedLookupCache::keys()"); | |
46 Add(ExternalReference::keyed_lookup_cache_field_offsets(isolate).address(), | |
47 "KeyedLookupCache::field_offsets()"); | |
48 Add(ExternalReference::handle_scope_next_address(isolate).address(), | |
49 "HandleScope::next"); | |
50 Add(ExternalReference::handle_scope_limit_address(isolate).address(), | |
51 "HandleScope::limit"); | |
52 Add(ExternalReference::handle_scope_level_address(isolate).address(), | |
53 "HandleScope::level"); | |
54 Add(ExternalReference::new_deoptimizer_function(isolate).address(), | |
55 "Deoptimizer::New()"); | |
56 Add(ExternalReference::compute_output_frames_function(isolate).address(), | |
57 "Deoptimizer::ComputeOutputFrames()"); | |
58 Add(ExternalReference::address_of_min_int().address(), | |
59 "LDoubleConstant::min_int"); | |
60 Add(ExternalReference::address_of_one_half().address(), | |
61 "LDoubleConstant::one_half"); | |
62 Add(ExternalReference::isolate_address(isolate).address(), "isolate"); | |
63 Add(ExternalReference::interpreter_dispatch_table_address(isolate).address(), | |
64 "Interpreter::dispatch_table_address"); | |
65 Add(ExternalReference::address_of_negative_infinity().address(), | |
66 "LDoubleConstant::negative_infinity"); | |
67 Add(ExternalReference::power_double_double_function(isolate).address(), | |
68 "power_double_double_function"); | |
69 Add(ExternalReference::power_double_int_function(isolate).address(), | |
70 "power_double_int_function"); | |
71 Add(ExternalReference::math_log_double_function(isolate).address(), | |
72 "std::log"); | |
73 Add(ExternalReference::store_buffer_top(isolate).address(), | |
74 "store_buffer_top"); | |
75 Add(ExternalReference::address_of_the_hole_nan().address(), "the_hole_nan"); | |
76 Add(ExternalReference::get_date_field_function(isolate).address(), | |
77 "JSDate::GetField"); | |
78 Add(ExternalReference::date_cache_stamp(isolate).address(), | |
79 "date_cache_stamp"); | |
80 Add(ExternalReference::address_of_pending_message_obj(isolate).address(), | |
81 "address_of_pending_message_obj"); | |
82 Add(ExternalReference::get_make_code_young_function(isolate).address(), | |
83 "Code::MakeCodeYoung"); | |
84 Add(ExternalReference::cpu_features().address(), "cpu_features"); | |
85 Add(ExternalReference::old_space_allocation_top_address(isolate).address(), | |
86 "Heap::OldSpaceAllocationTopAddress"); | |
87 Add(ExternalReference::old_space_allocation_limit_address(isolate).address(), | |
88 "Heap::OldSpaceAllocationLimitAddress"); | |
89 Add(ExternalReference::allocation_sites_list_address(isolate).address(), | |
90 "Heap::allocation_sites_list_address()"); | |
91 Add(ExternalReference::address_of_uint32_bias().address(), "uint32_bias"); | |
92 Add(ExternalReference::get_mark_code_as_executed_function(isolate).address(), | |
93 "Code::MarkCodeAsExecuted"); | |
94 Add(ExternalReference::is_profiling_address(isolate).address(), | |
95 "CpuProfiler::is_profiling"); | |
96 Add(ExternalReference::scheduled_exception_address(isolate).address(), | |
97 "Isolate::scheduled_exception"); | |
98 Add(ExternalReference::invoke_function_callback(isolate).address(), | |
99 "InvokeFunctionCallback"); | |
100 Add(ExternalReference::invoke_accessor_getter_callback(isolate).address(), | |
101 "InvokeAccessorGetterCallback"); | |
102 Add(ExternalReference::wasm_f32_trunc(isolate).address(), | |
103 "wasm::f32_trunc_wrapper"); | |
104 Add(ExternalReference::wasm_f32_floor(isolate).address(), | |
105 "wasm::f32_floor_wrapper"); | |
106 Add(ExternalReference::wasm_f32_ceil(isolate).address(), | |
107 "wasm::f32_ceil_wrapper"); | |
108 Add(ExternalReference::wasm_f32_nearest_int(isolate).address(), | |
109 "wasm::f32_nearest_int_wrapper"); | |
110 Add(ExternalReference::wasm_f64_trunc(isolate).address(), | |
111 "wasm::f64_trunc_wrapper"); | |
112 Add(ExternalReference::wasm_f64_floor(isolate).address(), | |
113 "wasm::f64_floor_wrapper"); | |
114 Add(ExternalReference::wasm_f64_ceil(isolate).address(), | |
115 "wasm::f64_ceil_wrapper"); | |
116 Add(ExternalReference::wasm_f64_nearest_int(isolate).address(), | |
117 "wasm::f64_nearest_int_wrapper"); | |
118 Add(ExternalReference::wasm_int64_to_float32(isolate).address(), | |
119 "wasm::int64_to_float32_wrapper"); | |
120 Add(ExternalReference::wasm_uint64_to_float32(isolate).address(), | |
121 "wasm::uint64_to_float32_wrapper"); | |
122 Add(ExternalReference::wasm_int64_to_float64(isolate).address(), | |
123 "wasm::int64_to_float64_wrapper"); | |
124 Add(ExternalReference::wasm_uint64_to_float64(isolate).address(), | |
125 "wasm::uint64_to_float64_wrapper"); | |
126 Add(ExternalReference::wasm_float32_to_int64(isolate).address(), | |
127 "wasm::float32_to_int64_wrapper"); | |
128 Add(ExternalReference::wasm_float32_to_uint64(isolate).address(), | |
129 "wasm::float32_to_uint64_wrapper"); | |
130 Add(ExternalReference::wasm_float64_to_int64(isolate).address(), | |
131 "wasm::float64_to_int64_wrapper"); | |
132 Add(ExternalReference::wasm_float64_to_uint64(isolate).address(), | |
133 "wasm::float64_to_uint64_wrapper"); | |
134 Add(ExternalReference::wasm_int64_div(isolate).address(), "wasm::int64_div"); | |
135 Add(ExternalReference::wasm_int64_mod(isolate).address(), "wasm::int64_mod"); | |
136 Add(ExternalReference::wasm_uint64_div(isolate).address(), | |
137 "wasm::uint64_div"); | |
138 Add(ExternalReference::wasm_uint64_mod(isolate).address(), | |
139 "wasm::uint64_mod"); | |
140 Add(ExternalReference::f64_acos_wrapper_function(isolate).address(), | |
141 "f64_acos_wrapper"); | |
142 Add(ExternalReference::f64_asin_wrapper_function(isolate).address(), | |
143 "f64_asin_wrapper"); | |
144 Add(ExternalReference::f64_atan_wrapper_function(isolate).address(), | |
145 "f64_atan_wrapper"); | |
146 Add(ExternalReference::f64_cos_wrapper_function(isolate).address(), | |
147 "f64_cos_wrapper"); | |
148 Add(ExternalReference::f64_sin_wrapper_function(isolate).address(), | |
149 "f64_sin_wrapper"); | |
150 Add(ExternalReference::f64_tan_wrapper_function(isolate).address(), | |
151 "f64_tan_wrapper"); | |
152 Add(ExternalReference::f64_exp_wrapper_function(isolate).address(), | |
153 "f64_exp_wrapper"); | |
154 Add(ExternalReference::f64_log_wrapper_function(isolate).address(), | |
155 "f64_log_wrapper"); | |
156 Add(ExternalReference::f64_pow_wrapper_function(isolate).address(), | |
157 "f64_pow_wrapper"); | |
158 Add(ExternalReference::f64_atan2_wrapper_function(isolate).address(), | |
159 "f64_atan2_wrapper"); | |
160 Add(ExternalReference::f64_mod_wrapper_function(isolate).address(), | |
161 "f64_mod_wrapper"); | |
162 Add(ExternalReference::log_enter_external_function(isolate).address(), | |
163 "Logger::EnterExternal"); | |
164 Add(ExternalReference::log_leave_external_function(isolate).address(), | |
165 "Logger::LeaveExternal"); | |
166 Add(ExternalReference::address_of_minus_one_half().address(), | |
167 "double_constants.minus_one_half"); | |
168 Add(ExternalReference::stress_deopt_count(isolate).address(), | |
169 "Isolate::stress_deopt_count_address()"); | |
170 Add(ExternalReference::virtual_handler_register(isolate).address(), | |
171 "Isolate::virtual_handler_register()"); | |
172 Add(ExternalReference::virtual_slot_register(isolate).address(), | |
173 "Isolate::virtual_slot_register()"); | |
174 Add(ExternalReference::runtime_function_table_address(isolate).address(), | |
175 "Runtime::runtime_function_table_address()"); | |
176 | |
177 // Debug addresses | |
178 Add(ExternalReference::debug_after_break_target_address(isolate).address(), | |
179 "Debug::after_break_target_address()"); | |
180 Add(ExternalReference::debug_is_active_address(isolate).address(), | |
181 "Debug::is_active_address()"); | |
182 Add(ExternalReference::debug_step_in_enabled_address(isolate).address(), | |
183 "Debug::step_in_enabled_address()"); | |
184 | |
185 #ifndef V8_INTERPRETED_REGEXP | |
186 Add(ExternalReference::re_case_insensitive_compare_uc16(isolate).address(), | |
187 "NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()"); | |
188 Add(ExternalReference::re_check_stack_guard_state(isolate).address(), | |
189 "RegExpMacroAssembler*::CheckStackGuardState()"); | |
190 Add(ExternalReference::re_grow_stack(isolate).address(), | |
191 "NativeRegExpMacroAssembler::GrowStack()"); | |
192 Add(ExternalReference::re_word_character_map().address(), | |
193 "NativeRegExpMacroAssembler::word_character_map"); | |
194 Add(ExternalReference::address_of_regexp_stack_limit(isolate).address(), | |
195 "RegExpStack::limit_address()"); | |
196 Add(ExternalReference::address_of_regexp_stack_memory_address(isolate) | |
197 .address(), | |
198 "RegExpStack::memory_address()"); | |
199 Add(ExternalReference::address_of_regexp_stack_memory_size(isolate).address(), | |
200 "RegExpStack::memory_size()"); | |
201 Add(ExternalReference::address_of_static_offsets_vector(isolate).address(), | |
202 "OffsetsVector::static_offsets_vector"); | |
203 #endif // V8_INTERPRETED_REGEXP | |
204 | |
205 // The following populates all of the different type of external references | |
206 // into the ExternalReferenceTable. | |
207 // | |
208 // NOTE: This function was originally 100k of code. It has since been | |
209 // rewritten to be mostly table driven, as the callback macro style tends to | |
210 // very easily cause code bloat. Please be careful in the future when adding | |
211 // new references. | |
212 | |
213 struct RefTableEntry { | |
214 uint16_t id; | |
215 const char* name; | |
216 }; | |
217 | |
218 static const RefTableEntry c_builtins[] = { | |
219 #define DEF_ENTRY_C(name, ignored) {Builtins::c_##name, "Builtins::" #name}, | |
220 BUILTIN_LIST_C(DEF_ENTRY_C) | |
221 #undef DEF_ENTRY_C | |
222 }; | |
223 | |
224 for (unsigned i = 0; i < arraysize(c_builtins); ++i) { | |
225 ExternalReference ref(static_cast<Builtins::CFunctionId>(c_builtins[i].id), | |
226 isolate); | |
227 Add(ref.address(), c_builtins[i].name); | |
228 } | |
229 | |
230 static const RefTableEntry builtins[] = { | |
231 #define DEF_ENTRY_C(name, ignored) {Builtins::k##name, "Builtins::" #name}, | |
232 #define DEF_ENTRY_A(name, i1, i2, i3) {Builtins::k##name, "Builtins::" #name}, | |
233 BUILTIN_LIST_C(DEF_ENTRY_C) BUILTIN_LIST_A(DEF_ENTRY_A) | |
234 BUILTIN_LIST_DEBUG_A(DEF_ENTRY_A) | |
235 #undef DEF_ENTRY_C | |
236 #undef DEF_ENTRY_A | |
237 }; | |
238 | |
239 for (unsigned i = 0; i < arraysize(builtins); ++i) { | |
240 ExternalReference ref(static_cast<Builtins::Name>(builtins[i].id), isolate); | |
241 Add(ref.address(), builtins[i].name); | |
242 } | |
243 | |
244 static const RefTableEntry runtime_functions[] = { | |
245 #define RUNTIME_ENTRY(name, i1, i2) {Runtime::k##name, "Runtime::" #name}, | |
246 FOR_EACH_INTRINSIC(RUNTIME_ENTRY) | |
247 #undef RUNTIME_ENTRY | |
248 }; | |
249 | |
250 for (unsigned i = 0; i < arraysize(runtime_functions); ++i) { | |
251 ExternalReference ref( | |
252 static_cast<Runtime::FunctionId>(runtime_functions[i].id), isolate); | |
253 Add(ref.address(), runtime_functions[i].name); | |
254 } | |
255 | |
256 // Stat counters | |
257 struct StatsRefTableEntry { | |
258 StatsCounter* (Counters::*counter)(); | |
259 const char* name; | |
260 }; | |
261 | |
262 static const StatsRefTableEntry stats_ref_table[] = { | |
263 #define COUNTER_ENTRY(name, caption) {&Counters::name, "Counters::" #name}, | |
264 STATS_COUNTER_LIST_1(COUNTER_ENTRY) STATS_COUNTER_LIST_2(COUNTER_ENTRY) | |
265 #undef COUNTER_ENTRY | |
266 }; | |
267 | |
268 Counters* counters = isolate->counters(); | |
269 for (unsigned i = 0; i < arraysize(stats_ref_table); ++i) { | |
270 // To make sure the indices are not dependent on whether counters are | |
271 // enabled, use a dummy address as filler. | |
272 Address address = NotAvailable(); | |
273 StatsCounter* counter = (counters->*(stats_ref_table[i].counter))(); | |
274 if (counter->Enabled()) { | |
275 address = reinterpret_cast<Address>(counter->GetInternalPointer()); | |
276 } | |
277 Add(address, stats_ref_table[i].name); | |
278 } | |
279 | |
280 // Top addresses | |
281 static const char* address_names[] = { | |
282 #define BUILD_NAME_LITERAL(Name, name) "Isolate::" #name "_address", | |
283 FOR_EACH_ISOLATE_ADDRESS_NAME(BUILD_NAME_LITERAL) NULL | |
284 #undef BUILD_NAME_LITERAL | |
285 }; | |
286 | |
287 for (int i = 0; i < Isolate::kIsolateAddressCount; ++i) { | |
288 Add(isolate->get_address_from_id(static_cast<Isolate::AddressId>(i)), | |
289 address_names[i]); | |
290 } | |
291 | |
292 // Accessors | |
293 struct AccessorRefTable { | |
294 Address address; | |
295 const char* name; | |
296 }; | |
297 | |
298 static const AccessorRefTable accessors[] = { | |
299 #define ACCESSOR_INFO_DECLARATION(name) \ | |
300 {FUNCTION_ADDR(&Accessors::name##Getter), "Accessors::" #name "Getter"}, | |
301 ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION) | |
302 #undef ACCESSOR_INFO_DECLARATION | |
303 #define ACCESSOR_SETTER_DECLARATION(name) \ | |
304 {FUNCTION_ADDR(&Accessors::name), "Accessors::" #name}, | |
305 ACCESSOR_SETTER_LIST(ACCESSOR_SETTER_DECLARATION) | |
306 #undef ACCESSOR_INFO_DECLARATION | |
307 }; | |
308 | |
309 for (unsigned i = 0; i < arraysize(accessors); ++i) { | |
310 Add(accessors[i].address, accessors[i].name); | |
311 } | |
312 | |
313 StubCache* stub_cache = isolate->stub_cache(); | |
314 | |
315 // Stub cache tables | |
316 Add(stub_cache->key_reference(StubCache::kPrimary).address(), | |
317 "StubCache::primary_->key"); | |
318 Add(stub_cache->value_reference(StubCache::kPrimary).address(), | |
319 "StubCache::primary_->value"); | |
320 Add(stub_cache->map_reference(StubCache::kPrimary).address(), | |
321 "StubCache::primary_->map"); | |
322 Add(stub_cache->key_reference(StubCache::kSecondary).address(), | |
323 "StubCache::secondary_->key"); | |
324 Add(stub_cache->value_reference(StubCache::kSecondary).address(), | |
325 "StubCache::secondary_->value"); | |
326 Add(stub_cache->map_reference(StubCache::kSecondary).address(), | |
327 "StubCache::secondary_->map"); | |
328 | |
329 // Runtime entries | |
330 Add(ExternalReference::delete_handle_scope_extensions(isolate).address(), | |
331 "HandleScope::DeleteExtensions"); | |
332 Add(ExternalReference::incremental_marking_record_write_function(isolate) | |
333 .address(), | |
334 "IncrementalMarking::RecordWrite"); | |
335 Add(ExternalReference::incremental_marking_record_write_code_entry_function( | |
336 isolate) | |
337 .address(), | |
338 "IncrementalMarking::RecordWriteOfCodeEntryFromCode"); | |
339 Add(ExternalReference::store_buffer_overflow_function(isolate).address(), | |
340 "StoreBuffer::StoreBufferOverflow"); | |
341 | |
342 // Add a small set of deopt entry addresses to encoder without generating the | |
343 // deopt table code, which isn't possible at deserialization time. | |
344 HandleScope scope(isolate); | |
345 for (int entry = 0; entry < kDeoptTableSerializeEntryCount; ++entry) { | |
346 Address address = Deoptimizer::GetDeoptimizationEntry( | |
347 isolate, entry, Deoptimizer::LAZY, | |
348 Deoptimizer::CALCULATE_ENTRY_ADDRESS); | |
349 Add(address, "lazy_deopt"); | |
350 } | |
351 } | |
352 | |
353 ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate) { | 14 ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate) { |
354 map_ = isolate->external_reference_map(); | 15 map_ = isolate->external_reference_map(); |
355 if (map_ != NULL) return; | 16 if (map_ != NULL) return; |
356 map_ = new HashMap(HashMap::PointersMatch); | 17 map_ = new HashMap(HashMap::PointersMatch); |
357 ExternalReferenceTable* table = ExternalReferenceTable::instance(isolate); | 18 ExternalReferenceTable* table = ExternalReferenceTable::instance(isolate); |
358 for (int i = 0; i < table->size(); ++i) { | 19 for (int i = 0; i < table->size(); ++i) { |
359 Address addr = table->address(i); | 20 Address addr = table->address(i); |
360 if (addr == ExternalReferenceTable::NotAvailable()) continue; | 21 if (addr == ExternalReferenceTable::NotAvailable()) continue; |
361 // We expect no duplicate external references entries in the table. | 22 // We expect no duplicate external references entries in the table. |
362 DCHECK_NULL(map_->Lookup(addr, Hash(addr))); | 23 DCHECK_NULL(map_->Lookup(addr, Hash(addr))); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 if (cache->at(i)->IsUndefined()) break; | 67 if (cache->at(i)->IsUndefined()) break; |
407 } | 68 } |
408 } | 69 } |
409 | 70 |
410 bool SerializerDeserializer::CanBeDeferred(HeapObject* o) { | 71 bool SerializerDeserializer::CanBeDeferred(HeapObject* o) { |
411 return !o->IsString() && !o->IsScript(); | 72 return !o->IsString() && !o->IsScript(); |
412 } | 73 } |
413 | 74 |
414 } // namespace internal | 75 } // namespace internal |
415 } // namespace v8 | 76 } // namespace v8 |
OLD | NEW |