| 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" |
| (...skipping 2038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2049 Handle<WasmDebugInfo> wasm::GetDebugInfo(Handle<JSObject> wasm) { | 2049 Handle<WasmDebugInfo> wasm::GetDebugInfo(Handle<JSObject> wasm) { |
| 2050 Handle<Object> info(wasm->GetInternalField(kWasmDebugInfo), | 2050 Handle<Object> info(wasm->GetInternalField(kWasmDebugInfo), |
| 2051 wasm->GetIsolate()); | 2051 wasm->GetIsolate()); |
| 2052 if (!info->IsUndefined(wasm->GetIsolate())) | 2052 if (!info->IsUndefined(wasm->GetIsolate())) |
| 2053 return Handle<WasmDebugInfo>::cast(info); | 2053 return Handle<WasmDebugInfo>::cast(info); |
| 2054 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(wasm); | 2054 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(wasm); |
| 2055 wasm->SetInternalField(kWasmDebugInfo, *new_info); | 2055 wasm->SetInternalField(kWasmDebugInfo, *new_info); |
| 2056 return new_info; | 2056 return new_info; |
| 2057 } | 2057 } |
| 2058 | 2058 |
| 2059 bool wasm::UpdateWasmModuleMemory(Handle<JSObject> object, Address old_start, |
| 2060 Address new_start, uint32_t old_size, |
| 2061 uint32_t new_size) { |
| 2062 DisallowHeapAllocation no_allocation; |
| 2063 if (!IsWasmObject(*object)) { |
| 2064 return false; |
| 2065 } |
| 2066 |
| 2067 // Get code table associated with the module js_object |
| 2068 Object* obj = object->GetInternalField(kWasmModuleCodeTable); |
| 2069 Handle<FixedArray> code_table(FixedArray::cast(obj)); |
| 2070 |
| 2071 // Iterate through the code objects in the code table and update relocation |
| 2072 // information |
| 2073 for (int i = 0; i < code_table->length(); ++i) { |
| 2074 obj = code_table->get(i); |
| 2075 Handle<Code> code(Code::cast(obj)); |
| 2076 |
| 2077 int mode_mask = RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_REFERENCE) | |
| 2078 RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_SIZE_REFERENCE); |
| 2079 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
| 2080 RelocInfo::Mode mode = it.rinfo()->rmode(); |
| 2081 if (RelocInfo::IsWasmMemoryReference(mode) || |
| 2082 RelocInfo::IsWasmMemorySizeReference(mode)) { |
| 2083 it.rinfo()->update_wasm_memory_reference(old_start, new_start, old_size, |
| 2084 new_size); |
| 2085 } |
| 2086 } |
| 2087 } |
| 2088 return true; |
| 2089 } |
| 2090 |
| 2059 Handle<FixedArray> wasm::BuildFunctionTable(Isolate* isolate, uint32_t index, | 2091 Handle<FixedArray> wasm::BuildFunctionTable(Isolate* isolate, uint32_t index, |
| 2060 const WasmModule* module) { | 2092 const WasmModule* module) { |
| 2061 const WasmIndirectFunctionTable* table = &module->function_tables[index]; | 2093 const WasmIndirectFunctionTable* table = &module->function_tables[index]; |
| 2062 DCHECK_EQ(table->size, table->values.size()); | 2094 DCHECK_EQ(table->size, table->values.size()); |
| 2063 DCHECK_GE(table->max_size, table->size); | 2095 DCHECK_GE(table->max_size, table->size); |
| 2064 Handle<FixedArray> values = | 2096 Handle<FixedArray> values = |
| 2065 isolate->factory()->NewFixedArray(2 * table->max_size, TENURED); | 2097 isolate->factory()->NewFixedArray(2 * table->max_size, TENURED); |
| 2066 for (uint32_t i = 0; i < table->size; ++i) { | 2098 for (uint32_t i = 0; i < table->size; ++i) { |
| 2067 const WasmFunction* function = &module->functions[table->values[i]]; | 2099 const WasmFunction* function = &module->functions[table->values[i]]; |
| 2068 int32_t index = table->map.Find(function->sig); | 2100 int32_t index = table->map.Find(function->sig); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2200 Handle<JSArrayBuffer> buffer; | 2232 Handle<JSArrayBuffer> buffer; |
| 2201 if (!maybe_mem_buffer.ToHandle(&buffer)) { | 2233 if (!maybe_mem_buffer.ToHandle(&buffer)) { |
| 2202 return 0; | 2234 return 0; |
| 2203 } else { | 2235 } else { |
| 2204 return buffer->byte_length()->Number() / WasmModule::kPageSize; | 2236 return buffer->byte_length()->Number() / WasmModule::kPageSize; |
| 2205 } | 2237 } |
| 2206 } | 2238 } |
| 2207 | 2239 |
| 2208 int32_t wasm::GrowInstanceMemory(Isolate* isolate, Handle<JSObject> instance, | 2240 int32_t wasm::GrowInstanceMemory(Isolate* isolate, Handle<JSObject> instance, |
| 2209 uint32_t pages) { | 2241 uint32_t pages) { |
| 2210 if (!IsWasmObject(*instance)) return false; | 2242 if (pages == 0) { |
| 2211 if (pages == 0) return GetInstanceMemorySize(isolate, instance); | 2243 return GetInstanceMemorySize(isolate, instance); |
| 2212 | 2244 } |
| 2213 Address old_mem_start = nullptr; | 2245 Address old_mem_start = nullptr; |
| 2214 uint32_t old_size = 0, new_size = 0; | 2246 uint32_t old_size = 0, new_size = 0; |
| 2215 | 2247 |
| 2216 MaybeHandle<JSArrayBuffer> maybe_mem_buffer = | 2248 MaybeHandle<JSArrayBuffer> maybe_mem_buffer = |
| 2217 GetInstanceMemory(isolate, instance); | 2249 GetInstanceMemory(isolate, instance); |
| 2218 Handle<JSArrayBuffer> old_buffer; | 2250 Handle<JSArrayBuffer> old_buffer; |
| 2219 if (!maybe_mem_buffer.ToHandle(&old_buffer)) { | 2251 if (!maybe_mem_buffer.ToHandle(&old_buffer)) { |
| 2220 // If module object does not have linear memory associated with it, | 2252 // If module object does not have linear memory associated with it, |
| 2221 // Allocate new array buffer of given size. | 2253 // Allocate new array buffer of given size. |
| 2222 // TODO(gdeepti): Fix bounds check to take into account size of memtype. | 2254 // TODO(gdeepti): Fix bounds check to take into account size of memtype. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2239 WasmModule::kMaxMemPages * WasmModule::kPageSize <= new_size) { | 2271 WasmModule::kMaxMemPages * WasmModule::kPageSize <= new_size) { |
| 2240 return -1; | 2272 return -1; |
| 2241 } | 2273 } |
| 2242 Handle<JSArrayBuffer> buffer = NewArrayBuffer(isolate, new_size); | 2274 Handle<JSArrayBuffer> buffer = NewArrayBuffer(isolate, new_size); |
| 2243 if (buffer.is_null()) return -1; | 2275 if (buffer.is_null()) return -1; |
| 2244 Address new_mem_start = static_cast<Address>(buffer->backing_store()); | 2276 Address new_mem_start = static_cast<Address>(buffer->backing_store()); |
| 2245 if (old_size != 0) { | 2277 if (old_size != 0) { |
| 2246 memcpy(new_mem_start, old_mem_start, old_size); | 2278 memcpy(new_mem_start, old_mem_start, old_size); |
| 2247 } | 2279 } |
| 2248 SetInstanceMemory(instance, *buffer); | 2280 SetInstanceMemory(instance, *buffer); |
| 2249 RelocateInstanceCode(instance, old_mem_start, new_mem_start, old_size, | 2281 if (!UpdateWasmModuleMemory(instance, old_mem_start, new_mem_start, old_size, |
| 2250 new_size); | 2282 new_size)) { |
| 2283 return -1; |
| 2284 } |
| 2251 DCHECK(old_size % WasmModule::kPageSize == 0); | 2285 DCHECK(old_size % WasmModule::kPageSize == 0); |
| 2252 return (old_size / WasmModule::kPageSize); | 2286 return (old_size / WasmModule::kPageSize); |
| 2253 } | 2287 } |
| 2254 | 2288 |
| 2255 void testing::ValidateInstancesChain(Isolate* isolate, | 2289 void testing::ValidateInstancesChain(Isolate* isolate, |
| 2256 Handle<JSObject> module_obj, | 2290 Handle<JSObject> module_obj, |
| 2257 int instance_count) { | 2291 int instance_count) { |
| 2258 CHECK_GE(instance_count, 0); | 2292 CHECK_GE(instance_count, 0); |
| 2259 DisallowHeapAllocation no_gc; | 2293 DisallowHeapAllocation no_gc; |
| 2260 WasmCompiledModule* compiled_module = | 2294 WasmCompiledModule* compiled_module = |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2294 } | 2328 } |
| 2295 | 2329 |
| 2296 void testing::ValidateOrphanedInstance(Isolate* isolate, | 2330 void testing::ValidateOrphanedInstance(Isolate* isolate, |
| 2297 Handle<JSObject> instance) { | 2331 Handle<JSObject> instance) { |
| 2298 DisallowHeapAllocation no_gc; | 2332 DisallowHeapAllocation no_gc; |
| 2299 CHECK(IsWasmObject(*instance)); | 2333 CHECK(IsWasmObject(*instance)); |
| 2300 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); | 2334 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); |
| 2301 CHECK(compiled_module->has_weak_module_object()); | 2335 CHECK(compiled_module->has_weak_module_object()); |
| 2302 CHECK(compiled_module->ptr_to_weak_module_object()->cleared()); | 2336 CHECK(compiled_module->ptr_to_weak_module_object()->cleared()); |
| 2303 } | 2337 } |
| OLD | NEW |