Chromium Code Reviews| 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 Handle<SeqOneByteString> wire_bytes = compiled_module->module_bytes(); | |
|
Yang
2016/10/20 06:46:17
Another way to do this is to use attached referenc
Mircea Trofin
2016/10/20 07:22:30
Oh... yes. Yes, makes sense :) Thanks!
| |
| 227 compiled_module->reset_module_bytes(); | |
| 226 ScriptData* data = wasm_cs.Serialize(compiled_module); | 228 ScriptData* data = wasm_cs.Serialize(compiled_module); |
| 229 compiled_module->set_module_bytes(wire_bytes); | |
| 227 return std::unique_ptr<ScriptData>(data); | 230 return std::unique_ptr<ScriptData>(data); |
| 228 } | 231 } |
| 229 | 232 |
| 230 MaybeHandle<FixedArray> WasmCompiledModuleSerializer::DeserializeWasmModule( | 233 MaybeHandle<FixedArray> WasmCompiledModuleSerializer::DeserializeWasmModule( |
| 231 Isolate* isolate, ScriptData* data) { | 234 Isolate* isolate, ScriptData* data, Vector<const byte> wire_bytes) { |
| 232 SerializedCodeData::SanityCheckResult sanity_check_result = | 235 SerializedCodeData::SanityCheckResult sanity_check_result = |
| 233 SerializedCodeData::CHECK_SUCCESS; | 236 SerializedCodeData::CHECK_SUCCESS; |
| 234 MaybeHandle<FixedArray> nothing; | 237 MaybeHandle<FixedArray> nothing; |
| 235 const SerializedCodeData scd = SerializedCodeData::FromCachedData( | 238 const SerializedCodeData scd = SerializedCodeData::FromCachedData( |
| 236 isolate, data, 0, &sanity_check_result); | 239 isolate, data, 0, &sanity_check_result); |
| 237 | 240 |
| 238 if (sanity_check_result != SerializedCodeData::CHECK_SUCCESS) { | 241 if (sanity_check_result != SerializedCodeData::CHECK_SUCCESS) { |
| 239 return nothing; | 242 return nothing; |
| 240 } | 243 } |
| 241 | 244 |
| 242 Deserializer deserializer(&scd, true); | 245 Deserializer deserializer(&scd, true); |
| 243 deserializer.AddAttachedObject(isolate->native_context()); | 246 deserializer.AddAttachedObject(isolate->native_context()); |
| 244 | 247 |
| 245 Vector<const uint32_t> stub_keys = scd.CodeStubKeys(); | 248 Vector<const uint32_t> stub_keys = scd.CodeStubKeys(); |
| 246 for (int i = 0; i < stub_keys.length(); ++i) { | 249 for (int i = 0; i < stub_keys.length(); ++i) { |
| 247 deserializer.AddAttachedObject( | 250 deserializer.AddAttachedObject( |
| 248 CodeStub::GetCode(isolate, stub_keys[i]).ToHandleChecked()); | 251 CodeStub::GetCode(isolate, stub_keys[i]).ToHandleChecked()); |
| 249 } | 252 } |
| 250 | 253 |
| 251 MaybeHandle<HeapObject> obj = deserializer.DeserializeObject(isolate); | 254 MaybeHandle<HeapObject> obj = deserializer.DeserializeObject(isolate); |
| 252 if (obj.is_null() || !obj.ToHandleChecked()->IsFixedArray()) return nothing; | 255 if (obj.is_null() || !obj.ToHandleChecked()->IsFixedArray()) return nothing; |
| 253 Handle<FixedArray> compiled_module = | 256 Handle<wasm::WasmCompiledModule> compiled_module = |
| 254 Handle<FixedArray>::cast(obj.ToHandleChecked()); | 257 Handle<wasm::WasmCompiledModule>::cast(obj.ToHandleChecked()); |
| 258 MaybeHandle<String> maybe_wire_bytes_as_string = | |
| 259 isolate->factory()->NewStringFromOneByte(wire_bytes, TENURED); | |
| 260 Handle<String> wire_bytes_as_string; | |
| 261 if (!maybe_wire_bytes_as_string.ToHandle(&wire_bytes_as_string)) | |
| 262 return nothing; | |
| 263 | |
| 264 compiled_module->set_module_bytes( | |
| 265 handle(SeqOneByteString::cast(*wire_bytes_as_string))); | |
| 255 wasm::WasmCompiledModule::RecreateModuleWrapper(isolate, compiled_module); | 266 wasm::WasmCompiledModule::RecreateModuleWrapper(isolate, compiled_module); |
| 256 return compiled_module; | 267 return compiled_module; |
| 257 } | 268 } |
| 258 | 269 |
| 259 class Checksum { | 270 class Checksum { |
| 260 public: | 271 public: |
| 261 explicit Checksum(Vector<const byte> payload) { | 272 explicit Checksum(Vector<const byte> payload) { |
| 262 #ifdef MEMORY_SANITIZER | 273 #ifdef MEMORY_SANITIZER |
| 263 // Computing the checksum includes padding bytes for objects like strings. | 274 // Computing the checksum includes padding bytes for objects like strings. |
| 264 // Mark every object as initialized in the code serializer. | 275 // 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); | 427 *rejection_result = scd.SanityCheck(isolate, expected_source_hash); |
| 417 if (*rejection_result != CHECK_SUCCESS) { | 428 if (*rejection_result != CHECK_SUCCESS) { |
| 418 cached_data->Reject(); | 429 cached_data->Reject(); |
| 419 return SerializedCodeData(nullptr, 0); | 430 return SerializedCodeData(nullptr, 0); |
| 420 } | 431 } |
| 421 return scd; | 432 return scd; |
| 422 } | 433 } |
| 423 | 434 |
| 424 } // namespace internal | 435 } // namespace internal |
| 425 } // namespace v8 | 436 } // namespace v8 |
| OLD | NEW |