Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "src/base/atomic-utils.h" | 7 #include "src/base/atomic-utils.h" |
| 8 #include "src/code-stubs.h" | |
| 9 | |
| 8 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
| 9 #include "src/objects.h" | 11 #include "src/objects.h" |
| 10 #include "src/property-descriptor.h" | 12 #include "src/property-descriptor.h" |
| 13 #include "src/simulator.h" | |
| 14 #include "src/snapshot/snapshot.h" | |
| 11 #include "src/v8.h" | 15 #include "src/v8.h" |
| 12 | 16 |
| 13 #include "src/simulator.h" | |
| 14 | |
| 15 #include "src/wasm/ast-decoder.h" | 17 #include "src/wasm/ast-decoder.h" |
| 16 #include "src/wasm/module-decoder.h" | 18 #include "src/wasm/module-decoder.h" |
| 17 #include "src/wasm/wasm-debug.h" | 19 #include "src/wasm/wasm-debug.h" |
| 18 #include "src/wasm/wasm-function-name-table.h" | 20 #include "src/wasm/wasm-function-name-table.h" |
| 19 #include "src/wasm/wasm-module.h" | 21 #include "src/wasm/wasm-module.h" |
| 20 #include "src/wasm/wasm-result.h" | 22 #include "src/wasm/wasm-result.h" |
| 21 | 23 |
| 22 #include "src/compiler/wasm-compiler.h" | 24 #include "src/compiler/wasm-compiler.h" |
| 23 | 25 |
| 26 // DELETE THESE 2: | |
| 27 #include "src/snapshot/code-serializer.h" | |
| 28 #include "src/snapshot/deserializer.h" | |
|
Yang
2016/08/05 15:39:28
Should this be removed?
Mircea Trofin
2016/08/06 00:31:39
Done.
| |
| 29 // | |
| 30 | |
| 24 namespace v8 { | 31 namespace v8 { |
| 25 namespace internal { | 32 namespace internal { |
| 26 namespace wasm { | 33 namespace wasm { |
| 27 | 34 |
| 28 static const int kPlaceholderMarker = 1000000000; | 35 static const int kPlaceholderMarker = 1000000000; |
| 29 | 36 |
| 30 static const char* wasmSections[] = { | 37 static const char* wasmSections[] = { |
| 31 #define F(enumerator, order, string) string, | 38 #define F(enumerator, order, string) string, |
| 32 FOR_EACH_WASM_SECTION_TYPE(F) | 39 FOR_EACH_WASM_SECTION_TYPE(F) |
| 33 #undef F | 40 #undef F |
| (...skipping 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1510 table->set(static_cast<int>(i), *(*code_table)[index]); | 1517 table->set(static_cast<int>(i), *(*code_table)[index]); |
| 1511 } | 1518 } |
| 1512 } | 1519 } |
| 1513 | 1520 |
| 1514 int GetNumberOfFunctions(JSObject* wasm) { | 1521 int GetNumberOfFunctions(JSObject* wasm) { |
| 1515 Object* func_names_obj = wasm->GetInternalField(kWasmFunctionNamesArray); | 1522 Object* func_names_obj = wasm->GetInternalField(kWasmFunctionNamesArray); |
| 1516 // TODO(clemensh): this looks inside an array constructed elsewhere. Refactor. | 1523 // TODO(clemensh): this looks inside an array constructed elsewhere. Refactor. |
| 1517 return ByteArray::cast(func_names_obj)->get_int(0); | 1524 return ByteArray::cast(func_names_obj)->get_int(0); |
| 1518 } | 1525 } |
| 1519 | 1526 |
| 1527 ScriptData* SerializeWasmCompiledModule(Isolate* isolate, | |
| 1528 Handle<FixedArray> compiled_module) { | |
| 1529 CodeSerializer cs(isolate, 0); | |
| 1530 cs.reference_map()->AddAttachedReference(*isolate->native_context()); | |
|
Yang
2016/08/05 12:04:17
Can we put all this into src/snapshot in a new sub
Mircea Trofin
2016/08/05 15:01:29
Knowing we need to attach the native context is sp
Yang
2016/08/05 15:39:28
Same thing can be said for CodeSerializer::Seriali
Mircea Trofin
2016/08/06 00:31:39
Done.
I was a bit concerned that the serializer w
| |
| 1531 ScriptData* data = cs.Serialize(compiled_module); | |
| 1532 return data; | |
| 1533 } | |
| 1534 | |
| 1535 MaybeHandle<FixedArray> DeserializeWasmCompiledModule(Isolate* isolate, | |
| 1536 ScriptData* data) { | |
| 1537 SanityCheckResult sanity_check_result = CHECK_SUCCESS; | |
| 1538 MaybeHandle<FixedArray> nothing; | |
| 1539 const SerializedCodeData scd = SerializedCodeData::FromCachedData( | |
| 1540 isolate, data, 0, &sanity_check_result); | |
| 1541 | |
| 1542 if (sanity_check_result != SanityCheckResult::CHECK_SUCCESS) { | |
| 1543 return nothing; | |
| 1544 } | |
| 1545 | |
| 1546 Deserializer deserializer(&scd, true); | |
| 1547 deserializer.AddAttachedObject(isolate->native_context()); | |
| 1548 | |
| 1549 Vector<const uint32_t> stub_keys = scd.CodeStubKeys(); | |
| 1550 for (int i = 0; i < stub_keys.length(); ++i) { | |
| 1551 deserializer.AddAttachedObject( | |
| 1552 CodeStub::GetCode(isolate, stub_keys[i]).ToHandleChecked()); | |
| 1553 } | |
| 1554 | |
| 1555 MaybeHandle<HeapObject> obj = deserializer.DeserializeObject(isolate); | |
| 1556 if (obj.is_null() || !obj.ToHandleChecked()->IsFixedArray()) return nothing; | |
| 1557 return Handle<FixedArray>::cast(obj.ToHandleChecked()); | |
| 1558 } | |
| 1559 | |
| 1560 Handle<JSObject> CreateCompiledModuleObject( | |
| 1561 Isolate* isolate, Handle<FixedArray> compiled_module) { | |
| 1562 Handle<JSFunction> module_cons( | |
| 1563 isolate->native_context()->wasm_module_constructor()); | |
| 1564 Handle<JSObject> module_obj = isolate->factory()->NewJSObject(module_cons); | |
| 1565 module_obj->SetInternalField(0, *compiled_module); | |
| 1566 Handle<Symbol> module_sym(isolate->native_context()->wasm_module_sym()); | |
| 1567 Object::SetProperty(module_obj, module_sym, module_obj, STRICT).Check(); | |
| 1568 return module_obj; | |
| 1569 } | |
| 1570 | |
| 1520 namespace testing { | 1571 namespace testing { |
| 1521 | 1572 |
| 1522 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, | 1573 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, |
| 1523 const byte* module_end, bool asm_js) { | 1574 const byte* module_end, bool asm_js) { |
| 1524 HandleScope scope(isolate); | 1575 HandleScope scope(isolate); |
| 1525 Zone zone(isolate->allocator()); | 1576 Zone zone(isolate->allocator()); |
| 1526 ErrorThrower thrower(isolate, "CompileAndRunWasmModule"); | 1577 ErrorThrower thrower(isolate, "CompileAndRunWasmModule"); |
| 1527 | 1578 |
| 1528 // Decode the module, but don't verify function bodies, since we'll | 1579 // Decode the module, but don't verify function bodies, since we'll |
| 1529 // be compiling them anyway. | 1580 // be compiling them anyway. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1586 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); | 1637 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); |
| 1587 } | 1638 } |
| 1588 thrower.Error("WASM.compileRun() failed: Return value should be number"); | 1639 thrower.Error("WASM.compileRun() failed: Return value should be number"); |
| 1589 return -1; | 1640 return -1; |
| 1590 } | 1641 } |
| 1591 | 1642 |
| 1592 } // namespace testing | 1643 } // namespace testing |
| 1593 } // namespace wasm | 1644 } // namespace wasm |
| 1594 } // namespace internal | 1645 } // namespace internal |
| 1595 } // namespace v8 | 1646 } // namespace v8 |
| OLD | NEW |