| 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/code-serializer.h" | 5 #include "src/snapshot/code-serializer.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
| 10 #include "src/log.h" | 10 #include "src/log.h" |
| 11 #include "src/macro-assembler.h" | 11 #include "src/macro-assembler.h" |
| 12 #include "src/snapshot/deserializer.h" | 12 #include "src/snapshot/deserializer.h" |
| 13 #include "src/snapshot/snapshot.h" | 13 #include "src/snapshot/snapshot.h" |
| 14 #include "src/version.h" | 14 #include "src/version.h" |
| 15 #include "src/wasm/wasm-module.h" | 15 #include "src/wasm/wasm-module.h" |
| 16 #include "src/wasm/wasm-objects.h" |
| 16 | 17 |
| 17 namespace v8 { | 18 namespace v8 { |
| 18 namespace internal { | 19 namespace internal { |
| 19 | 20 |
| 20 ScriptData* CodeSerializer::Serialize(Isolate* isolate, | 21 ScriptData* CodeSerializer::Serialize(Isolate* isolate, |
| 21 Handle<SharedFunctionInfo> info, | 22 Handle<SharedFunctionInfo> info, |
| 22 Handle<String> source) { | 23 Handle<String> source) { |
| 23 base::ElapsedTimer timer; | 24 base::ElapsedTimer timer; |
| 24 if (FLAG_profile_deserialization) timer.Start(); | 25 if (FLAG_profile_deserialization) timer.Start(); |
| 25 if (FLAG_trace_serializer) { | 26 if (FLAG_trace_serializer) { |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 if (script->name()->IsString()) name = String::cast(script->name()); | 213 if (script->name()->IsString()) name = String::cast(script->name()); |
| 213 } | 214 } |
| 214 PROFILE(isolate, CodeCreateEvent(CodeEventListener::SCRIPT_TAG, | 215 PROFILE(isolate, CodeCreateEvent(CodeEventListener::SCRIPT_TAG, |
| 215 result->abstract_code(), *result, name)); | 216 result->abstract_code(), *result, name)); |
| 216 } | 217 } |
| 217 return scope.CloseAndEscape(result); | 218 return scope.CloseAndEscape(result); |
| 218 } | 219 } |
| 219 | 220 |
| 220 std::unique_ptr<ScriptData> WasmCompiledModuleSerializer::SerializeWasmModule( | 221 std::unique_ptr<ScriptData> WasmCompiledModuleSerializer::SerializeWasmModule( |
| 221 Isolate* isolate, Handle<FixedArray> input) { | 222 Isolate* isolate, Handle<FixedArray> input) { |
| 222 Handle<wasm::WasmCompiledModule> compiled_module = | 223 Handle<WasmCompiledModule> compiled_module = |
| 223 Handle<wasm::WasmCompiledModule>::cast(input); | 224 Handle<WasmCompiledModule>::cast(input); |
| 224 WasmCompiledModuleSerializer wasm_cs(isolate, 0); | 225 WasmCompiledModuleSerializer wasm_cs(isolate, 0); |
| 225 wasm_cs.reference_map()->AddAttachedReference(*isolate->native_context()); | 226 wasm_cs.reference_map()->AddAttachedReference(*isolate->native_context()); |
| 226 wasm_cs.reference_map()->AddAttachedReference( | 227 wasm_cs.reference_map()->AddAttachedReference( |
| 227 *compiled_module->module_bytes()); | 228 *compiled_module->module_bytes()); |
| 228 ScriptData* data = wasm_cs.Serialize(compiled_module); | 229 ScriptData* data = wasm_cs.Serialize(compiled_module); |
| 229 return std::unique_ptr<ScriptData>(data); | 230 return std::unique_ptr<ScriptData>(data); |
| 230 } | 231 } |
| 231 | 232 |
| 232 MaybeHandle<FixedArray> WasmCompiledModuleSerializer::DeserializeWasmModule( | 233 MaybeHandle<FixedArray> WasmCompiledModuleSerializer::DeserializeWasmModule( |
| 233 Isolate* isolate, ScriptData* data, Vector<const byte> wire_bytes) { | 234 Isolate* isolate, ScriptData* data, Vector<const byte> wire_bytes) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 254 handle(SeqOneByteString::cast(*wire_bytes_as_string))); | 255 handle(SeqOneByteString::cast(*wire_bytes_as_string))); |
| 255 | 256 |
| 256 Vector<const uint32_t> stub_keys = scd.CodeStubKeys(); | 257 Vector<const uint32_t> stub_keys = scd.CodeStubKeys(); |
| 257 for (int i = 0; i < stub_keys.length(); ++i) { | 258 for (int i = 0; i < stub_keys.length(); ++i) { |
| 258 deserializer.AddAttachedObject( | 259 deserializer.AddAttachedObject( |
| 259 CodeStub::GetCode(isolate, stub_keys[i]).ToHandleChecked()); | 260 CodeStub::GetCode(isolate, stub_keys[i]).ToHandleChecked()); |
| 260 } | 261 } |
| 261 | 262 |
| 262 MaybeHandle<HeapObject> obj = deserializer.DeserializeObject(isolate); | 263 MaybeHandle<HeapObject> obj = deserializer.DeserializeObject(isolate); |
| 263 if (obj.is_null() || !obj.ToHandleChecked()->IsFixedArray()) return nothing; | 264 if (obj.is_null() || !obj.ToHandleChecked()->IsFixedArray()) return nothing; |
| 264 Handle<wasm::WasmCompiledModule> compiled_module = | 265 Handle<WasmCompiledModule> compiled_module = |
| 265 Handle<wasm::WasmCompiledModule>::cast(obj.ToHandleChecked()); | 266 Handle<WasmCompiledModule>::cast(obj.ToHandleChecked()); |
| 266 | 267 |
| 267 wasm::WasmCompiledModule::RecreateModuleWrapper(isolate, compiled_module); | 268 WasmCompiledModule::RecreateModuleWrapper(isolate, compiled_module); |
| 268 return compiled_module; | 269 return compiled_module; |
| 269 } | 270 } |
| 270 | 271 |
| 271 class Checksum { | 272 class Checksum { |
| 272 public: | 273 public: |
| 273 explicit Checksum(Vector<const byte> payload) { | 274 explicit Checksum(Vector<const byte> payload) { |
| 274 #ifdef MEMORY_SANITIZER | 275 #ifdef MEMORY_SANITIZER |
| 275 // Computing the checksum includes padding bytes for objects like strings. | 276 // Computing the checksum includes padding bytes for objects like strings. |
| 276 // Mark every object as initialized in the code serializer. | 277 // Mark every object as initialized in the code serializer. |
| 277 MSAN_MEMORY_IS_INITIALIZED(payload.start(), payload.length()); | 278 MSAN_MEMORY_IS_INITIALIZED(payload.start(), payload.length()); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 *rejection_result = scd.SanityCheck(isolate, expected_source_hash); | 429 *rejection_result = scd.SanityCheck(isolate, expected_source_hash); |
| 429 if (*rejection_result != CHECK_SUCCESS) { | 430 if (*rejection_result != CHECK_SUCCESS) { |
| 430 cached_data->Reject(); | 431 cached_data->Reject(); |
| 431 return SerializedCodeData(nullptr, 0); | 432 return SerializedCodeData(nullptr, 0); |
| 432 } | 433 } |
| 433 return scd; | 434 return scd; |
| 434 } | 435 } |
| 435 | 436 |
| 436 } // namespace internal | 437 } // namespace internal |
| 437 } // namespace v8 | 438 } // namespace v8 |
| OLD | NEW |