Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: src/snapshot/serializer-common.cc

Issue 1751863002: [serializer] split up src/snapshot/serialize.* (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/snapshot/serializer-common.h"
6
7 #include "src/accessors.h"
8 #include "src/assembler.h"
9 #include "src/counters.h"
10 #include "src/deoptimizer.h"
11 #include "src/ic/stub-cache.h"
12 #include "src/list-inl.h"
13
14 namespace v8 {
15 namespace internal {
16
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::f32_trunc_wrapper_function(isolate).address(),
103 "f32_trunc_wrapper");
104 Add(ExternalReference::f32_floor_wrapper_function(isolate).address(),
105 "f32_floor_wrapper");
106 Add(ExternalReference::f32_ceil_wrapper_function(isolate).address(),
107 "f32_ceil_wrapper");
108 Add(ExternalReference::f32_nearest_int_wrapper_function(isolate).address(),
109 "f32_nearest_int_wrapper");
110 Add(ExternalReference::f64_trunc_wrapper_function(isolate).address(),
111 "f64_trunc_wrapper");
112 Add(ExternalReference::f64_floor_wrapper_function(isolate).address(),
113 "f64_floor_wrapper");
114 Add(ExternalReference::f64_ceil_wrapper_function(isolate).address(),
115 "f64_ceil_wrapper");
116 Add(ExternalReference::f64_nearest_int_wrapper_function(isolate).address(),
117 "f64_nearest_int_wrapper");
118 Add(ExternalReference::log_enter_external_function(isolate).address(),
119 "Logger::EnterExternal");
120 Add(ExternalReference::log_leave_external_function(isolate).address(),
121 "Logger::LeaveExternal");
122 Add(ExternalReference::address_of_minus_one_half().address(),
123 "double_constants.minus_one_half");
124 Add(ExternalReference::stress_deopt_count(isolate).address(),
125 "Isolate::stress_deopt_count_address()");
126 Add(ExternalReference::virtual_handler_register(isolate).address(),
127 "Isolate::virtual_handler_register()");
128 Add(ExternalReference::virtual_slot_register(isolate).address(),
129 "Isolate::virtual_slot_register()");
130 Add(ExternalReference::runtime_function_table_address(isolate).address(),
131 "Runtime::runtime_function_table_address()");
132
133 // Debug addresses
134 Add(ExternalReference::debug_after_break_target_address(isolate).address(),
135 "Debug::after_break_target_address()");
136 Add(ExternalReference::debug_is_active_address(isolate).address(),
137 "Debug::is_active_address()");
138 Add(ExternalReference::debug_step_in_enabled_address(isolate).address(),
139 "Debug::step_in_enabled_address()");
140
141 #ifndef V8_INTERPRETED_REGEXP
142 Add(ExternalReference::re_case_insensitive_compare_uc16(isolate).address(),
143 "NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()");
144 Add(ExternalReference::re_check_stack_guard_state(isolate).address(),
145 "RegExpMacroAssembler*::CheckStackGuardState()");
146 Add(ExternalReference::re_grow_stack(isolate).address(),
147 "NativeRegExpMacroAssembler::GrowStack()");
148 Add(ExternalReference::re_word_character_map().address(),
149 "NativeRegExpMacroAssembler::word_character_map");
150 Add(ExternalReference::address_of_regexp_stack_limit(isolate).address(),
151 "RegExpStack::limit_address()");
152 Add(ExternalReference::address_of_regexp_stack_memory_address(isolate)
153 .address(),
154 "RegExpStack::memory_address()");
155 Add(ExternalReference::address_of_regexp_stack_memory_size(isolate).address(),
156 "RegExpStack::memory_size()");
157 Add(ExternalReference::address_of_static_offsets_vector(isolate).address(),
158 "OffsetsVector::static_offsets_vector");
159 #endif // V8_INTERPRETED_REGEXP
160
161 // The following populates all of the different type of external references
162 // into the ExternalReferenceTable.
163 //
164 // NOTE: This function was originally 100k of code. It has since been
165 // rewritten to be mostly table driven, as the callback macro style tends to
166 // very easily cause code bloat. Please be careful in the future when adding
167 // new references.
168
169 struct RefTableEntry {
170 uint16_t id;
171 const char* name;
172 };
173
174 static const RefTableEntry c_builtins[] = {
175 #define DEF_ENTRY_C(name, ignored) {Builtins::c_##name, "Builtins::" #name},
176 BUILTIN_LIST_C(DEF_ENTRY_C)
177 #undef DEF_ENTRY_C
178 };
179
180 for (unsigned i = 0; i < arraysize(c_builtins); ++i) {
181 ExternalReference ref(static_cast<Builtins::CFunctionId>(c_builtins[i].id),
182 isolate);
183 Add(ref.address(), c_builtins[i].name);
184 }
185
186 static const RefTableEntry builtins[] = {
187 #define DEF_ENTRY_C(name, ignored) {Builtins::k##name, "Builtins::" #name},
188 #define DEF_ENTRY_A(name, i1, i2, i3) {Builtins::k##name, "Builtins::" #name},
189 BUILTIN_LIST_C(DEF_ENTRY_C) BUILTIN_LIST_A(DEF_ENTRY_A)
190 BUILTIN_LIST_DEBUG_A(DEF_ENTRY_A)
191 #undef DEF_ENTRY_C
192 #undef DEF_ENTRY_A
193 };
194
195 for (unsigned i = 0; i < arraysize(builtins); ++i) {
196 ExternalReference ref(static_cast<Builtins::Name>(builtins[i].id), isolate);
197 Add(ref.address(), builtins[i].name);
198 }
199
200 static const RefTableEntry runtime_functions[] = {
201 #define RUNTIME_ENTRY(name, i1, i2) {Runtime::k##name, "Runtime::" #name},
202 FOR_EACH_INTRINSIC(RUNTIME_ENTRY)
203 #undef RUNTIME_ENTRY
204 };
205
206 for (unsigned i = 0; i < arraysize(runtime_functions); ++i) {
207 ExternalReference ref(
208 static_cast<Runtime::FunctionId>(runtime_functions[i].id), isolate);
209 Add(ref.address(), runtime_functions[i].name);
210 }
211
212 // Stat counters
213 struct StatsRefTableEntry {
214 StatsCounter* (Counters::*counter)();
215 const char* name;
216 };
217
218 static const StatsRefTableEntry stats_ref_table[] = {
219 #define COUNTER_ENTRY(name, caption) {&Counters::name, "Counters::" #name},
220 STATS_COUNTER_LIST_1(COUNTER_ENTRY) STATS_COUNTER_LIST_2(COUNTER_ENTRY)
221 #undef COUNTER_ENTRY
222 };
223
224 Counters* counters = isolate->counters();
225 for (unsigned i = 0; i < arraysize(stats_ref_table); ++i) {
226 // To make sure the indices are not dependent on whether counters are
227 // enabled, use a dummy address as filler.
228 Address address = NotAvailable();
229 StatsCounter* counter = (counters->*(stats_ref_table[i].counter))();
230 if (counter->Enabled()) {
231 address = reinterpret_cast<Address>(counter->GetInternalPointer());
232 }
233 Add(address, stats_ref_table[i].name);
234 }
235
236 // Top addresses
237 static const char* address_names[] = {
238 #define BUILD_NAME_LITERAL(Name, name) "Isolate::" #name "_address",
239 FOR_EACH_ISOLATE_ADDRESS_NAME(BUILD_NAME_LITERAL) NULL
240 #undef BUILD_NAME_LITERAL
241 };
242
243 for (int i = 0; i < Isolate::kIsolateAddressCount; ++i) {
244 Add(isolate->get_address_from_id(static_cast<Isolate::AddressId>(i)),
245 address_names[i]);
246 }
247
248 // Accessors
249 struct AccessorRefTable {
250 Address address;
251 const char* name;
252 };
253
254 static const AccessorRefTable accessors[] = {
255 #define ACCESSOR_INFO_DECLARATION(name) \
256 {FUNCTION_ADDR(&Accessors::name##Getter), "Accessors::" #name "Getter"},
257 ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION)
258 #undef ACCESSOR_INFO_DECLARATION
259 #define ACCESSOR_SETTER_DECLARATION(name) \
260 {FUNCTION_ADDR(&Accessors::name), "Accessors::" #name},
261 ACCESSOR_SETTER_LIST(ACCESSOR_SETTER_DECLARATION)
262 #undef ACCESSOR_INFO_DECLARATION
263 };
264
265 for (unsigned i = 0; i < arraysize(accessors); ++i) {
266 Add(accessors[i].address, accessors[i].name);
267 }
268
269 StubCache* stub_cache = isolate->stub_cache();
270
271 // Stub cache tables
272 Add(stub_cache->key_reference(StubCache::kPrimary).address(),
273 "StubCache::primary_->key");
274 Add(stub_cache->value_reference(StubCache::kPrimary).address(),
275 "StubCache::primary_->value");
276 Add(stub_cache->map_reference(StubCache::kPrimary).address(),
277 "StubCache::primary_->map");
278 Add(stub_cache->key_reference(StubCache::kSecondary).address(),
279 "StubCache::secondary_->key");
280 Add(stub_cache->value_reference(StubCache::kSecondary).address(),
281 "StubCache::secondary_->value");
282 Add(stub_cache->map_reference(StubCache::kSecondary).address(),
283 "StubCache::secondary_->map");
284
285 // Runtime entries
286 Add(ExternalReference::delete_handle_scope_extensions(isolate).address(),
287 "HandleScope::DeleteExtensions");
288 Add(ExternalReference::incremental_marking_record_write_function(isolate)
289 .address(),
290 "IncrementalMarking::RecordWrite");
291 Add(ExternalReference::incremental_marking_record_write_code_entry_function(
292 isolate)
293 .address(),
294 "IncrementalMarking::RecordWriteOfCodeEntryFromCode");
295 Add(ExternalReference::store_buffer_overflow_function(isolate).address(),
296 "StoreBuffer::StoreBufferOverflow");
297
298 // Add a small set of deopt entry addresses to encoder without generating the
299 // deopt table code, which isn't possible at deserialization time.
300 HandleScope scope(isolate);
301 for (int entry = 0; entry < kDeoptTableSerializeEntryCount; ++entry) {
302 Address address = Deoptimizer::GetDeoptimizationEntry(
303 isolate, entry, Deoptimizer::LAZY,
304 Deoptimizer::CALCULATE_ENTRY_ADDRESS);
305 Add(address, "lazy_deopt");
306 }
307 }
308
309 ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate) {
310 map_ = isolate->external_reference_map();
311 if (map_ != NULL) return;
312 map_ = new HashMap(HashMap::PointersMatch);
313 ExternalReferenceTable* table = ExternalReferenceTable::instance(isolate);
314 for (int i = 0; i < table->size(); ++i) {
315 Address addr = table->address(i);
316 if (addr == ExternalReferenceTable::NotAvailable()) continue;
317 // We expect no duplicate external references entries in the table.
318 DCHECK_NULL(map_->Lookup(addr, Hash(addr)));
319 map_->LookupOrInsert(addr, Hash(addr))->value = reinterpret_cast<void*>(i);
320 }
321 isolate->set_external_reference_map(map_);
322 }
323
324 uint32_t ExternalReferenceEncoder::Encode(Address address) const {
325 DCHECK_NOT_NULL(address);
326 HashMap::Entry* entry =
327 const_cast<HashMap*>(map_)->Lookup(address, Hash(address));
328 DCHECK_NOT_NULL(entry);
329 return static_cast<uint32_t>(reinterpret_cast<intptr_t>(entry->value));
330 }
331
332 const char* ExternalReferenceEncoder::NameOfAddress(Isolate* isolate,
333 Address address) const {
334 HashMap::Entry* entry =
335 const_cast<HashMap*>(map_)->Lookup(address, Hash(address));
336 if (entry == NULL) return "<unknown>";
337 uint32_t i = static_cast<uint32_t>(reinterpret_cast<intptr_t>(entry->value));
338 return ExternalReferenceTable::instance(isolate)->name(i);
339 }
340
341 void SerializedData::AllocateData(int size) {
342 DCHECK(!owns_data_);
343 data_ = NewArray<byte>(size);
344 size_ = size;
345 owns_data_ = true;
346 DCHECK(IsAligned(reinterpret_cast<intptr_t>(data_), kPointerAlignment));
347 }
348
349 // This ensures that the partial snapshot cache keeps things alive during GC and
350 // tracks their movement. When it is called during serialization of the startup
351 // snapshot nothing happens. When the partial (context) snapshot is created,
352 // this array is populated with the pointers that the partial snapshot will
353 // need. As that happens we emit serialized objects to the startup snapshot
354 // that correspond to the elements of this cache array. On deserialization we
355 // therefore need to visit the cache array. This fills it up with pointers to
356 // deserialized objects.
357 void SerializerDeserializer::Iterate(Isolate* isolate, ObjectVisitor* visitor) {
358 if (isolate->serializer_enabled()) return;
359 List<Object*>* cache = isolate->partial_snapshot_cache();
360 for (int i = 0;; ++i) {
361 // Extend the array ready to get a value when deserializing.
362 if (cache->length() <= i) cache->Add(Smi::FromInt(0));
363 visitor->VisitPointer(&cache->at(i));
364 // Sentinel is the undefined object, which is a root so it will not normally
365 // be found in the cache.
366 if (cache->at(i)->IsUndefined()) break;
367 }
368 }
369
370 bool SerializerDeserializer::CanBeDeferred(HeapObject* o) {
371 return !o->IsString() && !o->IsScript();
372 }
373
374 } // namespace internal
375 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698