| 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 "src/wasm/wasm-objects.h" | 5 #include "src/wasm/wasm-objects.h" |
| 6 #include "src/utils.h" | 6 #include "src/utils.h" |
| 7 | 7 |
| 8 #include "src/assembler-inl.h" | 8 #include "src/assembler-inl.h" |
| 9 #include "src/base/iterator.h" | 9 #include "src/base/iterator.h" |
| 10 #include "src/compiler/wasm-compiler.h" | 10 #include "src/compiler/wasm-compiler.h" |
| (...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 Handle<WasmSharedModuleData> shared) { | 940 Handle<WasmSharedModuleData> shared) { |
| 941 if (shared->has_lazy_compilation_orchestrator()) return; | 941 if (shared->has_lazy_compilation_orchestrator()) return; |
| 942 Isolate* isolate = shared->GetIsolate(); | 942 Isolate* isolate = shared->GetIsolate(); |
| 943 LazyCompilationOrchestrator* orch = new LazyCompilationOrchestrator(); | 943 LazyCompilationOrchestrator* orch = new LazyCompilationOrchestrator(); |
| 944 Handle<Managed<LazyCompilationOrchestrator>> orch_handle = | 944 Handle<Managed<LazyCompilationOrchestrator>> orch_handle = |
| 945 Managed<LazyCompilationOrchestrator>::New(isolate, orch); | 945 Managed<LazyCompilationOrchestrator>::New(isolate, orch); |
| 946 shared->set(WasmSharedModuleData::kLazyCompilationOrchestrator, *orch_handle); | 946 shared->set(WasmSharedModuleData::kLazyCompilationOrchestrator, *orch_handle); |
| 947 } | 947 } |
| 948 | 948 |
| 949 Handle<WasmCompiledModule> WasmCompiledModule::New( | 949 Handle<WasmCompiledModule> WasmCompiledModule::New( |
| 950 Isolate* isolate, Handle<WasmSharedModuleData> shared) { | 950 Isolate* isolate, Handle<WasmSharedModuleData> shared, |
| 951 Handle<FixedArray> code_table, |
| 952 MaybeHandle<FixedArray> maybe_empty_function_tables, |
| 953 MaybeHandle<FixedArray> maybe_signature_tables) { |
| 951 Handle<FixedArray> ret = | 954 Handle<FixedArray> ret = |
| 952 isolate->factory()->NewFixedArray(PropertyIndices::Count, TENURED); | 955 isolate->factory()->NewFixedArray(PropertyIndices::Count, TENURED); |
| 953 // WasmCompiledModule::cast would fail since fields are not set yet. | 956 // WasmCompiledModule::cast would fail since fields are not set yet. |
| 954 Handle<WasmCompiledModule> compiled_module( | 957 Handle<WasmCompiledModule> compiled_module( |
| 955 reinterpret_cast<WasmCompiledModule*>(*ret), isolate); | 958 reinterpret_cast<WasmCompiledModule*>(*ret), isolate); |
| 956 compiled_module->InitId(); | 959 compiled_module->InitId(); |
| 957 compiled_module->set_num_imported_functions(0); | |
| 958 compiled_module->set_shared(shared); | 960 compiled_module->set_shared(shared); |
| 959 compiled_module->set_native_context(isolate->native_context()); | 961 compiled_module->set_native_context(isolate->native_context()); |
| 962 compiled_module->set_code_table(code_table); |
| 963 int function_table_count = |
| 964 static_cast<int>(shared->module()->function_tables.size()); |
| 965 if (function_table_count > 0) { |
| 966 compiled_module->set_signature_tables( |
| 967 maybe_signature_tables.ToHandleChecked()); |
| 968 compiled_module->set_empty_function_tables( |
| 969 maybe_empty_function_tables.ToHandleChecked()); |
| 970 } |
| 971 // TODO(mtrofin): we copy these because the order of finalization isn't |
| 972 // reliable, and we need some of these at Reset (which is called at |
| 973 // finalization). If the order were reliable, and top-down, we could instead |
| 974 // just get them from shared(). |
| 975 compiled_module->set_min_mem_pages(shared->module()->min_mem_pages); |
| 976 compiled_module->set_max_mem_pages(shared->module()->max_mem_pages); |
| 977 compiled_module->set_num_imported_functions( |
| 978 shared->module()->num_imported_functions); |
| 960 return compiled_module; | 979 return compiled_module; |
| 961 } | 980 } |
| 962 | 981 |
| 963 Handle<WasmCompiledModule> WasmCompiledModule::Clone( | 982 Handle<WasmCompiledModule> WasmCompiledModule::Clone( |
| 964 Isolate* isolate, Handle<WasmCompiledModule> module) { | 983 Isolate* isolate, Handle<WasmCompiledModule> module) { |
| 984 Handle<FixedArray> code_copy = |
| 985 isolate->factory()->CopyFixedArray(module->code_table()); |
| 965 Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast( | 986 Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast( |
| 966 isolate->factory()->CopyFixedArray(module)); | 987 isolate->factory()->CopyFixedArray(module)); |
| 967 ret->InitId(); | 988 ret->InitId(); |
| 989 ret->set_code_table(code_copy); |
| 968 ret->reset_weak_owning_instance(); | 990 ret->reset_weak_owning_instance(); |
| 969 ret->reset_weak_next_instance(); | 991 ret->reset_weak_next_instance(); |
| 970 ret->reset_weak_prev_instance(); | 992 ret->reset_weak_prev_instance(); |
| 971 ret->reset_weak_exported_functions(); | 993 ret->reset_weak_exported_functions(); |
| 972 if (ret->has_embedded_mem_start()) { | 994 if (ret->has_embedded_mem_start()) { |
| 973 WasmCompiledModule::recreate_embedded_mem_start(ret, isolate->factory(), | 995 WasmCompiledModule::recreate_embedded_mem_start(ret, isolate->factory(), |
| 974 ret->embedded_mem_start()); | 996 ret->embedded_mem_start()); |
| 975 } | 997 } |
| 976 if (ret->has_globals_start()) { | 998 if (ret->has_globals_start()) { |
| 977 WasmCompiledModule::recreate_globals_start(ret, isolate->factory(), | 999 WasmCompiledModule::recreate_globals_start(ret, isolate->factory(), |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 if (arr->length() != PropertyIndices::Count) return false; | 1148 if (arr->length() != PropertyIndices::Count) return false; |
| 1127 Isolate* isolate = arr->GetIsolate(); | 1149 Isolate* isolate = arr->GetIsolate(); |
| 1128 #define WCM_CHECK_TYPE(NAME, TYPE_CHECK) \ | 1150 #define WCM_CHECK_TYPE(NAME, TYPE_CHECK) \ |
| 1129 do { \ | 1151 do { \ |
| 1130 Object* obj = arr->get(kID_##NAME); \ | 1152 Object* obj = arr->get(kID_##NAME); \ |
| 1131 if (!(TYPE_CHECK)) return false; \ | 1153 if (!(TYPE_CHECK)) return false; \ |
| 1132 } while (false); | 1154 } while (false); |
| 1133 // We're OK with undefined, generally, because maybe we don't | 1155 // We're OK with undefined, generally, because maybe we don't |
| 1134 // have a value for that item. For example, we may not have a | 1156 // have a value for that item. For example, we may not have a |
| 1135 // memory, or globals. | 1157 // memory, or globals. |
| 1136 // We're not OK with the fixed numbers being undefined. We want | 1158 // We're not OK with the const numbers being undefined. They are |
| 1137 // to set once all of them. | 1159 // expected to be initialized at construction. |
| 1138 #define WCM_CHECK_OBJECT(TYPE, NAME) \ | 1160 #define WCM_CHECK_OBJECT(TYPE, NAME) \ |
| 1139 WCM_CHECK_TYPE(NAME, obj->IsUndefined(isolate) || obj->Is##TYPE()) | 1161 WCM_CHECK_TYPE(NAME, obj->IsUndefined(isolate) || obj->Is##TYPE()) |
| 1162 #define WCM_CHECK_CONST_OBJECT(TYPE, NAME) \ |
| 1163 WCM_CHECK_TYPE(NAME, obj->IsUndefined(isolate) || obj->Is##TYPE()) |
| 1140 #define WCM_CHECK_WASM_OBJECT(TYPE, NAME) \ | 1164 #define WCM_CHECK_WASM_OBJECT(TYPE, NAME) \ |
| 1141 WCM_CHECK_TYPE(NAME, TYPE::Is##TYPE(obj)) | 1165 WCM_CHECK_TYPE(NAME, TYPE::Is##TYPE(obj)) |
| 1142 #define WCM_CHECK_WEAK_LINK(TYPE, NAME) WCM_CHECK_OBJECT(WeakCell, NAME) | 1166 #define WCM_CHECK_WEAK_LINK(TYPE, NAME) WCM_CHECK_OBJECT(WeakCell, NAME) |
| 1143 #define WCM_CHECK_SMALL_NUMBER(TYPE, NAME) \ | 1167 #define WCM_CHECK_SMALL_NUMBER(TYPE, NAME) \ |
| 1144 WCM_CHECK_TYPE(NAME, obj->IsUndefined(isolate) || obj->IsSmi()) | 1168 WCM_CHECK_TYPE(NAME, obj->IsUndefined(isolate) || obj->IsSmi()) |
| 1145 #define WCM_CHECK(KIND, TYPE, NAME) WCM_CHECK_##KIND(TYPE, NAME) | 1169 #define WCM_CHECK(KIND, TYPE, NAME) WCM_CHECK_##KIND(TYPE, NAME) |
| 1146 #define WCM_CHECK_SMALL_FIXED_NUMBER(TYPE, NAME) \ | 1170 #define WCM_CHECK_SMALL_CONST_NUMBER(TYPE, NAME) \ |
| 1147 WCM_CHECK_TYPE(NAME, obj->IsSmi()) | 1171 WCM_CHECK_TYPE(NAME, obj->IsSmi()) |
| 1148 #define WCM_CHECK_LARGE_NUMBER(TYPE, NAME) \ | 1172 #define WCM_CHECK_LARGE_NUMBER(TYPE, NAME) \ |
| 1149 WCM_CHECK_TYPE(NAME, obj->IsUndefined(isolate) || obj->IsMutableHeapNumber()) | 1173 WCM_CHECK_TYPE(NAME, obj->IsUndefined(isolate) || obj->IsMutableHeapNumber()) |
| 1150 WCM_PROPERTY_TABLE(WCM_CHECK) | 1174 WCM_PROPERTY_TABLE(WCM_CHECK) |
| 1151 #undef WCM_CHECK | 1175 #undef WCM_CHECK |
| 1152 | 1176 |
| 1153 // All checks passed. | 1177 // All checks passed. |
| 1154 return true; | 1178 return true; |
| 1155 } | 1179 } |
| 1156 | 1180 |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1549 if (!array->get(kWrapperInstanceObject)->IsWeakCell()) return false; | 1573 if (!array->get(kWrapperInstanceObject)->IsWeakCell()) return false; |
| 1550 Isolate* isolate = array->GetIsolate(); | 1574 Isolate* isolate = array->GetIsolate(); |
| 1551 if (!array->get(kNextInstanceWrapper)->IsUndefined(isolate) && | 1575 if (!array->get(kNextInstanceWrapper)->IsUndefined(isolate) && |
| 1552 !array->get(kNextInstanceWrapper)->IsFixedArray()) | 1576 !array->get(kNextInstanceWrapper)->IsFixedArray()) |
| 1553 return false; | 1577 return false; |
| 1554 if (!array->get(kPreviousInstanceWrapper)->IsUndefined(isolate) && | 1578 if (!array->get(kPreviousInstanceWrapper)->IsUndefined(isolate) && |
| 1555 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) | 1579 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) |
| 1556 return false; | 1580 return false; |
| 1557 return true; | 1581 return true; |
| 1558 } | 1582 } |
| OLD | NEW |