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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 return scope.CloseAndEscape(result); | 224 return scope.CloseAndEscape(result); |
225 } | 225 } |
226 | 226 |
227 std::unique_ptr<ScriptData> WasmCompiledModuleSerializer::SerializeWasmModule( | 227 std::unique_ptr<ScriptData> WasmCompiledModuleSerializer::SerializeWasmModule( |
228 Isolate* isolate, Handle<FixedArray> input) { | 228 Isolate* isolate, Handle<FixedArray> input) { |
229 Handle<WasmCompiledModule> compiled_module = | 229 Handle<WasmCompiledModule> compiled_module = |
230 Handle<WasmCompiledModule>::cast(input); | 230 Handle<WasmCompiledModule>::cast(input); |
231 WasmCompiledModuleSerializer wasm_cs(isolate, 0); | 231 WasmCompiledModuleSerializer wasm_cs(isolate, 0); |
232 wasm_cs.reference_map()->AddAttachedReference(*isolate->native_context()); | 232 wasm_cs.reference_map()->AddAttachedReference(*isolate->native_context()); |
233 wasm_cs.reference_map()->AddAttachedReference( | 233 wasm_cs.reference_map()->AddAttachedReference( |
234 *compiled_module->module_bytes()); | 234 compiled_module->module_bytes()); |
235 ScriptData* data = wasm_cs.Serialize(compiled_module); | 235 ScriptData* data = wasm_cs.Serialize(compiled_module); |
236 return std::unique_ptr<ScriptData>(data); | 236 return std::unique_ptr<ScriptData>(data); |
237 } | 237 } |
238 | 238 |
239 MaybeHandle<FixedArray> WasmCompiledModuleSerializer::DeserializeWasmModule( | 239 MaybeHandle<FixedArray> WasmCompiledModuleSerializer::DeserializeWasmModule( |
240 Isolate* isolate, ScriptData* data, Vector<const byte> wire_bytes) { | 240 Isolate* isolate, ScriptData* data, Vector<const byte> wire_bytes) { |
241 SerializedCodeData::SanityCheckResult sanity_check_result = | 241 SerializedCodeData::SanityCheckResult sanity_check_result = |
242 SerializedCodeData::CHECK_SUCCESS; | 242 SerializedCodeData::CHECK_SUCCESS; |
243 MaybeHandle<FixedArray> nothing; | 243 MaybeHandle<FixedArray> nothing; |
244 const SerializedCodeData scd = SerializedCodeData::FromCachedData( | 244 const SerializedCodeData scd = SerializedCodeData::FromCachedData( |
(...skipping 16 matching lines...) Expand all Loading... |
261 handle(SeqOneByteString::cast(*wire_bytes_as_string))); | 261 handle(SeqOneByteString::cast(*wire_bytes_as_string))); |
262 | 262 |
263 Vector<const uint32_t> stub_keys = scd.CodeStubKeys(); | 263 Vector<const uint32_t> stub_keys = scd.CodeStubKeys(); |
264 for (int i = 0; i < stub_keys.length(); ++i) { | 264 for (int i = 0; i < stub_keys.length(); ++i) { |
265 deserializer.AddAttachedObject( | 265 deserializer.AddAttachedObject( |
266 CodeStub::GetCode(isolate, stub_keys[i]).ToHandleChecked()); | 266 CodeStub::GetCode(isolate, stub_keys[i]).ToHandleChecked()); |
267 } | 267 } |
268 | 268 |
269 MaybeHandle<HeapObject> obj = deserializer.DeserializeObject(isolate); | 269 MaybeHandle<HeapObject> obj = deserializer.DeserializeObject(isolate); |
270 if (obj.is_null() || !obj.ToHandleChecked()->IsFixedArray()) return nothing; | 270 if (obj.is_null() || !obj.ToHandleChecked()->IsFixedArray()) return nothing; |
271 Handle<WasmCompiledModule> compiled_module = | 271 // Cast without type checks, as the module wrapper is not there yet. |
272 Handle<WasmCompiledModule>::cast(obj.ToHandleChecked()); | 272 Handle<WasmCompiledModule> compiled_module( |
| 273 static_cast<WasmCompiledModule*>(*obj.ToHandleChecked()), isolate); |
273 | 274 |
274 WasmCompiledModule::RecreateModuleWrapper(isolate, compiled_module); | 275 WasmCompiledModule::RecreateModuleWrapper(isolate, compiled_module); |
| 276 DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module)); |
275 return compiled_module; | 277 return compiled_module; |
276 } | 278 } |
277 | 279 |
278 class Checksum { | 280 class Checksum { |
279 public: | 281 public: |
280 explicit Checksum(Vector<const byte> payload) { | 282 explicit Checksum(Vector<const byte> payload) { |
281 #ifdef MEMORY_SANITIZER | 283 #ifdef MEMORY_SANITIZER |
282 // Computing the checksum includes padding bytes for objects like strings. | 284 // Computing the checksum includes padding bytes for objects like strings. |
283 // Mark every object as initialized in the code serializer. | 285 // Mark every object as initialized in the code serializer. |
284 MSAN_MEMORY_IS_INITIALIZED(payload.start(), payload.length()); | 286 MSAN_MEMORY_IS_INITIALIZED(payload.start(), payload.length()); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 *rejection_result = scd.SanityCheck(isolate, expected_source_hash); | 437 *rejection_result = scd.SanityCheck(isolate, expected_source_hash); |
436 if (*rejection_result != CHECK_SUCCESS) { | 438 if (*rejection_result != CHECK_SUCCESS) { |
437 cached_data->Reject(); | 439 cached_data->Reject(); |
438 return SerializedCodeData(nullptr, 0); | 440 return SerializedCodeData(nullptr, 0); |
439 } | 441 } |
440 return scd; | 442 return scd; |
441 } | 443 } |
442 | 444 |
443 } // namespace internal | 445 } // namespace internal |
444 } // namespace v8 | 446 } // namespace v8 |
OLD | NEW |