| 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 v8::V8::SnapshotCreator::FunctionCodeHandling function_code_handling) |
| 16 : Serializer(isolate, sink), | 16 : Serializer(isolate, sink), |
| 17 function_code_handling_(function_code_handling), | 17 clear_function_code_(function_code_handling == |
| 18 v8::V8::SnapshotCreator::CLEAR_FUNCTION_CODE), |
| 18 serializing_builtins_(false) { | 19 serializing_builtins_(false) { |
| 19 InitializeCodeAddressMap(); | 20 InitializeCodeAddressMap(); |
| 20 } | 21 } |
| 21 | 22 |
| 22 StartupSerializer::~StartupSerializer() { | 23 StartupSerializer::~StartupSerializer() { |
| 23 OutputStatistics("StartupSerializer"); | 24 OutputStatistics("StartupSerializer"); |
| 24 } | 25 } |
| 25 | 26 |
| 26 void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, | 27 void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, |
| 27 WhereToPoint where_to_point, int skip) { | 28 WhereToPoint where_to_point, int skip) { |
| 28 DCHECK(!obj->IsJSFunction()); | 29 DCHECK(!obj->IsJSFunction()); |
| 29 | 30 |
| 30 if (function_code_handling_ == CLEAR_FUNCTION_CODE) { | 31 if (clear_function_code_) { |
| 31 if (obj->IsCode()) { | 32 if (obj->IsCode()) { |
| 32 Code* code = Code::cast(obj); | 33 Code* code = Code::cast(obj); |
| 33 // If the function code is compiled (either as native code or bytecode), | 34 // 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 // replace it with lazy-compile builtin. Only exception is when we are |
| 35 // serializing the canonical interpreter-entry-trampoline builtin. | 36 // serializing the canonical interpreter-entry-trampoline builtin. |
| 36 if (code->kind() == Code::FUNCTION || | 37 if (code->kind() == Code::FUNCTION || |
| 37 (!serializing_builtins_ && | 38 (!serializing_builtins_ && |
| 38 code->is_interpreter_trampoline_builtin())) { | 39 code->is_interpreter_trampoline_builtin())) { |
| 39 obj = isolate()->builtins()->builtin(Builtins::kCompileLazy); | 40 obj = isolate()->builtins()->builtin(Builtins::kCompileLazy); |
| 40 } | 41 } |
| 41 } else if (obj->IsBytecodeArray()) { | 42 } else if (obj->IsBytecodeArray()) { |
| 42 obj = isolate()->heap()->undefined_value(); | 43 obj = isolate()->heap()->undefined_value(); |
| 43 } | 44 } |
| 44 } else if (obj->IsCode()) { | 45 } else if (obj->IsCode()) { |
| 45 DCHECK_EQ(KEEP_FUNCTION_CODE, function_code_handling_); | |
| 46 Code* code = Code::cast(obj); | 46 Code* code = Code::cast(obj); |
| 47 if (code->kind() == Code::FUNCTION) { | 47 if (code->kind() == Code::FUNCTION) { |
| 48 code->ClearInlineCaches(); | 48 code->ClearInlineCaches(); |
| 49 code->set_profiler_ticks(0); | 49 code->set_profiler_ticks(0); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 int root_index = root_index_map_.Lookup(obj); | 53 int root_index = root_index_map_.Lookup(obj); |
| 54 // We can only encode roots as such if it has already been serialized. | 54 // We can only encode roots as such if it has already been serialized. |
| 55 // That applies to root indices below the wave front. | 55 // That applies to root indices below the wave front. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 if (root_index == Heap::kStackLimitRootIndex || | 159 if (root_index == Heap::kStackLimitRootIndex || |
| 160 root_index == Heap::kRealStackLimitRootIndex) { | 160 root_index == Heap::kRealStackLimitRootIndex) { |
| 161 return true; | 161 return true; |
| 162 } | 162 } |
| 163 return Heap::RootIsImmortalImmovable(root_index) != | 163 return Heap::RootIsImmortalImmovable(root_index) != |
| 164 serializing_immortal_immovables_roots_; | 164 serializing_immortal_immovables_roots_; |
| 165 } | 165 } |
| 166 | 166 |
| 167 } // namespace internal | 167 } // namespace internal |
| 168 } // namespace v8 | 168 } // namespace v8 |
| OLD | NEW |