| 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" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 } | 216 } |
| 217 return scope.CloseAndEscape(result); | 217 return scope.CloseAndEscape(result); |
| 218 } | 218 } |
| 219 | 219 |
| 220 std::unique_ptr<ScriptData> WasmCompiledModuleSerializer::SerializeWasmModule( | 220 std::unique_ptr<ScriptData> WasmCompiledModuleSerializer::SerializeWasmModule( |
| 221 Isolate* isolate, Handle<FixedArray> input) { | 221 Isolate* isolate, Handle<FixedArray> input) { |
| 222 Handle<wasm::WasmCompiledModule> compiled_module = | 222 Handle<wasm::WasmCompiledModule> compiled_module = |
| 223 Handle<wasm::WasmCompiledModule>::cast(input); | 223 Handle<wasm::WasmCompiledModule>::cast(input); |
| 224 WasmCompiledModuleSerializer wasm_cs(isolate, 0); | 224 WasmCompiledModuleSerializer wasm_cs(isolate, 0); |
| 225 wasm_cs.reference_map()->AddAttachedReference(*isolate->native_context()); | 225 wasm_cs.reference_map()->AddAttachedReference(*isolate->native_context()); |
| 226 wasm_cs.reference_map()->AddAttachedReference( |
| 227 *compiled_module->module_bytes()); |
| 226 ScriptData* data = wasm_cs.Serialize(compiled_module); | 228 ScriptData* data = wasm_cs.Serialize(compiled_module); |
| 227 return std::unique_ptr<ScriptData>(data); | 229 return std::unique_ptr<ScriptData>(data); |
| 228 } | 230 } |
| 229 | 231 |
| 230 MaybeHandle<FixedArray> WasmCompiledModuleSerializer::DeserializeWasmModule( | 232 MaybeHandle<FixedArray> WasmCompiledModuleSerializer::DeserializeWasmModule( |
| 231 Isolate* isolate, ScriptData* data) { | 233 Isolate* isolate, ScriptData* data, Vector<const byte> wire_bytes) { |
| 232 SerializedCodeData::SanityCheckResult sanity_check_result = | 234 SerializedCodeData::SanityCheckResult sanity_check_result = |
| 233 SerializedCodeData::CHECK_SUCCESS; | 235 SerializedCodeData::CHECK_SUCCESS; |
| 234 MaybeHandle<FixedArray> nothing; | 236 MaybeHandle<FixedArray> nothing; |
| 235 const SerializedCodeData scd = SerializedCodeData::FromCachedData( | 237 const SerializedCodeData scd = SerializedCodeData::FromCachedData( |
| 236 isolate, data, 0, &sanity_check_result); | 238 isolate, data, 0, &sanity_check_result); |
| 237 | 239 |
| 238 if (sanity_check_result != SerializedCodeData::CHECK_SUCCESS) { | 240 if (sanity_check_result != SerializedCodeData::CHECK_SUCCESS) { |
| 239 return nothing; | 241 return nothing; |
| 240 } | 242 } |
| 241 | 243 |
| 242 Deserializer deserializer(&scd, true); | 244 Deserializer deserializer(&scd, true); |
| 243 deserializer.AddAttachedObject(isolate->native_context()); | 245 deserializer.AddAttachedObject(isolate->native_context()); |
| 244 | 246 |
| 247 MaybeHandle<String> maybe_wire_bytes_as_string = |
| 248 isolate->factory()->NewStringFromOneByte(wire_bytes, TENURED); |
| 249 Handle<String> wire_bytes_as_string; |
| 250 if (!maybe_wire_bytes_as_string.ToHandle(&wire_bytes_as_string)) { |
| 251 return nothing; |
| 252 } |
| 253 deserializer.AddAttachedObject( |
| 254 handle(SeqOneByteString::cast(*wire_bytes_as_string))); |
| 255 |
| 245 Vector<const uint32_t> stub_keys = scd.CodeStubKeys(); | 256 Vector<const uint32_t> stub_keys = scd.CodeStubKeys(); |
| 246 for (int i = 0; i < stub_keys.length(); ++i) { | 257 for (int i = 0; i < stub_keys.length(); ++i) { |
| 247 deserializer.AddAttachedObject( | 258 deserializer.AddAttachedObject( |
| 248 CodeStub::GetCode(isolate, stub_keys[i]).ToHandleChecked()); | 259 CodeStub::GetCode(isolate, stub_keys[i]).ToHandleChecked()); |
| 249 } | 260 } |
| 250 | 261 |
| 251 MaybeHandle<HeapObject> obj = deserializer.DeserializeObject(isolate); | 262 MaybeHandle<HeapObject> obj = deserializer.DeserializeObject(isolate); |
| 252 if (obj.is_null() || !obj.ToHandleChecked()->IsFixedArray()) return nothing; | 263 if (obj.is_null() || !obj.ToHandleChecked()->IsFixedArray()) return nothing; |
| 253 Handle<FixedArray> compiled_module = | 264 Handle<wasm::WasmCompiledModule> compiled_module = |
| 254 Handle<FixedArray>::cast(obj.ToHandleChecked()); | 265 Handle<wasm::WasmCompiledModule>::cast(obj.ToHandleChecked()); |
| 266 |
| 255 wasm::WasmCompiledModule::RecreateModuleWrapper(isolate, compiled_module); | 267 wasm::WasmCompiledModule::RecreateModuleWrapper(isolate, compiled_module); |
| 256 return compiled_module; | 268 return compiled_module; |
| 257 } | 269 } |
| 258 | 270 |
| 259 class Checksum { | 271 class Checksum { |
| 260 public: | 272 public: |
| 261 explicit Checksum(Vector<const byte> payload) { | 273 explicit Checksum(Vector<const byte> payload) { |
| 262 #ifdef MEMORY_SANITIZER | 274 #ifdef MEMORY_SANITIZER |
| 263 // Computing the checksum includes padding bytes for objects like strings. | 275 // Computing the checksum includes padding bytes for objects like strings. |
| 264 // Mark every object as initialized in the code serializer. | 276 // Mark every object as initialized in the code serializer. |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 *rejection_result = scd.SanityCheck(isolate, expected_source_hash); | 428 *rejection_result = scd.SanityCheck(isolate, expected_source_hash); |
| 417 if (*rejection_result != CHECK_SUCCESS) { | 429 if (*rejection_result != CHECK_SUCCESS) { |
| 418 cached_data->Reject(); | 430 cached_data->Reject(); |
| 419 return SerializedCodeData(nullptr, 0); | 431 return SerializedCodeData(nullptr, 0); |
| 420 } | 432 } |
| 421 return scd; | 433 return scd; |
| 422 } | 434 } |
| 423 | 435 |
| 424 } // namespace internal | 436 } // namespace internal |
| 425 } // namespace v8 | 437 } // namespace v8 |
| OLD | NEW |