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

Side by Side Diff: src/runtime/runtime-test.cc

Issue 2205973003: [wasm] Serialization/Deserialization of compiled module (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: disable dchecks Created 4 years, 4 months 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/runtime/runtime.h ('k') | src/snapshot/code-serializer.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/arguments.h" 9 #include "src/arguments.h"
10 #include "src/deoptimizer.h" 10 #include "src/deoptimizer.h"
11 #include "src/frames-inl.h" 11 #include "src/frames-inl.h"
12 #include "src/full-codegen/full-codegen.h" 12 #include "src/full-codegen/full-codegen.h"
13 #include "src/isolate-inl.h" 13 #include "src/isolate-inl.h"
14 #include "src/snapshot/code-serializer.h"
14 #include "src/snapshot/natives.h" 15 #include "src/snapshot/natives.h"
16 #include "src/wasm/wasm-module.h"
15 17
16 namespace v8 { 18 namespace v8 {
17 namespace internal { 19 namespace internal {
18 20
19 RUNTIME_FUNCTION(Runtime_ConstructDouble) { 21 RUNTIME_FUNCTION(Runtime_ConstructDouble) {
20 HandleScope scope(isolate); 22 HandleScope scope(isolate);
21 DCHECK(args.length() == 2); 23 DCHECK(args.length() == 2);
22 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]); 24 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]);
23 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]); 25 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]);
24 uint64_t result = (static_cast<uint64_t>(hi) << 32) | lo; 26 uint64_t result = (static_cast<uint64_t>(hi) << 32) | lo;
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 635
634 #undef FIXED_TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION 636 #undef FIXED_TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION
635 637
636 638
637 RUNTIME_FUNCTION(Runtime_SpeciesProtector) { 639 RUNTIME_FUNCTION(Runtime_SpeciesProtector) {
638 SealHandleScope shs(isolate); 640 SealHandleScope shs(isolate);
639 DCHECK_EQ(0, args.length()); 641 DCHECK_EQ(0, args.length());
640 return isolate->heap()->ToBoolean(isolate->IsArraySpeciesLookupChainIntact()); 642 return isolate->heap()->ToBoolean(isolate->IsArraySpeciesLookupChainIntact());
641 } 643 }
642 644
645 // Take a compiled wasm module, serialize it and copy the buffer into an array
646 // buffer, which is then returned.
647 RUNTIME_FUNCTION(Runtime_SerializeWasmModule) {
648 HandleScope shs(isolate);
649 DCHECK(args.length() == 1);
650 CONVERT_ARG_HANDLE_CHECKED(JSObject, module_obj, 0);
651
652 Handle<FixedArray> orig =
653 handle(FixedArray::cast(module_obj->GetInternalField(0)));
654 std::unique_ptr<ScriptData> data =
655 WasmCompiledModuleSerializer::SerializeWasmModule(isolate, orig);
656 void* buff = isolate->array_buffer_allocator()->Allocate(data->length());
657 Handle<JSArrayBuffer> ret = isolate->factory()->NewJSArrayBuffer();
658 JSArrayBuffer::Setup(ret, isolate, false, buff, data->length());
659 memcpy(buff, data->data(), data->length());
660 return *ret;
661 }
662
663 // Take an array buffer and attempt to reconstruct a compiled wasm module.
664 // Return undefined if unsuccessful.
665 RUNTIME_FUNCTION(Runtime_DeserializeWasmModule) {
666 HandleScope shs(isolate);
667 DCHECK(args.length() == 1);
668 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 0);
669
670 Address mem_start = static_cast<Address>(buffer->backing_store());
671 int mem_size = static_cast<int>(buffer->byte_length()->Number());
672
673 ScriptData sc(mem_start, mem_size);
674 MaybeHandle<FixedArray> maybe_compiled_module =
675 WasmCompiledModuleSerializer::DeserializeWasmModule(isolate, &sc);
676 Handle<FixedArray> compiled_module;
677 if (!maybe_compiled_module.ToHandle(&compiled_module)) {
678 return isolate->heap()->undefined_value();
679 }
680 return *wasm::CreateCompiledModuleObject(isolate, compiled_module);
681 }
643 682
644 } // namespace internal 683 } // namespace internal
645 } // namespace v8 684 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/snapshot/code-serializer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698