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" | 8 #include "src/code-stubs.h" |
9 | 9 |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
11 #include "src/objects.h" | 11 #include "src/objects.h" |
12 #include "src/property-descriptor.h" | 12 #include "src/property-descriptor.h" |
13 #include "src/simulator.h" | 13 #include "src/simulator.h" |
14 #include "src/snapshot/snapshot.h" | 14 #include "src/snapshot/snapshot.h" |
15 #include "src/v8.h" | 15 #include "src/v8.h" |
16 | 16 |
17 #include "src/wasm/ast-decoder.h" | 17 #include "src/wasm/ast-decoder.h" |
18 #include "src/wasm/module-decoder.h" | 18 #include "src/wasm/module-decoder.h" |
19 #include "src/wasm/wasm-debug.h" | 19 #include "src/wasm/wasm-debug.h" |
20 #include "src/wasm/wasm-function-name-table.h" | 20 #include "src/wasm/wasm-function-name-table.h" |
21 #include "src/wasm/wasm-js.h" | 21 #include "src/wasm/wasm-js.h" |
22 #include "src/wasm/wasm-module.h" | 22 #include "src/wasm/wasm-module.h" |
23 #include "src/wasm/wasm-result.h" | 23 #include "src/wasm/wasm-result.h" |
24 | 24 |
25 #include "src/compiler/wasm-compiler.h" | 25 #include "src/compiler/wasm-compiler.h" |
26 | 26 |
27 namespace v8 { | 27 using namespace v8::internal; |
28 namespace internal { | 28 using namespace v8::internal::wasm; |
29 namespace wasm { | 29 namespace base = v8::base; |
30 | 30 |
31 #define TRACE(...) \ | 31 #define TRACE(...) \ |
32 do { \ | 32 do { \ |
33 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \ | 33 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \ |
34 } while (false) | 34 } while (false) |
35 | 35 |
36 #define TRACE_CHAIN(instance) \ | 36 #define TRACE_CHAIN(instance) \ |
37 do { \ | 37 do { \ |
38 instance->PrintInstancesChain(); \ | 38 instance->PrintInstancesChain(); \ |
39 } while (false) | 39 } while (false) |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 Handle<Code> wasm_function = | 749 Handle<Code> wasm_function = |
750 wasm_functions->GetValueChecked<Code>(isolate, fct_index); | 750 wasm_functions->GetValueChecked<Code>(isolate, fct_index); |
751 PatchFunctionTable(wasm_function, table_to_replace, cloned_table); | 751 PatchFunctionTable(wasm_function, table_to_replace, cloned_table); |
752 } | 752 } |
753 } | 753 } |
754 return cloned_indirect_tables; | 754 return cloned_indirect_tables; |
755 } | 755 } |
756 | 756 |
757 } // namespace | 757 } // namespace |
758 | 758 |
759 const char* SectionName(WasmSectionCode code) { | 759 const char* wasm::SectionName(WasmSectionCode code) { |
760 switch (code) { | 760 switch (code) { |
761 case kUnknownSectionCode: | 761 case kUnknownSectionCode: |
762 return "Unknown"; | 762 return "Unknown"; |
763 case kTypeSectionCode: | 763 case kTypeSectionCode: |
764 return "Type"; | 764 return "Type"; |
765 case kImportSectionCode: | 765 case kImportSectionCode: |
766 return "Import"; | 766 return "Import"; |
767 case kFunctionSectionCode: | 767 case kFunctionSectionCode: |
768 return "Function"; | 768 return "Function"; |
769 case kTableSectionCode: | 769 case kTableSectionCode: |
(...skipping 12 matching lines...) Expand all Loading... |
782 return "Element"; | 782 return "Element"; |
783 case kDataSectionCode: | 783 case kDataSectionCode: |
784 return "Data"; | 784 return "Data"; |
785 case kNameSectionCode: | 785 case kNameSectionCode: |
786 return "Name"; | 786 return "Name"; |
787 default: | 787 default: |
788 return "<unknown>"; | 788 return "<unknown>"; |
789 } | 789 } |
790 } | 790 } |
791 | 791 |
792 std::ostream& operator<<(std::ostream& os, const WasmModule& module) { | 792 std::ostream& wasm::operator<<(std::ostream& os, const WasmModule& module) { |
793 os << "WASM module with "; | 793 os << "WASM module with "; |
794 os << (module.min_mem_pages * module.kPageSize) << " min mem"; | 794 os << (module.min_mem_pages * module.kPageSize) << " min mem"; |
795 os << (module.max_mem_pages * module.kPageSize) << " max mem"; | 795 os << (module.max_mem_pages * module.kPageSize) << " max mem"; |
796 os << module.functions.size() << " functions"; | 796 os << module.functions.size() << " functions"; |
797 os << module.functions.size() << " globals"; | 797 os << module.functions.size() << " globals"; |
798 os << module.functions.size() << " data segments"; | 798 os << module.functions.size() << " data segments"; |
799 return os; | 799 return os; |
800 } | 800 } |
801 | 801 |
802 std::ostream& operator<<(std::ostream& os, const WasmFunction& function) { | 802 std::ostream& wasm::operator<<(std::ostream& os, const WasmFunction& function) { |
803 os << "WASM function with signature " << *function.sig; | 803 os << "WASM function with signature " << *function.sig; |
804 | 804 |
805 os << " code bytes: " | 805 os << " code bytes: " |
806 << (function.code_end_offset - function.code_start_offset); | 806 << (function.code_end_offset - function.code_start_offset); |
807 return os; | 807 return os; |
808 } | 808 } |
809 | 809 |
810 std::ostream& operator<<(std::ostream& os, const WasmFunctionName& pair) { | 810 std::ostream& wasm::operator<<(std::ostream& os, const WasmFunctionName& pair) { |
811 os << "#" << pair.function_->func_index << ":"; | 811 os << "#" << pair.function_->func_index << ":"; |
812 if (pair.function_->name_offset > 0) { | 812 if (pair.function_->name_offset > 0) { |
813 if (pair.module_) { | 813 if (pair.module_) { |
814 WasmName name = pair.module_->GetName(pair.function_->name_offset, | 814 WasmName name = pair.module_->GetName(pair.function_->name_offset, |
815 pair.function_->name_length); | 815 pair.function_->name_length); |
816 os.write(name.start(), name.length()); | 816 os.write(name.start(), name.length()); |
817 } else { | 817 } else { |
818 os << "+" << pair.function_->func_index; | 818 os << "+" << pair.function_->func_index; |
819 } | 819 } |
820 } else { | 820 } else { |
821 os << "?"; | 821 os << "?"; |
822 } | 822 } |
823 return os; | 823 return os; |
824 } | 824 } |
825 | 825 |
826 Handle<JSFunction> WrapExportCodeAsJSFunction( | 826 Handle<JSFunction> wasm::WrapExportCodeAsJSFunction( |
827 Isolate* isolate, Handle<Code> export_code, Handle<String> name, int arity, | 827 Isolate* isolate, Handle<Code> export_code, Handle<String> name, int arity, |
828 MaybeHandle<ByteArray> maybe_signature, Handle<JSObject> module_instance) { | 828 MaybeHandle<ByteArray> maybe_signature, Handle<JSObject> module_instance) { |
829 Handle<SharedFunctionInfo> shared = | 829 Handle<SharedFunctionInfo> shared = |
830 isolate->factory()->NewSharedFunctionInfo(name, export_code, false); | 830 isolate->factory()->NewSharedFunctionInfo(name, export_code, false); |
831 shared->set_length(arity); | 831 shared->set_length(arity); |
832 shared->set_internal_formal_parameter_count(arity); | 832 shared->set_internal_formal_parameter_count(arity); |
833 Handle<JSFunction> function = isolate->factory()->NewFunction( | 833 Handle<JSFunction> function = isolate->factory()->NewFunction( |
834 isolate->wasm_function_map(), name, export_code); | 834 isolate->wasm_function_map(), name, export_code); |
835 function->set_shared(*shared); | 835 function->set_shared(*shared); |
836 | 836 |
837 function->SetInternalField(kInternalModuleInstance, *module_instance); | 837 function->SetInternalField(kInternalModuleInstance, *module_instance); |
838 // add another Internal Field as the function arity | 838 // add another Internal Field as the function arity |
839 function->SetInternalField(kInternalArity, Smi::FromInt(arity)); | 839 function->SetInternalField(kInternalArity, Smi::FromInt(arity)); |
840 // add another Internal Field as the signature of the foreign function | 840 // add another Internal Field as the signature of the foreign function |
841 Handle<ByteArray> signature; | 841 Handle<ByteArray> signature; |
842 if (maybe_signature.ToHandle(&signature)) { | 842 if (maybe_signature.ToHandle(&signature)) { |
843 function->SetInternalField(kInternalSignature, *signature); | 843 function->SetInternalField(kInternalSignature, *signature); |
844 } | 844 } |
845 return function; | 845 return function; |
846 } | 846 } |
847 | 847 |
848 Object* GetOwningWasmInstance(Code* code) { | 848 Object* wasm::GetOwningWasmInstance(Code* code) { |
849 DCHECK(code->kind() == Code::WASM_FUNCTION); | 849 DCHECK(code->kind() == Code::WASM_FUNCTION); |
850 DisallowHeapAllocation no_gc; | 850 DisallowHeapAllocation no_gc; |
851 FixedArray* deopt_data = code->deoptimization_data(); | 851 FixedArray* deopt_data = code->deoptimization_data(); |
852 DCHECK_NOT_NULL(deopt_data); | 852 DCHECK_NOT_NULL(deopt_data); |
853 DCHECK(deopt_data->length() == 2); | 853 DCHECK(deopt_data->length() == 2); |
854 Object* weak_link = deopt_data->get(0); | 854 Object* weak_link = deopt_data->get(0); |
855 if (!weak_link->IsWeakCell()) return nullptr; | 855 if (!weak_link->IsWeakCell()) return nullptr; |
856 WeakCell* cell = WeakCell::cast(weak_link); | 856 WeakCell* cell = WeakCell::cast(weak_link); |
857 return cell->value(); | 857 return cell->value(); |
858 } | 858 } |
859 | 859 |
860 int GetNumImportedFunctions(Handle<JSObject> wasm_object) { | 860 int wasm::GetNumImportedFunctions(Handle<JSObject> wasm_object) { |
861 // TODO(wasm): Cache this number if it ever becomes a performance problem. | 861 // TODO(wasm): Cache this number if it ever becomes a performance problem. |
862 DCHECK(IsWasmObject(*wasm_object)); | 862 DCHECK(IsWasmObject(*wasm_object)); |
863 WasmCompiledModule* compiled_module = GetCompiledModule(*wasm_object); | 863 WasmCompiledModule* compiled_module = GetCompiledModule(*wasm_object); |
864 Handle<FixedArray> imports = | 864 Handle<FixedArray> imports = |
865 WasmCompiledModule::cast(compiled_module)->imports(); | 865 WasmCompiledModule::cast(compiled_module)->imports(); |
866 int num_imports = imports->length(); | 866 int num_imports = imports->length(); |
867 int num_imported_functions = 0; | 867 int num_imported_functions = 0; |
868 for (int i = 0; i < num_imports; ++i) { | 868 for (int i = 0; i < num_imports; ++i) { |
869 FixedArray* encoded_import = FixedArray::cast(imports->get(i)); | 869 FixedArray* encoded_import = FixedArray::cast(imports->get(i)); |
870 int kind = Smi::cast(encoded_import->get(kImportKind))->value(); | 870 int kind = Smi::cast(encoded_import->get(kImportKind))->value(); |
871 if (kind == kExternalFunction) ++num_imported_functions; | 871 if (kind == kExternalFunction) ++num_imported_functions; |
872 } | 872 } |
873 return num_imported_functions; | 873 return num_imported_functions; |
874 } | 874 } |
875 | 875 |
876 WasmModule::WasmModule(byte* module_start) | 876 WasmModule::WasmModule(byte* module_start) |
877 : module_start(module_start), | 877 : module_start(module_start), |
878 module_end(nullptr), | 878 module_end(nullptr), |
879 min_mem_pages(0), | 879 min_mem_pages(0), |
880 max_mem_pages(0), | 880 max_mem_pages(0), |
881 mem_export(false), | 881 mem_export(false), |
882 start_function_index(-1), | 882 start_function_index(-1), |
883 origin(kWasmOrigin), | 883 origin(kWasmOrigin), |
884 globals_size(0), | 884 globals_size(0), |
885 num_imported_functions(0), | 885 num_imported_functions(0), |
886 num_declared_functions(0), | 886 num_declared_functions(0), |
887 num_exported_functions(0), | 887 num_exported_functions(0), |
888 pending_tasks(new base::Semaphore(0)) {} | 888 pending_tasks(new base::Semaphore(0)) {} |
889 | 889 |
| 890 namespace { |
| 891 |
890 void EncodeInit(const WasmModule* module, Factory* factory, | 892 void EncodeInit(const WasmModule* module, Factory* factory, |
891 Handle<FixedArray> entry, int kind_index, int value_index, | 893 Handle<FixedArray> entry, int kind_index, int value_index, |
892 const WasmInitExpr& expr) { | 894 const WasmInitExpr& expr) { |
893 entry->set(kind_index, Smi::kZero); | 895 entry->set(kind_index, Smi::kZero); |
894 | 896 |
895 Handle<Object> value; | 897 Handle<Object> value; |
896 switch (expr.kind) { | 898 switch (expr.kind) { |
897 case WasmInitExpr::kGlobalIndex: { | 899 case WasmInitExpr::kGlobalIndex: { |
898 TRACE(" kind = 1, global index %u\n", expr.val.global_index); | 900 TRACE(" kind = 1, global index %u\n", expr.val.global_index); |
899 entry->set(kind_index, Smi::FromInt(1)); | 901 entry->set(kind_index, Smi::FromInt(1)); |
(...skipping 16 matching lines...) Expand all Loading... |
916 case WasmInitExpr::kF64Const: | 918 case WasmInitExpr::kF64Const: |
917 TRACE(" kind = 0, f64 = %lf\n", expr.val.f64_const); | 919 TRACE(" kind = 0, f64 = %lf\n", expr.val.f64_const); |
918 value = factory->NewNumber(expr.val.f64_const); | 920 value = factory->NewNumber(expr.val.f64_const); |
919 break; | 921 break; |
920 default: | 922 default: |
921 UNREACHABLE(); | 923 UNREACHABLE(); |
922 } | 924 } |
923 entry->set(value_index, *value); | 925 entry->set(value_index, *value); |
924 } | 926 } |
925 | 927 |
| 928 } // namespace |
| 929 |
926 MaybeHandle<WasmCompiledModule> WasmModule::CompileFunctions( | 930 MaybeHandle<WasmCompiledModule> WasmModule::CompileFunctions( |
927 Isolate* isolate, ErrorThrower* thrower) const { | 931 Isolate* isolate, ErrorThrower* thrower) const { |
928 Factory* factory = isolate->factory(); | 932 Factory* factory = isolate->factory(); |
929 | 933 |
930 MaybeHandle<WasmCompiledModule> nothing; | 934 MaybeHandle<WasmCompiledModule> nothing; |
931 | 935 |
932 WasmModuleInstance temp_instance(this); | 936 WasmModuleInstance temp_instance(this); |
933 temp_instance.context = isolate->native_context(); | 937 temp_instance.context = isolate->native_context(); |
934 temp_instance.mem_size = GetMinModuleMemSize(this); | 938 temp_instance.mem_size = GetMinModuleMemSize(this); |
935 temp_instance.mem_start = nullptr; | 939 temp_instance.mem_start = nullptr; |
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1857 UNREACHABLE(); | 1861 UNREACHABLE(); |
1858 } | 1862 } |
1859 desc.set_value(isolate_->factory()->NewNumber(num)); | 1863 desc.set_value(isolate_->factory()->NewNumber(num)); |
1860 break; | 1864 break; |
1861 } | 1865 } |
1862 default: | 1866 default: |
1863 UNREACHABLE(); | 1867 UNREACHABLE(); |
1864 break; | 1868 break; |
1865 } | 1869 } |
1866 | 1870 |
1867 Maybe<bool> status = JSReceiver::DefineOwnProperty( | 1871 v8::Maybe<bool> status = JSReceiver::DefineOwnProperty( |
1868 isolate_, exports_object, name, &desc, Object::THROW_ON_ERROR); | 1872 isolate_, exports_object, name, &desc, Object::THROW_ON_ERROR); |
1869 if (!status.IsJust()) { | 1873 if (!status.IsJust()) { |
1870 thrower_->Error("export of %.*s failed.", name->length(), | 1874 thrower_->Error("export of %.*s failed.", name->length(), |
1871 name->ToCString().get()); | 1875 name->ToCString().get()); |
1872 return; | 1876 return; |
1873 } | 1877 } |
1874 } | 1878 } |
1875 } | 1879 } |
1876 }; | 1880 }; |
1877 | 1881 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1945 PrintF("->%d", current->instance_id()); | 1949 PrintF("->%d", current->instance_id()); |
1946 if (current->ptr_to_weak_next_instance() == nullptr) break; | 1950 if (current->ptr_to_weak_next_instance() == nullptr) break; |
1947 CHECK(!current->ptr_to_weak_next_instance()->cleared()); | 1951 CHECK(!current->ptr_to_weak_next_instance()->cleared()); |
1948 current = | 1952 current = |
1949 WasmCompiledModule::cast(current->ptr_to_weak_next_instance()->value()); | 1953 WasmCompiledModule::cast(current->ptr_to_weak_next_instance()->value()); |
1950 } | 1954 } |
1951 PrintF("\n"); | 1955 PrintF("\n"); |
1952 #endif | 1956 #endif |
1953 } | 1957 } |
1954 | 1958 |
1955 Handle<Object> GetWasmFunctionNameOrNull(Isolate* isolate, Handle<Object> wasm, | 1959 Handle<Object> wasm::GetWasmFunctionNameOrNull(Isolate* isolate, |
1956 uint32_t func_index) { | 1960 Handle<Object> wasm, |
| 1961 uint32_t func_index) { |
1957 if (!wasm->IsUndefined(isolate)) { | 1962 if (!wasm->IsUndefined(isolate)) { |
1958 DCHECK(IsWasmObject(*wasm)); | 1963 DCHECK(IsWasmObject(*wasm)); |
1959 WasmCompiledModule* compiled_module = | 1964 WasmCompiledModule* compiled_module = |
1960 GetCompiledModule(JSObject::cast(*wasm)); | 1965 GetCompiledModule(JSObject::cast(*wasm)); |
1961 Handle<ByteArray> func_names = compiled_module->function_names(); | 1966 Handle<ByteArray> func_names = compiled_module->function_names(); |
1962 // TODO(clemens): Extract this from the module bytes; skip whole function | 1967 // TODO(clemens): Extract this from the module bytes; skip whole function |
1963 // name table. | 1968 // name table. |
1964 Handle<Object> name; | 1969 Handle<Object> name; |
1965 if (GetWasmFunctionNameFromTable(func_names, func_index).ToHandle(&name)) { | 1970 if (GetWasmFunctionNameFromTable(func_names, func_index).ToHandle(&name)) { |
1966 return name; | 1971 return name; |
1967 } | 1972 } |
1968 } | 1973 } |
1969 return isolate->factory()->null_value(); | 1974 return isolate->factory()->null_value(); |
1970 } | 1975 } |
1971 | 1976 |
1972 Handle<String> GetWasmFunctionName(Isolate* isolate, Handle<Object> wasm, | 1977 Handle<String> wasm::GetWasmFunctionName(Isolate* isolate, Handle<Object> wasm, |
1973 uint32_t func_index) { | 1978 uint32_t func_index) { |
1974 Handle<Object> name_or_null = | 1979 Handle<Object> name_or_null = |
1975 GetWasmFunctionNameOrNull(isolate, wasm, func_index); | 1980 GetWasmFunctionNameOrNull(isolate, wasm, func_index); |
1976 if (!name_or_null->IsNull(isolate)) { | 1981 if (!name_or_null->IsNull(isolate)) { |
1977 return Handle<String>::cast(name_or_null); | 1982 return Handle<String>::cast(name_or_null); |
1978 } | 1983 } |
1979 return isolate->factory()->NewStringFromStaticChars("<WASM UNNAMED>"); | 1984 return isolate->factory()->NewStringFromStaticChars("<WASM UNNAMED>"); |
1980 } | 1985 } |
1981 | 1986 |
1982 bool IsWasmObject(Object* object) { | 1987 bool wasm::IsWasmObject(Object* object) { |
1983 if (!object->IsJSObject()) return false; | 1988 if (!object->IsJSObject()) return false; |
1984 | 1989 |
1985 JSObject* obj = JSObject::cast(object); | 1990 JSObject* obj = JSObject::cast(object); |
1986 Isolate* isolate = obj->GetIsolate(); | 1991 Isolate* isolate = obj->GetIsolate(); |
1987 if (obj->GetInternalFieldCount() != kWasmModuleInternalFieldCount) { | 1992 if (obj->GetInternalFieldCount() != kWasmModuleInternalFieldCount) { |
1988 return false; | 1993 return false; |
1989 } | 1994 } |
1990 | 1995 |
1991 Object* mem = obj->GetInternalField(kWasmMemArrayBuffer); | 1996 Object* mem = obj->GetInternalField(kWasmMemArrayBuffer); |
1992 if (!obj->GetInternalField(kWasmModuleCodeTable)->IsFixedArray() || | 1997 if (!obj->GetInternalField(kWasmModuleCodeTable)->IsFixedArray() || |
1993 !(mem->IsUndefined(isolate) || mem->IsJSArrayBuffer()) || | 1998 !(mem->IsUndefined(isolate) || mem->IsJSArrayBuffer()) || |
1994 !WasmCompiledModule::IsWasmCompiledModule( | 1999 !WasmCompiledModule::IsWasmCompiledModule( |
1995 obj->GetInternalField(kWasmCompiledModule))) { | 2000 obj->GetInternalField(kWasmCompiledModule))) { |
1996 return false; | 2001 return false; |
1997 } | 2002 } |
1998 | 2003 |
1999 // All checks passed. | 2004 // All checks passed. |
2000 return true; | 2005 return true; |
2001 } | 2006 } |
2002 | 2007 |
2003 WasmCompiledModule* GetCompiledModule(JSObject* wasm) { | 2008 WasmCompiledModule* wasm::GetCompiledModule(JSObject* wasm) { |
2004 return WasmCompiledModule::cast(wasm->GetInternalField(kWasmCompiledModule)); | 2009 return WasmCompiledModule::cast(wasm->GetInternalField(kWasmCompiledModule)); |
2005 } | 2010 } |
2006 | 2011 |
2007 bool WasmIsAsmJs(Object* wasm, Isolate* isolate) { | 2012 bool wasm::WasmIsAsmJs(Object* wasm, Isolate* isolate) { |
2008 if (wasm->IsUndefined(isolate)) return false; | 2013 if (wasm->IsUndefined(isolate)) return false; |
2009 DCHECK(IsWasmObject(wasm)); | 2014 DCHECK(IsWasmObject(wasm)); |
2010 WasmCompiledModule* compiled_module = GetCompiledModule(JSObject::cast(wasm)); | 2015 WasmCompiledModule* compiled_module = GetCompiledModule(JSObject::cast(wasm)); |
2011 return compiled_module->has_asm_js_script(); | 2016 return compiled_module->has_asm_js_script(); |
2012 } | 2017 } |
2013 | 2018 |
2014 Handle<Script> GetAsmWasmScript(Handle<JSObject> wasm) { | 2019 Handle<Script> wasm::GetAsmWasmScript(Handle<JSObject> wasm) { |
2015 DCHECK(IsWasmObject(*wasm)); | 2020 DCHECK(IsWasmObject(*wasm)); |
2016 WasmCompiledModule* compiled_module = GetCompiledModule(*wasm); | 2021 WasmCompiledModule* compiled_module = GetCompiledModule(*wasm); |
2017 return compiled_module->asm_js_script(); | 2022 return compiled_module->asm_js_script(); |
2018 } | 2023 } |
2019 | 2024 |
2020 int GetAsmWasmSourcePosition(Handle<JSObject> wasm, int func_index, | 2025 int wasm::GetAsmWasmSourcePosition(Handle<JSObject> wasm, int func_index, |
2021 int byte_offset) { | 2026 int byte_offset) { |
2022 return WasmDebugInfo::GetAsmJsSourcePosition(GetDebugInfo(wasm), func_index, | 2027 return WasmDebugInfo::GetAsmJsSourcePosition(GetDebugInfo(wasm), func_index, |
2023 byte_offset); | 2028 byte_offset); |
2024 } | 2029 } |
2025 | 2030 |
2026 Handle<SeqOneByteString> GetWasmBytes(Handle<JSObject> wasm) { | 2031 Handle<SeqOneByteString> wasm::GetWasmBytes(Handle<JSObject> wasm) { |
2027 DCHECK(IsWasmObject(*wasm)); | 2032 DCHECK(IsWasmObject(*wasm)); |
2028 WasmCompiledModule* compiled_module = GetCompiledModule(*wasm); | 2033 WasmCompiledModule* compiled_module = GetCompiledModule(*wasm); |
2029 return compiled_module->module_bytes(); | 2034 return compiled_module->module_bytes(); |
2030 } | 2035 } |
2031 | 2036 |
2032 Handle<WasmDebugInfo> GetDebugInfo(Handle<JSObject> wasm) { | 2037 Handle<WasmDebugInfo> wasm::GetDebugInfo(Handle<JSObject> wasm) { |
2033 Handle<Object> info(wasm->GetInternalField(kWasmDebugInfo), | 2038 Handle<Object> info(wasm->GetInternalField(kWasmDebugInfo), |
2034 wasm->GetIsolate()); | 2039 wasm->GetIsolate()); |
2035 if (!info->IsUndefined(wasm->GetIsolate())) | 2040 if (!info->IsUndefined(wasm->GetIsolate())) |
2036 return Handle<WasmDebugInfo>::cast(info); | 2041 return Handle<WasmDebugInfo>::cast(info); |
2037 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(wasm); | 2042 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(wasm); |
2038 wasm->SetInternalField(kWasmDebugInfo, *new_info); | 2043 wasm->SetInternalField(kWasmDebugInfo, *new_info); |
2039 return new_info; | 2044 return new_info; |
2040 } | 2045 } |
2041 | 2046 |
2042 bool UpdateWasmModuleMemory(Handle<JSObject> object, Address old_start, | 2047 bool wasm::UpdateWasmModuleMemory(Handle<JSObject> object, Address old_start, |
2043 Address new_start, uint32_t old_size, | 2048 Address new_start, uint32_t old_size, |
2044 uint32_t new_size) { | 2049 uint32_t new_size) { |
2045 DisallowHeapAllocation no_allocation; | 2050 DisallowHeapAllocation no_allocation; |
2046 if (!IsWasmObject(*object)) { | 2051 if (!IsWasmObject(*object)) { |
2047 return false; | 2052 return false; |
2048 } | 2053 } |
2049 | 2054 |
2050 // Get code table associated with the module js_object | 2055 // Get code table associated with the module js_object |
2051 Object* obj = object->GetInternalField(kWasmModuleCodeTable); | 2056 Object* obj = object->GetInternalField(kWasmModuleCodeTable); |
2052 Handle<FixedArray> code_table(FixedArray::cast(obj)); | 2057 Handle<FixedArray> code_table(FixedArray::cast(obj)); |
2053 | 2058 |
2054 // Iterate through the code objects in the code table and update relocation | 2059 // Iterate through the code objects in the code table and update relocation |
2055 // information | 2060 // information |
2056 for (int i = 0; i < code_table->length(); ++i) { | 2061 for (int i = 0; i < code_table->length(); ++i) { |
2057 obj = code_table->get(i); | 2062 obj = code_table->get(i); |
2058 Handle<Code> code(Code::cast(obj)); | 2063 Handle<Code> code(Code::cast(obj)); |
2059 | 2064 |
2060 int mode_mask = RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_REFERENCE) | | 2065 int mode_mask = RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_REFERENCE) | |
2061 RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_SIZE_REFERENCE); | 2066 RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_SIZE_REFERENCE); |
2062 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { | 2067 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
2063 RelocInfo::Mode mode = it.rinfo()->rmode(); | 2068 RelocInfo::Mode mode = it.rinfo()->rmode(); |
2064 if (RelocInfo::IsWasmMemoryReference(mode) || | 2069 if (RelocInfo::IsWasmMemoryReference(mode) || |
2065 RelocInfo::IsWasmMemorySizeReference(mode)) { | 2070 RelocInfo::IsWasmMemorySizeReference(mode)) { |
2066 it.rinfo()->update_wasm_memory_reference(old_start, new_start, old_size, | 2071 it.rinfo()->update_wasm_memory_reference(old_start, new_start, old_size, |
2067 new_size); | 2072 new_size); |
2068 } | 2073 } |
2069 } | 2074 } |
2070 } | 2075 } |
2071 return true; | 2076 return true; |
2072 } | 2077 } |
2073 | 2078 |
2074 Handle<FixedArray> BuildFunctionTable(Isolate* isolate, uint32_t index, | 2079 Handle<FixedArray> wasm::BuildFunctionTable(Isolate* isolate, uint32_t index, |
2075 const WasmModule* module) { | 2080 const WasmModule* module) { |
2076 const WasmIndirectFunctionTable* table = &module->function_tables[index]; | 2081 const WasmIndirectFunctionTable* table = &module->function_tables[index]; |
2077 DCHECK_EQ(table->size, table->values.size()); | 2082 DCHECK_EQ(table->size, table->values.size()); |
2078 DCHECK_GE(table->max_size, table->size); | 2083 DCHECK_GE(table->max_size, table->size); |
2079 Handle<FixedArray> values = | 2084 Handle<FixedArray> values = |
2080 isolate->factory()->NewFixedArray(2 * table->max_size, TENURED); | 2085 isolate->factory()->NewFixedArray(2 * table->max_size, TENURED); |
2081 for (uint32_t i = 0; i < table->size; ++i) { | 2086 for (uint32_t i = 0; i < table->size; ++i) { |
2082 const WasmFunction* function = &module->functions[table->values[i]]; | 2087 const WasmFunction* function = &module->functions[table->values[i]]; |
2083 int32_t index = table->map.Find(function->sig); | 2088 int32_t index = table->map.Find(function->sig); |
2084 DCHECK_GE(index, 0); | 2089 DCHECK_GE(index, 0); |
2085 values->set(i, Smi::FromInt(index)); | 2090 values->set(i, Smi::FromInt(index)); |
2086 values->set(i + table->max_size, Smi::FromInt(table->values[i])); | 2091 values->set(i + table->max_size, Smi::FromInt(table->values[i])); |
2087 } | 2092 } |
2088 // Set the remaining elements to -1 (instead of "undefined"). These | 2093 // Set the remaining elements to -1 (instead of "undefined"). These |
2089 // elements are accessed directly as SMIs (without a check). On 64-bit | 2094 // elements are accessed directly as SMIs (without a check). On 64-bit |
2090 // platforms, it is possible to have the top bits of "undefined" take | 2095 // platforms, it is possible to have the top bits of "undefined" take |
2091 // small integer values (or zero), which are more likely to be equal to | 2096 // small integer values (or zero), which are more likely to be equal to |
2092 // the signature index we check against. | 2097 // the signature index we check against. |
2093 for (uint32_t i = table->size; i < table->max_size; ++i) { | 2098 for (uint32_t i = table->size; i < table->max_size; ++i) { |
2094 values->set(i, Smi::FromInt(-1)); | 2099 values->set(i, Smi::FromInt(-1)); |
2095 } | 2100 } |
2096 return values; | 2101 return values; |
2097 } | 2102 } |
2098 | 2103 |
2099 void PopulateFunctionTable(Handle<FixedArray> table, uint32_t table_size, | 2104 void wasm::PopulateFunctionTable(Handle<FixedArray> table, uint32_t table_size, |
2100 const std::vector<Handle<Code>>* code_table) { | 2105 const std::vector<Handle<Code>>* code_table) { |
2101 uint32_t max_size = table->length() / 2; | 2106 uint32_t max_size = table->length() / 2; |
2102 for (uint32_t i = max_size; i < max_size + table_size; ++i) { | 2107 for (uint32_t i = max_size; i < max_size + table_size; ++i) { |
2103 int index = Smi::cast(table->get(static_cast<int>(i)))->value(); | 2108 int index = Smi::cast(table->get(static_cast<int>(i)))->value(); |
2104 DCHECK_GE(index, 0); | 2109 DCHECK_GE(index, 0); |
2105 DCHECK_LT(static_cast<size_t>(index), code_table->size()); | 2110 DCHECK_LT(static_cast<size_t>(index), code_table->size()); |
2106 table->set(static_cast<int>(i), *(*code_table)[index]); | 2111 table->set(static_cast<int>(i), *(*code_table)[index]); |
2107 } | 2112 } |
2108 } | 2113 } |
2109 | 2114 |
2110 int GetNumberOfFunctions(Handle<JSObject> wasm) { | 2115 int wasm::GetNumberOfFunctions(Handle<JSObject> wasm) { |
2111 DCHECK(IsWasmObject(*wasm)); | 2116 DCHECK(IsWasmObject(*wasm)); |
2112 WasmCompiledModule* compiled_module = GetCompiledModule(*wasm); | 2117 WasmCompiledModule* compiled_module = GetCompiledModule(*wasm); |
2113 ByteArray* func_names_arr = compiled_module->ptr_to_function_names(); | 2118 ByteArray* func_names_arr = compiled_module->ptr_to_function_names(); |
2114 // TODO(clemensh): this looks inside an array constructed elsewhere. Refactor. | 2119 // TODO(clemensh): this looks inside an array constructed elsewhere. Refactor. |
2115 return func_names_arr->get_int(0); | 2120 return func_names_arr->get_int(0); |
2116 } | 2121 } |
2117 | 2122 |
2118 Handle<JSObject> CreateCompiledModuleObject( | 2123 Handle<JSObject> wasm::CreateCompiledModuleObject( |
2119 Isolate* isolate, Handle<WasmCompiledModule> compiled_module, | 2124 Isolate* isolate, Handle<WasmCompiledModule> compiled_module, |
2120 ModuleOrigin origin) { | 2125 ModuleOrigin origin) { |
2121 Handle<JSObject> module_obj; | 2126 Handle<JSObject> module_obj; |
2122 if (origin == ModuleOrigin::kWasmOrigin) { | 2127 if (origin == ModuleOrigin::kWasmOrigin) { |
2123 Handle<JSFunction> module_cons( | 2128 Handle<JSFunction> module_cons( |
2124 isolate->native_context()->wasm_module_constructor()); | 2129 isolate->native_context()->wasm_module_constructor()); |
2125 module_obj = isolate->factory()->NewJSObject(module_cons); | 2130 module_obj = isolate->factory()->NewJSObject(module_cons); |
2126 } else { | 2131 } else { |
2127 DCHECK(origin == ModuleOrigin::kAsmJsOrigin); | 2132 DCHECK(origin == ModuleOrigin::kAsmJsOrigin); |
2128 Handle<Map> map = isolate->factory()->NewMap( | 2133 Handle<Map> map = isolate->factory()->NewMap( |
2129 JS_OBJECT_TYPE, JSObject::kHeaderSize + kPointerSize); | 2134 JS_OBJECT_TYPE, JSObject::kHeaderSize + kPointerSize); |
2130 module_obj = isolate->factory()->NewJSObjectFromMap(map, TENURED); | 2135 module_obj = isolate->factory()->NewJSObjectFromMap(map, TENURED); |
2131 } | 2136 } |
2132 module_obj->SetInternalField(0, *compiled_module); | 2137 module_obj->SetInternalField(0, *compiled_module); |
2133 if (origin == ModuleOrigin::kWasmOrigin) { | 2138 if (origin == ModuleOrigin::kWasmOrigin) { |
2134 Handle<Symbol> module_sym(isolate->native_context()->wasm_module_sym()); | 2139 Handle<Symbol> module_sym(isolate->native_context()->wasm_module_sym()); |
2135 Object::SetProperty(module_obj, module_sym, module_obj, STRICT).Check(); | 2140 Object::SetProperty(module_obj, module_sym, module_obj, STRICT).Check(); |
2136 } | 2141 } |
2137 Handle<WeakCell> link_to_module = isolate->factory()->NewWeakCell(module_obj); | 2142 Handle<WeakCell> link_to_module = isolate->factory()->NewWeakCell(module_obj); |
2138 compiled_module->set_weak_module_object(link_to_module); | 2143 compiled_module->set_weak_module_object(link_to_module); |
2139 return module_obj; | 2144 return module_obj; |
2140 } | 2145 } |
2141 | 2146 |
2142 // TODO(clemensh): origin can be inferred from asm_js_script; remove it. | 2147 // TODO(clemensh): origin can be inferred from asm_js_script; remove it. |
2143 MaybeHandle<JSObject> CreateModuleObjectFromBytes( | 2148 MaybeHandle<JSObject> wasm::CreateModuleObjectFromBytes( |
2144 Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower, | 2149 Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower, |
2145 ModuleOrigin origin, Handle<Script> asm_js_script, | 2150 ModuleOrigin origin, Handle<Script> asm_js_script, |
2146 const byte* asm_js_offset_tables_start, | 2151 const byte* asm_js_offset_tables_start, |
2147 const byte* asm_js_offset_tables_end) { | 2152 const byte* asm_js_offset_tables_end) { |
2148 MaybeHandle<JSObject> nothing; | 2153 MaybeHandle<JSObject> nothing; |
2149 Zone zone(isolate->allocator()); | 2154 Zone zone(isolate->allocator()); |
2150 ModuleResult result = | 2155 ModuleResult result = |
2151 DecodeWasmModule(isolate, &zone, start, end, false, origin); | 2156 DecodeWasmModule(isolate, &zone, start, end, false, origin); |
2152 std::unique_ptr<const WasmModule> decoded_module(result.val); | 2157 std::unique_ptr<const WasmModule> decoded_module(result.val); |
2153 if (result.failed()) { | 2158 if (result.failed()) { |
(...skipping 17 matching lines...) Expand all Loading... |
2171 Handle<ByteArray> offset_tables = | 2176 Handle<ByteArray> offset_tables = |
2172 isolate->factory()->NewByteArray(static_cast<int>(offset_tables_len)); | 2177 isolate->factory()->NewByteArray(static_cast<int>(offset_tables_len)); |
2173 memcpy(offset_tables->GetDataStartAddress(), asm_js_offset_tables_start, | 2178 memcpy(offset_tables->GetDataStartAddress(), asm_js_offset_tables_start, |
2174 offset_tables_len); | 2179 offset_tables_len); |
2175 compiled_module->set_asm_js_offset_tables(offset_tables); | 2180 compiled_module->set_asm_js_offset_tables(offset_tables); |
2176 } | 2181 } |
2177 | 2182 |
2178 return CreateCompiledModuleObject(isolate, compiled_module, origin); | 2183 return CreateCompiledModuleObject(isolate, compiled_module, origin); |
2179 } | 2184 } |
2180 | 2185 |
2181 bool ValidateModuleBytes(Isolate* isolate, const byte* start, const byte* end, | 2186 bool wasm::ValidateModuleBytes(Isolate* isolate, const byte* start, |
2182 ErrorThrower* thrower, ModuleOrigin origin) { | 2187 const byte* end, ErrorThrower* thrower, |
| 2188 ModuleOrigin origin) { |
2183 Zone zone(isolate->allocator()); | 2189 Zone zone(isolate->allocator()); |
2184 ModuleResult result = | 2190 ModuleResult result = |
2185 DecodeWasmModule(isolate, &zone, start, end, false, origin); | 2191 DecodeWasmModule(isolate, &zone, start, end, false, origin); |
2186 if (result.ok()) { | 2192 if (result.ok()) { |
2187 DCHECK_NOT_NULL(result.val); | 2193 DCHECK_NOT_NULL(result.val); |
2188 delete result.val; | 2194 delete result.val; |
2189 return true; | 2195 return true; |
2190 } | 2196 } |
2191 return false; | 2197 return false; |
2192 } | 2198 } |
2193 | 2199 |
| 2200 namespace { |
| 2201 |
2194 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, | 2202 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, |
2195 Handle<JSObject> instance) { | 2203 Handle<JSObject> instance) { |
2196 Object* mem = instance->GetInternalField(kWasmMemArrayBuffer); | 2204 Object* mem = instance->GetInternalField(kWasmMemArrayBuffer); |
2197 DCHECK(IsWasmObject(*instance)); | 2205 DCHECK(IsWasmObject(*instance)); |
2198 if (mem->IsUndefined(isolate)) return MaybeHandle<JSArrayBuffer>(); | 2206 if (mem->IsUndefined(isolate)) return MaybeHandle<JSArrayBuffer>(); |
2199 return Handle<JSArrayBuffer>(JSArrayBuffer::cast(mem)); | 2207 return Handle<JSArrayBuffer>(JSArrayBuffer::cast(mem)); |
2200 } | 2208 } |
2201 | 2209 |
2202 void SetInstanceMemory(Handle<JSObject> instance, JSArrayBuffer* buffer) { | 2210 void SetInstanceMemory(Handle<JSObject> instance, JSArrayBuffer* buffer) { |
2203 DisallowHeapAllocation no_gc; | 2211 DisallowHeapAllocation no_gc; |
2204 DCHECK(IsWasmObject(*instance)); | 2212 DCHECK(IsWasmObject(*instance)); |
2205 instance->SetInternalField(kWasmMemArrayBuffer, buffer); | 2213 instance->SetInternalField(kWasmMemArrayBuffer, buffer); |
2206 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); | 2214 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); |
2207 compiled_module->set_ptr_to_heap(buffer); | 2215 compiled_module->set_ptr_to_heap(buffer); |
2208 } | 2216 } |
2209 | 2217 |
2210 int32_t GetInstanceMemorySize(Isolate* isolate, Handle<JSObject> instance) { | 2218 } // namespace |
| 2219 |
| 2220 int32_t wasm::GetInstanceMemorySize(Isolate* isolate, |
| 2221 Handle<JSObject> instance) { |
2211 MaybeHandle<JSArrayBuffer> maybe_mem_buffer = | 2222 MaybeHandle<JSArrayBuffer> maybe_mem_buffer = |
2212 GetInstanceMemory(isolate, instance); | 2223 GetInstanceMemory(isolate, instance); |
2213 Handle<JSArrayBuffer> buffer; | 2224 Handle<JSArrayBuffer> buffer; |
2214 if (!maybe_mem_buffer.ToHandle(&buffer)) { | 2225 if (!maybe_mem_buffer.ToHandle(&buffer)) { |
2215 return 0; | 2226 return 0; |
2216 } else { | 2227 } else { |
2217 return buffer->byte_length()->Number() / WasmModule::kPageSize; | 2228 return buffer->byte_length()->Number() / WasmModule::kPageSize; |
2218 } | 2229 } |
2219 } | 2230 } |
2220 | 2231 |
2221 int32_t GrowInstanceMemory(Isolate* isolate, Handle<JSObject> instance, | 2232 int32_t wasm::GrowInstanceMemory(Isolate* isolate, Handle<JSObject> instance, |
2222 uint32_t pages) { | 2233 uint32_t pages) { |
2223 if (pages == 0) { | 2234 if (pages == 0) { |
2224 return GetInstanceMemorySize(isolate, instance); | 2235 return GetInstanceMemorySize(isolate, instance); |
2225 } | 2236 } |
2226 Address old_mem_start = nullptr; | 2237 Address old_mem_start = nullptr; |
2227 uint32_t old_size = 0, new_size = 0; | 2238 uint32_t old_size = 0, new_size = 0; |
2228 | 2239 |
2229 MaybeHandle<JSArrayBuffer> maybe_mem_buffer = | 2240 MaybeHandle<JSArrayBuffer> maybe_mem_buffer = |
2230 GetInstanceMemory(isolate, instance); | 2241 GetInstanceMemory(isolate, instance); |
2231 Handle<JSArrayBuffer> old_buffer; | 2242 Handle<JSArrayBuffer> old_buffer; |
2232 if (!maybe_mem_buffer.ToHandle(&old_buffer)) { | 2243 if (!maybe_mem_buffer.ToHandle(&old_buffer)) { |
(...skipping 27 matching lines...) Expand all Loading... |
2260 } | 2271 } |
2261 SetInstanceMemory(instance, *buffer); | 2272 SetInstanceMemory(instance, *buffer); |
2262 if (!UpdateWasmModuleMemory(instance, old_mem_start, new_mem_start, old_size, | 2273 if (!UpdateWasmModuleMemory(instance, old_mem_start, new_mem_start, old_size, |
2263 new_size)) { | 2274 new_size)) { |
2264 return -1; | 2275 return -1; |
2265 } | 2276 } |
2266 DCHECK(old_size % WasmModule::kPageSize == 0); | 2277 DCHECK(old_size % WasmModule::kPageSize == 0); |
2267 return (old_size / WasmModule::kPageSize); | 2278 return (old_size / WasmModule::kPageSize); |
2268 } | 2279 } |
2269 | 2280 |
2270 namespace testing { | 2281 void testing::ValidateInstancesChain(Isolate* isolate, |
2271 | 2282 Handle<JSObject> module_obj, |
2272 void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> module_obj, | 2283 int instance_count) { |
2273 int instance_count) { | |
2274 CHECK_GE(instance_count, 0); | 2284 CHECK_GE(instance_count, 0); |
2275 DisallowHeapAllocation no_gc; | 2285 DisallowHeapAllocation no_gc; |
2276 WasmCompiledModule* compiled_module = | 2286 WasmCompiledModule* compiled_module = |
2277 WasmCompiledModule::cast(module_obj->GetInternalField(0)); | 2287 WasmCompiledModule::cast(module_obj->GetInternalField(0)); |
2278 CHECK_EQ( | 2288 CHECK_EQ( |
2279 JSObject::cast(compiled_module->ptr_to_weak_module_object()->value()), | 2289 JSObject::cast(compiled_module->ptr_to_weak_module_object()->value()), |
2280 *module_obj); | 2290 *module_obj); |
2281 Object* prev = nullptr; | 2291 Object* prev = nullptr; |
2282 int found_instances = compiled_module->has_weak_owning_instance() ? 1 : 0; | 2292 int found_instances = compiled_module->has_weak_owning_instance() ? 1 : 0; |
2283 WasmCompiledModule* current_instance = compiled_module; | 2293 WasmCompiledModule* current_instance = compiled_module; |
2284 while (current_instance->has_weak_next_instance()) { | 2294 while (current_instance->has_weak_next_instance()) { |
2285 CHECK((prev == nullptr && !current_instance->has_weak_prev_instance()) || | 2295 CHECK((prev == nullptr && !current_instance->has_weak_prev_instance()) || |
2286 current_instance->ptr_to_weak_prev_instance()->value() == prev); | 2296 current_instance->ptr_to_weak_prev_instance()->value() == prev); |
2287 CHECK_EQ(current_instance->ptr_to_weak_module_object()->value(), | 2297 CHECK_EQ(current_instance->ptr_to_weak_module_object()->value(), |
2288 *module_obj); | 2298 *module_obj); |
2289 CHECK( | 2299 CHECK( |
2290 IsWasmObject(current_instance->ptr_to_weak_owning_instance()->value())); | 2300 IsWasmObject(current_instance->ptr_to_weak_owning_instance()->value())); |
2291 prev = current_instance; | 2301 prev = current_instance; |
2292 current_instance = WasmCompiledModule::cast( | 2302 current_instance = WasmCompiledModule::cast( |
2293 current_instance->ptr_to_weak_next_instance()->value()); | 2303 current_instance->ptr_to_weak_next_instance()->value()); |
2294 ++found_instances; | 2304 ++found_instances; |
2295 CHECK_LE(found_instances, instance_count); | 2305 CHECK_LE(found_instances, instance_count); |
2296 } | 2306 } |
2297 CHECK_EQ(found_instances, instance_count); | 2307 CHECK_EQ(found_instances, instance_count); |
2298 } | 2308 } |
2299 | 2309 |
2300 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj) { | 2310 void testing::ValidateModuleState(Isolate* isolate, |
| 2311 Handle<JSObject> module_obj) { |
2301 DisallowHeapAllocation no_gc; | 2312 DisallowHeapAllocation no_gc; |
2302 WasmCompiledModule* compiled_module = | 2313 WasmCompiledModule* compiled_module = |
2303 WasmCompiledModule::cast(module_obj->GetInternalField(0)); | 2314 WasmCompiledModule::cast(module_obj->GetInternalField(0)); |
2304 CHECK(compiled_module->has_weak_module_object()); | 2315 CHECK(compiled_module->has_weak_module_object()); |
2305 CHECK_EQ(compiled_module->ptr_to_weak_module_object()->value(), *module_obj); | 2316 CHECK_EQ(compiled_module->ptr_to_weak_module_object()->value(), *module_obj); |
2306 CHECK(!compiled_module->has_weak_prev_instance()); | 2317 CHECK(!compiled_module->has_weak_prev_instance()); |
2307 CHECK(!compiled_module->has_weak_next_instance()); | 2318 CHECK(!compiled_module->has_weak_next_instance()); |
2308 CHECK(!compiled_module->has_weak_owning_instance()); | 2319 CHECK(!compiled_module->has_weak_owning_instance()); |
2309 } | 2320 } |
2310 | 2321 |
2311 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance) { | 2322 void testing::ValidateOrphanedInstance(Isolate* isolate, |
| 2323 Handle<JSObject> instance) { |
2312 DisallowHeapAllocation no_gc; | 2324 DisallowHeapAllocation no_gc; |
2313 CHECK(IsWasmObject(*instance)); | 2325 CHECK(IsWasmObject(*instance)); |
2314 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); | 2326 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); |
2315 CHECK(compiled_module->has_weak_module_object()); | 2327 CHECK(compiled_module->has_weak_module_object()); |
2316 CHECK(compiled_module->ptr_to_weak_module_object()->cleared()); | 2328 CHECK(compiled_module->ptr_to_weak_module_object()->cleared()); |
2317 } | 2329 } |
2318 | |
2319 } // namespace testing | |
2320 } // namespace wasm | |
2321 } // namespace internal | |
2322 } // namespace v8 | |
OLD | NEW |