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/startup-serializer.h" | 5 #include "src/snapshot/startup-serializer.h" |
6 | 6 |
7 #include "src/objects-inl.h" | 7 #include "src/objects-inl.h" |
8 #include "src/v8threads.h" | 8 #include "src/v8threads.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 StartupSerializer::StartupSerializer( | 13 StartupSerializer::StartupSerializer( |
14 Isolate* isolate, SnapshotByteSink* sink, | 14 Isolate* isolate, SnapshotByteSink* sink, |
15 FunctionCodeHandling function_code_handling) | 15 FunctionCodeHandling function_code_handling) |
16 : Serializer(isolate, sink), | 16 : Serializer(isolate, sink), |
17 function_code_handling_(function_code_handling), | 17 function_code_handling_(function_code_handling), |
18 serializing_builtins_(false) { | 18 serializing_builtins_(false) { |
19 InitializeCodeAddressMap(); | 19 InitializeCodeAddressMap(); |
20 } | 20 } |
21 | 21 |
22 StartupSerializer::~StartupSerializer() { | 22 StartupSerializer::~StartupSerializer() { |
23 OutputStatistics("StartupSerializer"); | 23 OutputStatistics("StartupSerializer"); |
24 } | 24 } |
25 | 25 |
26 void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, | 26 void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, |
27 WhereToPoint where_to_point, int skip) { | 27 WhereToPoint where_to_point, int skip) { |
28 DCHECK(!obj->IsJSFunction()); | 28 DCHECK(!obj->IsJSFunction()); |
29 | 29 |
30 if (obj->IsCode()) { | 30 if (function_code_handling_ == CLEAR_FUNCTION_CODE) { |
| 31 if (obj->IsCode()) { |
| 32 Code* code = Code::cast(obj); |
| 33 // If the function code is compiled (either as native code or bytecode), |
| 34 // replace it with lazy-compile builtin. Only exception is when we are |
| 35 // serializing the canonical interpreter-entry-trampoline builtin. |
| 36 if (code->kind() == Code::FUNCTION || |
| 37 (!serializing_builtins_ && code->is_interpreter_entry_trampoline())) { |
| 38 obj = isolate()->builtins()->builtin(Builtins::kCompileLazy); |
| 39 } |
| 40 } else if (obj->IsBytecodeArray()) { |
| 41 obj = isolate()->heap()->undefined_value(); |
| 42 } |
| 43 } else if (obj->IsCode()) { |
| 44 DCHECK_EQ(KEEP_FUNCTION_CODE, function_code_handling_); |
31 Code* code = Code::cast(obj); | 45 Code* code = Code::cast(obj); |
32 // If the function code is compiled (either as native code or bytecode), | 46 if (code->kind() == Code::FUNCTION) { |
33 // replace it with lazy-compile builtin. Only exception is when we are | 47 code->ClearInlineCaches(); |
34 // serializing the canonical interpreter-entry-trampoline builtin. | 48 code->set_profiler_ticks(0); |
35 if (function_code_handling_ == CLEAR_FUNCTION_CODE && | |
36 (code->kind() == Code::FUNCTION || | |
37 (!serializing_builtins_ && code->is_interpreter_entry_trampoline()))) { | |
38 obj = isolate()->builtins()->builtin(Builtins::kCompileLazy); | |
39 } | 49 } |
40 } else if (obj->IsBytecodeArray()) { | |
41 obj = isolate()->heap()->undefined_value(); | |
42 } | 50 } |
43 | 51 |
44 int root_index = root_index_map_.Lookup(obj); | 52 int root_index = root_index_map_.Lookup(obj); |
45 // We can only encode roots as such if it has already been serialized. | 53 // We can only encode roots as such if it has already been serialized. |
46 // That applies to root indices below the wave front. | 54 // That applies to root indices below the wave front. |
47 if (root_index != RootIndexMap::kInvalidRootIndex) { | 55 if (root_index != RootIndexMap::kInvalidRootIndex) { |
48 if (root_has_been_serialized_.test(root_index)) { | 56 if (root_has_been_serialized_.test(root_index)) { |
49 PutRoot(root_index, obj, how_to_code, where_to_point, skip); | 57 PutRoot(root_index, obj, how_to_code, where_to_point, skip); |
50 return; | 58 return; |
51 } | 59 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 root_index == Heap::kStackLimitRootIndex || | 154 root_index == Heap::kStackLimitRootIndex || |
147 root_index == Heap::kRealStackLimitRootIndex) { | 155 root_index == Heap::kRealStackLimitRootIndex) { |
148 return true; | 156 return true; |
149 } | 157 } |
150 return Heap::RootIsImmortalImmovable(root_index) != | 158 return Heap::RootIsImmortalImmovable(root_index) != |
151 serializing_immortal_immovables_roots_; | 159 serializing_immortal_immovables_roots_; |
152 } | 160 } |
153 | 161 |
154 } // namespace internal | 162 } // namespace internal |
155 } // namespace v8 | 163 } // namespace v8 |
OLD | NEW |