Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1065)

Side by Side Diff: src/value-serializer.cc

Issue 2490663002: [wasm] Move all heap-allocated WASM structures into wasm-objects.h. (Closed)
Patch Set: [wasm] Move all heap-allocated WASM structures into wasm-objects.h. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/v8.gyp ('k') | src/wasm/wasm-debug.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/value-serializer.h" 5 #include "src/value-serializer.h"
6 6
7 #include <type_traits> 7 #include <type_traits>
8 8
9 #include "src/base/logging.h" 9 #include "src/base/logging.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
11 #include "src/factory.h" 11 #include "src/factory.h"
12 #include "src/flags.h" 12 #include "src/flags.h"
13 #include "src/handles-inl.h" 13 #include "src/handles-inl.h"
14 #include "src/isolate.h" 14 #include "src/isolate.h"
15 #include "src/objects-inl.h" 15 #include "src/objects-inl.h"
16 #include "src/objects.h" 16 #include "src/objects.h"
17 #include "src/snapshot/code-serializer.h" 17 #include "src/snapshot/code-serializer.h"
18 #include "src/transitions.h" 18 #include "src/transitions.h"
19 #include "src/wasm/wasm-module.h" 19 #include "src/wasm/wasm-module.h"
20 #include "src/wasm/wasm-objects.h"
20 #include "src/wasm/wasm-result.h" 21 #include "src/wasm/wasm-result.h"
21 22
22 namespace v8 { 23 namespace v8 {
23 namespace internal { 24 namespace internal {
24 25
25 static const uint32_t kLatestVersion = 9; 26 static const uint32_t kLatestVersion = 9;
26 static const int kPretenureThreshold = 100 * KB; 27 static const int kPretenureThreshold = 100 * KB;
27 28
28 template <typename T> 29 template <typename T>
29 static size_t BytesNeededForVarint(T value) { 30 static size_t BytesNeededForVarint(T value) {
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 DCHECK(view->IsJSDataView()); 733 DCHECK(view->IsJSDataView());
733 tag = ArrayBufferViewTag::kDataView; 734 tag = ArrayBufferViewTag::kDataView;
734 } 735 }
735 WriteVarint(static_cast<uint8_t>(tag)); 736 WriteVarint(static_cast<uint8_t>(tag));
736 WriteVarint(NumberToUint32(view->byte_offset())); 737 WriteVarint(NumberToUint32(view->byte_offset()));
737 WriteVarint(NumberToUint32(view->byte_length())); 738 WriteVarint(NumberToUint32(view->byte_length()));
738 return Just(true); 739 return Just(true);
739 } 740 }
740 741
741 Maybe<bool> ValueSerializer::WriteWasmModule(Handle<JSObject> object) { 742 Maybe<bool> ValueSerializer::WriteWasmModule(Handle<JSObject> object) {
742 Handle<wasm::WasmCompiledModule> compiled_part( 743 Handle<WasmCompiledModule> compiled_part(
743 wasm::WasmCompiledModule::cast(object->GetInternalField(0)), isolate_); 744 WasmCompiledModule::cast(object->GetInternalField(0)), isolate_);
744 WasmEncodingTag encoding_tag = WasmEncodingTag::kRawBytes; 745 WasmEncodingTag encoding_tag = WasmEncodingTag::kRawBytes;
745 WriteTag(SerializationTag::kWasmModule); 746 WriteTag(SerializationTag::kWasmModule);
746 WriteRawBytes(&encoding_tag, sizeof(encoding_tag)); 747 WriteRawBytes(&encoding_tag, sizeof(encoding_tag));
747 748
748 Handle<String> wire_bytes = compiled_part->module_bytes(); 749 Handle<String> wire_bytes = compiled_part->module_bytes();
749 int wire_bytes_length = wire_bytes->length(); 750 int wire_bytes_length = wire_bytes->length();
750 WriteVarint<uint32_t>(wire_bytes_length); 751 WriteVarint<uint32_t>(wire_bytes_length);
751 uint8_t* destination = ReserveRawBytes(wire_bytes_length); 752 uint8_t* destination = ReserveRawBytes(wire_bytes_length);
752 String::WriteToFlat(*wire_bytes, destination, 0, wire_bytes_length); 753 String::WriteToFlat(*wire_bytes, destination, 0, wire_bytes_length);
753 754
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 !ReadRawBytes(compiled_bytes_length).To(&compiled_bytes)) { 1502 !ReadRawBytes(compiled_bytes_length).To(&compiled_bytes)) {
1502 return MaybeHandle<JSObject>(); 1503 return MaybeHandle<JSObject>();
1503 } 1504 }
1504 1505
1505 // Try to deserialize the compiled module first. 1506 // Try to deserialize the compiled module first.
1506 ScriptData script_data(compiled_bytes.start(), compiled_bytes.length()); 1507 ScriptData script_data(compiled_bytes.start(), compiled_bytes.length());
1507 Handle<FixedArray> compiled_part; 1508 Handle<FixedArray> compiled_part;
1508 if (WasmCompiledModuleSerializer::DeserializeWasmModule( 1509 if (WasmCompiledModuleSerializer::DeserializeWasmModule(
1509 isolate_, &script_data, wire_bytes) 1510 isolate_, &script_data, wire_bytes)
1510 .ToHandle(&compiled_part)) { 1511 .ToHandle(&compiled_part)) {
1511 return wasm::CreateWasmModuleObject( 1512 return WasmModuleObject::New(
1512 isolate_, Handle<wasm::WasmCompiledModule>::cast(compiled_part), 1513 isolate_, Handle<WasmCompiledModule>::cast(compiled_part));
1513 wasm::ModuleOrigin::kWasmOrigin);
1514 } 1514 }
1515 1515
1516 // If that fails, recompile. 1516 // If that fails, recompile.
1517 wasm::ErrorThrower thrower(isolate_, "ValueDeserializer::ReadWasmModule"); 1517 wasm::ErrorThrower thrower(isolate_, "ValueDeserializer::ReadWasmModule");
1518 return wasm::CreateModuleObjectFromBytes( 1518 return wasm::CreateModuleObjectFromBytes(
1519 isolate_, wire_bytes.begin(), wire_bytes.end(), &thrower, 1519 isolate_, wire_bytes.begin(), wire_bytes.end(), &thrower,
1520 wasm::ModuleOrigin::kWasmOrigin, Handle<Script>::null(), nullptr, 1520 wasm::ModuleOrigin::kWasmOrigin, Handle<Script>::null(), nullptr,
1521 nullptr); 1521 nullptr);
1522 } 1522 }
1523 1523
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 if (stack.size() != 1) { 1825 if (stack.size() != 1) {
1826 isolate_->Throw(*isolate_->factory()->NewError( 1826 isolate_->Throw(*isolate_->factory()->NewError(
1827 MessageTemplate::kDataCloneDeserializationError)); 1827 MessageTemplate::kDataCloneDeserializationError));
1828 return MaybeHandle<Object>(); 1828 return MaybeHandle<Object>();
1829 } 1829 }
1830 return scope.CloseAndEscape(stack[0]); 1830 return scope.CloseAndEscape(stack[0]);
1831 } 1831 }
1832 1832
1833 } // namespace internal 1833 } // namespace internal
1834 } // namespace v8 1834 } // namespace v8
OLDNEW
« no previous file with comments | « src/v8.gyp ('k') | src/wasm/wasm-debug.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698