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

Side by Side Diff: src/wasm/wasm-module.cc

Issue 2696143006: [wasm] Refactor code specialization / patching (Closed)
Patch Set: Rebase Created 3 years, 10 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/wasm/wasm-code-specialization.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/assembler-inl.h" 7 #include "src/assembler-inl.h"
8 #include "src/base/adapters.h" 8 #include "src/base/adapters.h"
9 #include "src/base/atomic-utils.h" 9 #include "src/base/atomic-utils.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
11 #include "src/compiler/wasm-compiler.h" 11 #include "src/compiler/wasm-compiler.h"
12 #include "src/debug/interface-types.h" 12 #include "src/debug/interface-types.h"
13 #include "src/objects.h" 13 #include "src/objects.h"
14 #include "src/property-descriptor.h" 14 #include "src/property-descriptor.h"
15 #include "src/simulator.h" 15 #include "src/simulator.h"
16 #include "src/snapshot/snapshot.h" 16 #include "src/snapshot/snapshot.h"
17 #include "src/v8.h" 17 #include "src/v8.h"
18 18
19 #include "src/asmjs/asm-wasm-builder.h" 19 #include "src/asmjs/asm-wasm-builder.h"
20 #include "src/wasm/function-body-decoder.h" 20 #include "src/wasm/function-body-decoder.h"
21 #include "src/wasm/module-decoder.h" 21 #include "src/wasm/module-decoder.h"
22 #include "src/wasm/wasm-code-specialization.h"
22 #include "src/wasm/wasm-js.h" 23 #include "src/wasm/wasm-js.h"
23 #include "src/wasm/wasm-limits.h" 24 #include "src/wasm/wasm-limits.h"
24 #include "src/wasm/wasm-module.h" 25 #include "src/wasm/wasm-module.h"
25 #include "src/wasm/wasm-objects.h" 26 #include "src/wasm/wasm-objects.h"
26 #include "src/wasm/wasm-result.h" 27 #include "src/wasm/wasm-result.h"
27 28
28 using namespace v8::internal; 29 using namespace v8::internal;
29 using namespace v8::internal::wasm; 30 using namespace v8::internal::wasm;
30 namespace base = v8::base; 31 namespace base = v8::base;
31 32
32 #define TRACE(...) \ 33 #define TRACE(...) \
33 do { \ 34 do { \
34 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \ 35 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \
35 } while (false) 36 } while (false)
36 37
37 #define TRACE_CHAIN(instance) \ 38 #define TRACE_CHAIN(instance) \
38 do { \ 39 do { \
39 instance->PrintInstancesChain(); \ 40 instance->PrintInstancesChain(); \
40 } while (false) 41 } while (false)
41 42
42 namespace { 43 namespace {
43 44
44 static const int kInvalidSigIndex = -1; 45 static const int kInvalidSigIndex = -1;
45 46
46 byte* raw_buffer_ptr(MaybeHandle<JSArrayBuffer> buffer, int offset) { 47 byte* raw_buffer_ptr(MaybeHandle<JSArrayBuffer> buffer, int offset) {
47 return static_cast<byte*>(buffer.ToHandleChecked()->backing_store()) + offset; 48 return static_cast<byte*>(buffer.ToHandleChecked()->backing_store()) + offset;
48 } 49 }
49 50
50 void ReplaceReferenceInCode(Handle<Code> code, Handle<Object> old_ref,
51 Handle<Object> new_ref) {
52 for (RelocIterator it(*code, 1 << RelocInfo::EMBEDDED_OBJECT); !it.done();
53 it.next()) {
54 if (it.rinfo()->target_object() == *old_ref) {
55 it.rinfo()->set_target_object(*new_ref);
56 }
57 }
58 }
59
60 static void MemoryFinalizer(const v8::WeakCallbackInfo<void>& data) { 51 static void MemoryFinalizer(const v8::WeakCallbackInfo<void>& data) {
61 DisallowHeapAllocation no_gc; 52 DisallowHeapAllocation no_gc;
62 JSArrayBuffer** p = reinterpret_cast<JSArrayBuffer**>(data.GetParameter()); 53 JSArrayBuffer** p = reinterpret_cast<JSArrayBuffer**>(data.GetParameter());
63 JSArrayBuffer* buffer = *p; 54 JSArrayBuffer* buffer = *p;
64 55
65 if (!buffer->was_neutered()) { 56 if (!buffer->was_neutered()) {
66 void* memory = buffer->backing_store(); 57 void* memory = buffer->backing_store();
67 DCHECK(memory != nullptr); 58 DCHECK(memory != nullptr);
68 base::OS::Free(memory, 59 base::OS::Free(memory,
69 RoundUp(kWasmMaxHeapOffset, base::OS::CommitPageSize())); 60 RoundUp(kWasmMaxHeapOffset, base::OS::CommitPageSize()));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 ->AdjustAmountOfExternalAllocatedMemory(size); 106 ->AdjustAmountOfExternalAllocatedMemory(size);
116 107
117 is_external = true; 108 is_external = true;
118 return memory; 109 return memory;
119 } else { 110 } else {
120 void* memory = isolate->array_buffer_allocator()->Allocate(size); 111 void* memory = isolate->array_buffer_allocator()->Allocate(size);
121 return memory; 112 return memory;
122 } 113 }
123 } 114 }
124 115
125 void RelocateMemoryReferencesInCode(Handle<FixedArray> code_table,
126 uint32_t num_imported_functions,
127 Address old_start, Address start,
128 uint32_t prev_size, uint32_t new_size) {
129 for (int i = static_cast<int>(num_imported_functions);
130 i < code_table->length(); ++i) {
131 DCHECK(code_table->get(i)->IsCode());
132 Handle<Code> code = Handle<Code>(Code::cast(code_table->get(i)));
133 AllowDeferredHandleDereference embedding_raw_address;
134 int mask = (1 << RelocInfo::WASM_MEMORY_REFERENCE) |
135 (1 << RelocInfo::WASM_MEMORY_SIZE_REFERENCE);
136 for (RelocIterator it(*code, mask); !it.done(); it.next()) {
137 it.rinfo()->update_wasm_memory_reference(old_start, start, prev_size,
138 new_size);
139 }
140 }
141 }
142
143 void RelocateGlobals(Handle<FixedArray> code_table, Address old_start,
144 Address globals_start) {
145 for (int i = 0; i < code_table->length(); ++i) {
146 DCHECK(code_table->get(i)->IsCode());
147 Handle<Code> code = Handle<Code>(Code::cast(code_table->get(i)));
148 AllowDeferredHandleDereference embedding_raw_address;
149 int mask = 1 << RelocInfo::WASM_GLOBAL_REFERENCE;
150 for (RelocIterator it(*code, mask); !it.done(); it.next()) {
151 it.rinfo()->update_wasm_global_reference(old_start, globals_start);
152 }
153 }
154 }
155
156 void RelocateTableSizeReferences(Handle<FixedArray> code_table,
157 uint32_t old_size, uint32_t new_size) {
158 for (int i = 0; i < code_table->length(); ++i) {
159 DCHECK(code_table->get(i)->IsCode());
160 Handle<Code> code = Handle<Code>(Code::cast(code_table->get(i)));
161 AllowDeferredHandleDereference embedding_raw_address;
162 int mask = 1 << RelocInfo::WASM_FUNCTION_TABLE_SIZE_REFERENCE;
163 for (RelocIterator it(*code, mask); !it.done(); it.next()) {
164 it.rinfo()->update_wasm_function_table_size_reference(old_size, new_size);
165 }
166 }
167 }
168
169 void FlushICache(Isolate* isolate, Handle<FixedArray> code_table) { 116 void FlushICache(Isolate* isolate, Handle<FixedArray> code_table) {
170 for (int i = 0; i < code_table->length(); ++i) { 117 for (int i = 0; i < code_table->length(); ++i) {
171 Handle<Code> code = code_table->GetValueChecked<Code>(isolate, i); 118 Handle<Code> code = code_table->GetValueChecked<Code>(isolate, i);
172 Assembler::FlushICache(isolate, code->instruction_start(), 119 Assembler::FlushICache(isolate, code->instruction_start(),
173 code->instruction_size()); 120 code->instruction_size());
174 } 121 }
175 } 122 }
176 123
177 // Fetches the compilation unit of a wasm function and executes its parallel 124 // Fetches the compilation unit of a wasm function and executes its parallel
178 // phase. 125 // phase.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 code->relocation_info()->length()); 186 code->relocation_info()->length());
240 } 187 }
241 188
242 static void RecordStats(Isolate* isolate, Handle<FixedArray> functions) { 189 static void RecordStats(Isolate* isolate, Handle<FixedArray> functions) {
243 DisallowHeapAllocation no_gc; 190 DisallowHeapAllocation no_gc;
244 for (int i = 0; i < functions->length(); ++i) { 191 for (int i = 0; i < functions->length(); ++i) {
245 RecordStats(isolate, Code::cast(functions->get(i))); 192 RecordStats(isolate, Code::cast(functions->get(i)));
246 } 193 }
247 } 194 }
248 195
249 Address GetGlobalStartAddressFromCodeTemplate(Object* undefined,
250 JSObject* object) {
251 auto instance = WasmInstanceObject::cast(object);
252 Address old_address = nullptr;
253 if (instance->has_globals_buffer()) {
254 old_address =
255 static_cast<Address>(instance->globals_buffer()->backing_store());
256 }
257 return old_address;
258 }
259
260 void InitializeParallelCompilation( 196 void InitializeParallelCompilation(
261 Isolate* isolate, const std::vector<WasmFunction>& functions, 197 Isolate* isolate, const std::vector<WasmFunction>& functions,
262 std::vector<compiler::WasmCompilationUnit*>& compilation_units, 198 std::vector<compiler::WasmCompilationUnit*>& compilation_units,
263 ModuleBytesEnv& module_env, ErrorThrower* thrower) { 199 ModuleBytesEnv& module_env, ErrorThrower* thrower) {
264 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); ++i) { 200 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); ++i) {
265 const WasmFunction* func = &functions[i]; 201 const WasmFunction* func = &functions[i];
266 compilation_units[i] = 202 compilation_units[i] =
267 func->imported ? nullptr : new compiler::WasmCompilationUnit( 203 func->imported ? nullptr : new compiler::WasmCompilationUnit(
268 thrower, isolate, &module_env, func, i); 204 thrower, isolate, &module_env, func, i);
269 } 205 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 WasmName str = module_env->wire_bytes.GetName(&func); 344 WasmName str = module_env->wire_bytes.GetName(&func);
409 thrower->CompileError("Compilation of #%d:%.*s failed.", i, str.length(), 345 thrower->CompileError("Compilation of #%d:%.*s failed.", i, str.length(),
410 str.start()); 346 str.start());
411 break; 347 break;
412 } 348 }
413 // Install the code into the linker table. 349 // Install the code into the linker table.
414 functions[i] = code; 350 functions[i] = code;
415 } 351 }
416 } 352 }
417 353
418 int ExtractDirectCallIndex(wasm::Decoder& decoder, const byte* pc) {
419 DCHECK_EQ(static_cast<int>(kExprCallFunction), static_cast<int>(*pc));
420 decoder.Reset(pc + 1, pc + 6);
421 uint32_t call_idx = decoder.consume_u32v("call index");
422 DCHECK(decoder.ok());
423 DCHECK_GE(kMaxInt, call_idx);
424 return static_cast<int>(call_idx);
425 }
426
427 int AdvanceSourcePositionTableIterator(SourcePositionTableIterator& iterator,
428 size_t offset_l) {
429 DCHECK_GE(kMaxInt, offset_l);
430 int offset = static_cast<int>(offset_l);
431 DCHECK(!iterator.done());
432 int byte_pos;
433 do {
434 byte_pos = iterator.source_position().ScriptOffset();
435 iterator.Advance();
436 } while (!iterator.done() && iterator.code_offset() <= offset);
437 return byte_pos;
438 }
439
440 void PatchContext(RelocIterator& it, Context* context) {
441 Object* old = it.rinfo()->target_object();
442 // The only context we use is the native context.
443 DCHECK_IMPLIES(old->IsContext(), old->IsNativeContext());
444 if (!old->IsNativeContext()) return;
445 it.rinfo()->set_target_object(context, UPDATE_WRITE_BARRIER,
446 SKIP_ICACHE_FLUSH);
447 }
448
449 void PatchDirectCallsAndContext(Handle<FixedArray> new_functions,
450 Handle<WasmCompiledModule> compiled_module,
451 WasmModule* module, int start) {
452 DisallowHeapAllocation no_gc;
453 AllowDeferredHandleDereference embedding_raw_address;
454 SeqOneByteString* module_bytes = compiled_module->module_bytes();
455 std::vector<WasmFunction>* wasm_functions =
456 &compiled_module->module()->functions;
457 DCHECK_EQ(wasm_functions->size() +
458 compiled_module->module()->num_exported_functions,
459 new_functions->length());
460 DCHECK_EQ(start, compiled_module->module()->num_imported_functions);
461 Context* context = compiled_module->ptr_to_native_context();
462 int mode_mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) |
463 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
464
465 // Allocate decoder outside of the loop and reuse it to decode all function
466 // indexes.
467 wasm::Decoder decoder(nullptr, nullptr);
468 int num_wasm_functions = static_cast<int>(wasm_functions->size());
469 int func_index = start;
470 // We patch WASM_FUNCTION and WASM_TO_JS_FUNCTION during re-instantiation,
471 // and illegal builtins initially and after deserialization.
472 auto is_at_wasm_call = [](RelocIterator& it) {
473 Code* code = Code::GetCodeFromTargetAddress(it.rinfo()->target_address());
474 return code->kind() == Code::WASM_FUNCTION ||
475 code->kind() == Code::WASM_TO_JS_FUNCTION ||
476 code->builtin_index() == Builtins::kIllegal;
477 };
478
479 // Patch all wasm functions.
480 for (; func_index < num_wasm_functions; ++func_index) {
481 Code* wasm_function = Code::cast(new_functions->get(func_index));
482 DCHECK(wasm_function->kind() == Code::WASM_FUNCTION);
483 // Iterate simultaneously over the relocation information and the source
484 // position table. For each call in the reloc info, move the source position
485 // iterator forward to that position to find the byte offset of the
486 // respective call. Then extract the call index from the module wire bytes
487 // to find the new compiled function.
488 SourcePositionTableIterator source_pos_iterator(
489 wasm_function->source_position_table());
490 const byte* func_bytes =
491 module_bytes->GetChars() +
492 compiled_module->module()->functions[func_index].code_start_offset;
493 for (RelocIterator it(wasm_function, mode_mask); !it.done(); it.next()) {
494 if (RelocInfo::IsEmbeddedObject(it.rinfo()->rmode())) {
495 PatchContext(it, context);
496 continue;
497 }
498 DCHECK(RelocInfo::IsCodeTarget(it.rinfo()->rmode()));
499 if (!is_at_wasm_call(it)) continue;
500 size_t offset = it.rinfo()->pc() - wasm_function->instruction_start();
501 int byte_pos =
502 AdvanceSourcePositionTableIterator(source_pos_iterator, offset);
503 int called_func_index =
504 ExtractDirectCallIndex(decoder, func_bytes + byte_pos);
505 Code* new_code = Code::cast(new_functions->get(called_func_index));
506 it.rinfo()->set_target_address(new_code->instruction_start(),
507 UPDATE_WRITE_BARRIER, SKIP_ICACHE_FLUSH);
508 }
509 }
510 // Patch all exported functions.
511 for (auto exp : module->export_table) {
512 if (exp.kind != kExternalFunction) continue;
513 Code* export_wrapper = Code::cast(new_functions->get(func_index));
514 DCHECK_EQ(Code::JS_TO_WASM_FUNCTION, export_wrapper->kind());
515 // There must be exactly one call to WASM_FUNCTION or WASM_TO_JS_FUNCTION.
516 int num_wasm_calls = 0;
517 for (RelocIterator it(export_wrapper, mode_mask); !it.done(); it.next()) {
518 if (RelocInfo::IsEmbeddedObject(it.rinfo()->rmode())) {
519 PatchContext(it, context);
520 continue;
521 }
522 DCHECK(RelocInfo::IsCodeTarget(it.rinfo()->rmode()));
523 if (!is_at_wasm_call(it)) continue;
524 ++num_wasm_calls;
525 Code* new_code = Code::cast(new_functions->get(exp.index));
526 DCHECK(new_code->kind() == Code::WASM_FUNCTION ||
527 new_code->kind() == Code::WASM_TO_JS_FUNCTION);
528 it.rinfo()->set_target_address(new_code->instruction_start(),
529 UPDATE_WRITE_BARRIER, SKIP_ICACHE_FLUSH);
530 }
531 DCHECK_EQ(1, num_wasm_calls);
532 func_index++;
533 }
534 DCHECK_EQ(new_functions->length(), func_index);
535 }
536
537 static void ResetCompiledModule(Isolate* isolate, WasmInstanceObject* owner, 354 static void ResetCompiledModule(Isolate* isolate, WasmInstanceObject* owner,
538 WasmCompiledModule* compiled_module) { 355 WasmCompiledModule* compiled_module) {
539 TRACE("Resetting %d\n", compiled_module->instance_id()); 356 TRACE("Resetting %d\n", compiled_module->instance_id());
540 Object* undefined = *isolate->factory()->undefined_value(); 357 Object* undefined = *isolate->factory()->undefined_value();
541 uint32_t old_mem_size = compiled_module->mem_size(); 358 Object* fct_obj = compiled_module->ptr_to_code_table();
542 uint32_t default_mem_size = compiled_module->default_mem_size(); 359 if (fct_obj != nullptr && fct_obj != undefined) {
543 Object* mem_start = compiled_module->maybe_ptr_to_memory(); 360 uint32_t old_mem_size = compiled_module->mem_size();
544 Address old_mem_address = nullptr; 361 uint32_t default_mem_size = compiled_module->default_mem_size();
545 Address globals_start = 362 Object* mem_start = compiled_module->maybe_ptr_to_memory();
546 GetGlobalStartAddressFromCodeTemplate(undefined, owner);
547 363
548 // Reset function tables. 364 // Patch code to update memory references, global references, and function
549 FixedArray* function_tables = nullptr; 365 // table references.
550 FixedArray* empty_function_tables = nullptr; 366 Zone specialization_zone(isolate->allocator(), ZONE_NAME);
551 if (compiled_module->has_function_tables()) { 367 CodeSpecialization code_specialization(isolate, &specialization_zone);
552 function_tables = compiled_module->ptr_to_function_tables();
553 empty_function_tables = compiled_module->ptr_to_empty_function_tables();
554 compiled_module->set_ptr_to_function_tables(empty_function_tables);
555 }
556 368
557 if (old_mem_size > 0) { 369 if (old_mem_size > 0) {
558 CHECK_NE(mem_start, undefined); 370 CHECK_NE(mem_start, undefined);
559 old_mem_address = 371 Address old_mem_address =
560 static_cast<Address>(JSArrayBuffer::cast(mem_start)->backing_store()); 372 static_cast<Address>(JSArrayBuffer::cast(mem_start)->backing_store());
561 } 373 code_specialization.RelocateMemoryReferences(
562 int mode_mask = RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_REFERENCE) | 374 old_mem_address, old_mem_size, nullptr, default_mem_size);
563 RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_SIZE_REFERENCE) | 375 }
564 RelocInfo::ModeMask(RelocInfo::WASM_GLOBAL_REFERENCE) |
565 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
566 376
567 // Patch code to update memory references, global references, and function 377 if (owner->has_globals_buffer()) {
568 // table references. 378 Address globals_start =
569 Object* fct_obj = compiled_module->ptr_to_code_table(); 379 static_cast<Address>(owner->globals_buffer()->backing_store());
570 if (fct_obj != nullptr && fct_obj != undefined && 380 code_specialization.RelocateGlobals(globals_start, nullptr);
571 (old_mem_size > 0 || globals_start != nullptr || function_tables)) { 381 }
382
383 // Reset function tables.
384 if (compiled_module->has_function_tables()) {
385 FixedArray* function_tables = compiled_module->ptr_to_function_tables();
386 FixedArray* empty_function_tables =
387 compiled_module->ptr_to_empty_function_tables();
388 DCHECK_EQ(function_tables->length(), empty_function_tables->length());
389 for (int i = 0, e = function_tables->length(); i < e; ++i) {
390 code_specialization.RelocateObject(
391 handle(function_tables->get(i), isolate),
392 handle(empty_function_tables->get(i), isolate));
393 }
394 compiled_module->set_ptr_to_function_tables(empty_function_tables);
395 }
396
572 FixedArray* functions = FixedArray::cast(fct_obj); 397 FixedArray* functions = FixedArray::cast(fct_obj);
573 for (int i = compiled_module->num_imported_functions(); 398 for (int i = compiled_module->num_imported_functions(),
574 i < functions->length(); ++i) { 399 end = functions->length();
400 i < end; ++i) {
575 Code* code = Code::cast(functions->get(i)); 401 Code* code = Code::cast(functions->get(i));
576 bool changed = false; 402 if (code->kind() != Code::WASM_FUNCTION) {
577 for (RelocIterator it(code, mode_mask); !it.done(); it.next()) { 403 // From here on, there should only be wrappers for exported functions.
578 RelocInfo::Mode mode = it.rinfo()->rmode(); 404 for (; i < end; ++i) {
579 if (RelocInfo::IsWasmMemoryReference(mode) || 405 DCHECK_EQ(Code::JS_TO_WASM_FUNCTION,
580 RelocInfo::IsWasmMemorySizeReference(mode)) { 406 Code::cast(functions->get(i))->kind());
581 it.rinfo()->update_wasm_memory_reference(
582 old_mem_address, nullptr, old_mem_size, default_mem_size);
583 changed = true;
584 } else if (RelocInfo::IsWasmGlobalReference(mode)) {
585 it.rinfo()->update_wasm_global_reference(globals_start, nullptr);
586 changed = true;
587 } else if (RelocInfo::IsEmbeddedObject(mode) && function_tables) {
588 Object* old = it.rinfo()->target_object();
589 for (int j = 0; j < function_tables->length(); ++j) {
590 if (function_tables->get(j) == old) {
591 it.rinfo()->set_target_object(empty_function_tables->get(j));
592 changed = true;
593 }
594 }
595 } 407 }
408 break;
596 } 409 }
410 bool changed =
411 code_specialization.ApplyToWasmCode(code, SKIP_ICACHE_FLUSH);
412 // TODO(wasm): Check if this is faster than passing FLUSH_ICACHE_IF_NEEDED
413 // above.
597 if (changed) { 414 if (changed) {
598 Assembler::FlushICache(isolate, code->instruction_start(), 415 Assembler::FlushICache(isolate, code->instruction_start(),
599 code->instruction_size()); 416 code->instruction_size());
600 } 417 }
601 } 418 }
602 } 419 }
603 compiled_module->reset_memory(); 420 compiled_module->reset_memory();
604 } 421 }
605 422
606 static void MemoryInstanceFinalizer(Isolate* isolate, 423 static void MemoryInstanceFinalizer(Isolate* isolate,
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 TRACE("Reusing existing instance %d\n", 1095 TRACE("Reusing existing instance %d\n",
1279 compiled_module_->instance_id()); 1096 compiled_module_->instance_id());
1280 } 1097 }
1281 compiled_module_->set_code_table(code_table); 1098 compiled_module_->set_code_table(code_table);
1282 compiled_module_->set_native_context(isolate_->native_context()); 1099 compiled_module_->set_native_context(isolate_->native_context());
1283 } 1100 }
1284 1101
1285 //-------------------------------------------------------------------------- 1102 //--------------------------------------------------------------------------
1286 // Allocate the instance object. 1103 // Allocate the instance object.
1287 //-------------------------------------------------------------------------- 1104 //--------------------------------------------------------------------------
1105 Zone instantiation_zone(isolate_->allocator(), ZONE_NAME);
1106 CodeSpecialization code_specialization(isolate_, &instantiation_zone);
1288 Handle<WasmInstanceObject> instance = 1107 Handle<WasmInstanceObject> instance =
1289 WasmInstanceObject::New(isolate_, compiled_module_); 1108 WasmInstanceObject::New(isolate_, compiled_module_);
1290 1109
1291 //-------------------------------------------------------------------------- 1110 //--------------------------------------------------------------------------
1292 // Set up the globals for the new instance. 1111 // Set up the globals for the new instance.
1293 //-------------------------------------------------------------------------- 1112 //--------------------------------------------------------------------------
1294 MaybeHandle<JSArrayBuffer> old_globals; 1113 MaybeHandle<JSArrayBuffer> old_globals;
1295 uint32_t globals_size = module_->globals_size; 1114 uint32_t globals_size = module_->globals_size;
1296 if (globals_size > 0) { 1115 if (globals_size > 0) {
1297 const bool enable_guard_regions = false; 1116 const bool enable_guard_regions = false;
1298 Handle<JSArrayBuffer> global_buffer = 1117 Handle<JSArrayBuffer> global_buffer =
1299 NewArrayBuffer(isolate_, globals_size, enable_guard_regions); 1118 NewArrayBuffer(isolate_, globals_size, enable_guard_regions);
1300 globals_ = global_buffer; 1119 globals_ = global_buffer;
1301 if (globals_.is_null()) { 1120 if (globals_.is_null()) {
1302 thrower_->RangeError("Out of memory: wasm globals"); 1121 thrower_->RangeError("Out of memory: wasm globals");
1303 return nothing; 1122 return nothing;
1304 } 1123 }
1305 Address old_address = 1124 Address old_globals_start = nullptr;
1306 owner.is_null() ? nullptr : GetGlobalStartAddressFromCodeTemplate( 1125 if (!owner.is_null()) {
1307 isolate_->heap()->undefined_value(), 1126 DCHECK(owner.ToHandleChecked()->has_globals_buffer());
1308 *owner.ToHandleChecked()); 1127 old_globals_start = static_cast<Address>(
1309 RelocateGlobals(code_table, old_address, 1128 owner.ToHandleChecked()->globals_buffer()->backing_store());
1310 static_cast<Address>(global_buffer->backing_store())); 1129 }
1130 Address new_globals_start =
1131 static_cast<Address>(global_buffer->backing_store());
1132 code_specialization.RelocateGlobals(old_globals_start, new_globals_start);
1311 instance->set_globals_buffer(*global_buffer); 1133 instance->set_globals_buffer(*global_buffer);
1312 } 1134 }
1313 1135
1314 //-------------------------------------------------------------------------- 1136 //--------------------------------------------------------------------------
1315 // Prepare for initialization of function tables. 1137 // Prepare for initialization of function tables.
1316 //-------------------------------------------------------------------------- 1138 //--------------------------------------------------------------------------
1317 int function_table_count = 1139 int function_table_count =
1318 static_cast<int>(module_->function_tables.size()); 1140 static_cast<int>(module_->function_tables.size());
1319 table_instances_.reserve(module_->function_tables.size()); 1141 table_instances_.reserve(module_->function_tables.size());
1320 for (int index = 0; index < function_table_count; ++index) { 1142 for (int index = 0; index < function_table_count; ++index) {
1321 table_instances_.push_back( 1143 table_instances_.push_back(
1322 {Handle<WasmTableObject>::null(), Handle<FixedArray>::null(), 1144 {Handle<WasmTableObject>::null(), Handle<FixedArray>::null(),
1323 Handle<FixedArray>::null(), Handle<FixedArray>::null()}); 1145 Handle<FixedArray>::null(), Handle<FixedArray>::null()});
1324 } 1146 }
1325 1147
1326 //-------------------------------------------------------------------------- 1148 //--------------------------------------------------------------------------
1327 // Process the imports for the module. 1149 // Process the imports for the module.
1328 //-------------------------------------------------------------------------- 1150 //--------------------------------------------------------------------------
1329 int num_imported_functions = ProcessImports(code_table, instance); 1151 int num_imported_functions = ProcessImports(code_table, instance);
1330 if (num_imported_functions < 0) return nothing; 1152 if (num_imported_functions < 0) return nothing;
1331 1153
1332 //-------------------------------------------------------------------------- 1154 //--------------------------------------------------------------------------
1333 // Process the initialization for the module's globals. 1155 // Process the initialization for the module's globals.
1334 //-------------------------------------------------------------------------- 1156 //--------------------------------------------------------------------------
1335 InitGlobals(); 1157 InitGlobals();
1336 1158
1337 //-------------------------------------------------------------------------- 1159 //--------------------------------------------------------------------------
1338 // Set up the indirect function tables for the new instance. 1160 // Set up the indirect function tables for the new instance.
1339 //-------------------------------------------------------------------------- 1161 //--------------------------------------------------------------------------
1340 if (function_table_count > 0) InitializeTables(code_table, instance); 1162 if (function_table_count > 0)
1163 InitializeTables(code_table, instance, &code_specialization);
1341 1164
1342 //-------------------------------------------------------------------------- 1165 //--------------------------------------------------------------------------
1343 // Set up the memory for the new instance. 1166 // Set up the memory for the new instance.
1344 //-------------------------------------------------------------------------- 1167 //--------------------------------------------------------------------------
1345 MaybeHandle<JSArrayBuffer> old_memory; 1168 MaybeHandle<JSArrayBuffer> old_memory;
1346 1169
1347 uint32_t min_mem_pages = module_->min_mem_pages; 1170 uint32_t min_mem_pages = module_->min_mem_pages;
1348 isolate_->counters()->wasm_min_mem_pages_count()->AddSample(min_mem_pages); 1171 isolate_->counters()->wasm_min_mem_pages_count()->AddSample(min_mem_pages);
1349 1172
1350 if (!memory_.is_null()) { 1173 if (!memory_.is_null()) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 uint32_t mem_size = 1218 uint32_t mem_size =
1396 static_cast<uint32_t>(memory_->byte_length()->Number()); 1219 static_cast<uint32_t>(memory_->byte_length()->Number());
1397 LoadDataSegments(mem_start, mem_size); 1220 LoadDataSegments(mem_start, mem_size);
1398 1221
1399 uint32_t old_mem_size = compiled_module_->mem_size(); 1222 uint32_t old_mem_size = compiled_module_->mem_size();
1400 Address old_mem_start = 1223 Address old_mem_start =
1401 compiled_module_->has_memory() 1224 compiled_module_->has_memory()
1402 ? static_cast<Address>( 1225 ? static_cast<Address>(
1403 compiled_module_->memory()->backing_store()) 1226 compiled_module_->memory()->backing_store())
1404 : nullptr; 1227 : nullptr;
1405 RelocateMemoryReferencesInCode( 1228 code_specialization.RelocateMemoryReferences(old_mem_start, old_mem_size,
1406 code_table, module_->num_imported_functions, old_mem_start, mem_start, 1229 mem_start, mem_size);
1407 old_mem_size, mem_size);
1408 compiled_module_->set_memory(memory_); 1230 compiled_module_->set_memory(memory_);
1409 } 1231 }
1410 1232
1411 //-------------------------------------------------------------------------- 1233 //--------------------------------------------------------------------------
1412 // Set up the runtime support for the new instance. 1234 // Set up the runtime support for the new instance.
1413 //-------------------------------------------------------------------------- 1235 //--------------------------------------------------------------------------
1414 Handle<WeakCell> weak_link = factory->NewWeakCell(instance); 1236 Handle<WeakCell> weak_link = factory->NewWeakCell(instance);
1415 1237
1416 for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs; 1238 for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs;
1417 i < code_table->length(); ++i) { 1239 i < code_table->length(); ++i) {
(...skipping 18 matching lines...) Expand all
1436 DCHECK(wasm::IsWasmInstance(*instance)); 1258 DCHECK(wasm::IsWasmInstance(*instance));
1437 if (instance->has_memory_object()) { 1259 if (instance->has_memory_object()) {
1438 instance->memory_object()->AddInstance(isolate_, instance); 1260 instance->memory_object()->AddInstance(isolate_, instance);
1439 } 1261 }
1440 1262
1441 //-------------------------------------------------------------------------- 1263 //--------------------------------------------------------------------------
1442 // Initialize the indirect function tables. 1264 // Initialize the indirect function tables.
1443 //-------------------------------------------------------------------------- 1265 //--------------------------------------------------------------------------
1444 if (function_table_count > 0) LoadTableSegments(code_table, instance); 1266 if (function_table_count > 0) LoadTableSegments(code_table, instance);
1445 1267
1446 // Patch new call sites and the context. 1268 // Patch all code with the relocations registered in code_specialization.
1447 PatchDirectCallsAndContext(code_table, compiled_module_, module_, 1269 {
1448 num_imported_functions); 1270 code_specialization.RelocateDirectCalls(instance);
1271 code_specialization.ApplyToWholeInstance(*instance, SKIP_ICACHE_FLUSH);
1272 }
1449 1273
1450 FlushICache(isolate_, code_table); 1274 FlushICache(isolate_, code_table);
1451 1275
1452 //-------------------------------------------------------------------------- 1276 //--------------------------------------------------------------------------
1453 // Unpack and notify signal handler of protected instructions. 1277 // Unpack and notify signal handler of protected instructions.
1454 //-------------------------------------------------------------------------- 1278 //--------------------------------------------------------------------------
1455 if (FLAG_wasm_trap_handler) { 1279 if (FLAG_wasm_trap_handler) {
1456 for (int i = 0; i < code_table->length(); ++i) { 1280 for (int i = 0; i < code_table->length(); ++i) {
1457 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i); 1281 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i);
1458 1282
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
2135 1959
2136 if (module_->origin == kWasmOrigin) { 1960 if (module_->origin == kWasmOrigin) {
2137 v8::Maybe<bool> success = JSReceiver::SetIntegrityLevel( 1961 v8::Maybe<bool> success = JSReceiver::SetIntegrityLevel(
2138 exports_object, FROZEN, Object::DONT_THROW); 1962 exports_object, FROZEN, Object::DONT_THROW);
2139 DCHECK(success.FromMaybe(false)); 1963 DCHECK(success.FromMaybe(false));
2140 USE(success); 1964 USE(success);
2141 } 1965 }
2142 } 1966 }
2143 1967
2144 void InitializeTables(Handle<FixedArray> code_table, 1968 void InitializeTables(Handle<FixedArray> code_table,
2145 Handle<WasmInstanceObject> instance) { 1969 Handle<WasmInstanceObject> instance,
1970 CodeSpecialization* code_specialization) {
2146 int function_table_count = 1971 int function_table_count =
2147 static_cast<int>(module_->function_tables.size()); 1972 static_cast<int>(module_->function_tables.size());
2148 Handle<FixedArray> new_function_tables = 1973 Handle<FixedArray> new_function_tables =
2149 isolate_->factory()->NewFixedArray(function_table_count); 1974 isolate_->factory()->NewFixedArray(function_table_count);
2150 Handle<FixedArray> new_signature_tables = 1975 Handle<FixedArray> new_signature_tables =
2151 isolate_->factory()->NewFixedArray(function_table_count); 1976 isolate_->factory()->NewFixedArray(function_table_count);
2152 for (int index = 0; index < function_table_count; ++index) { 1977 for (int index = 0; index < function_table_count; ++index) {
2153 WasmIndirectFunctionTable& table = module_->function_tables[index]; 1978 WasmIndirectFunctionTable& table = module_->function_tables[index];
2154 TableInstance& table_instance = table_instances_[index]; 1979 TableInstance& table_instance = table_instances_[index];
2155 int table_size = static_cast<int>(table.min_size); 1980 int table_size = static_cast<int>(table.min_size);
2156 1981
2157 if (table_instance.function_table.is_null()) { 1982 if (table_instance.function_table.is_null()) {
2158 // Create a new dispatch table if necessary. 1983 // Create a new dispatch table if necessary.
2159 table_instance.function_table = 1984 table_instance.function_table =
2160 isolate_->factory()->NewFixedArray(table_size); 1985 isolate_->factory()->NewFixedArray(table_size);
2161 table_instance.signature_table = 1986 table_instance.signature_table =
2162 isolate_->factory()->NewFixedArray(table_size); 1987 isolate_->factory()->NewFixedArray(table_size);
2163 for (int i = 0; i < table_size; ++i) { 1988 for (int i = 0; i < table_size; ++i) {
2164 // Fill the table with invalid signature indexes so that 1989 // Fill the table with invalid signature indexes so that
2165 // uninitialized entries will always fail the signature check. 1990 // uninitialized entries will always fail the signature check.
2166 table_instance.signature_table->set(i, 1991 table_instance.signature_table->set(i,
2167 Smi::FromInt(kInvalidSigIndex)); 1992 Smi::FromInt(kInvalidSigIndex));
2168 } 1993 }
2169 } else { 1994 } else {
2170 // Table is imported, patch table bounds check 1995 // Table is imported, patch table bounds check
2171 DCHECK(table_size <= table_instance.function_table->length()); 1996 DCHECK(table_size <= table_instance.function_table->length());
2172 if (table_size < table_instance.function_table->length()) { 1997 if (table_size < table_instance.function_table->length()) {
2173 RelocateTableSizeReferences(code_table, table_size, 1998 code_specialization->PatchTableSize(
2174 table_instance.function_table->length()); 1999 table_size, table_instance.function_table->length());
2175 } 2000 }
2176 } 2001 }
2177 2002
2178 new_function_tables->set(static_cast<int>(index), 2003 new_function_tables->set(static_cast<int>(index),
2179 *table_instance.function_table); 2004 *table_instance.function_table);
2180 new_signature_tables->set(static_cast<int>(index), 2005 new_signature_tables->set(static_cast<int>(index),
2181 *table_instance.signature_table); 2006 *table_instance.signature_table);
2182 } 2007 }
2183 2008
2184 // Patch all code that has references to the old indirect tables. 2009 FixedArray* old_function_tables =
2185 Handle<FixedArray> old_function_tables = 2010 compiled_module_->ptr_to_function_tables();
2186 compiled_module_->function_tables(); 2011 DCHECK_EQ(old_function_tables->length(), new_function_tables->length());
2187 Handle<FixedArray> old_signature_tables = 2012 for (int i = 0, e = new_function_tables->length(); i < e; ++i) {
2188 compiled_module_->signature_tables(); 2013 code_specialization->RelocateObject(
2189 for (int i = 0; i < code_table->length(); ++i) { 2014 handle(old_function_tables->get(i), isolate_),
2190 if (!code_table->get(i)->IsCode()) continue; 2015 handle(new_function_tables->get(i), isolate_));
2191 Handle<Code> code(Code::cast(code_table->get(i)), isolate_);
2192 for (int j = 0; j < function_table_count; ++j) {
2193 ReplaceReferenceInCode(
2194 code, Handle<Object>(old_function_tables->get(j), isolate_),
2195 Handle<Object>(new_function_tables->get(j), isolate_));
2196 ReplaceReferenceInCode(
2197 code, Handle<Object>(old_signature_tables->get(j), isolate_),
2198 Handle<Object>(new_signature_tables->get(j), isolate_));
2199 }
2200 } 2016 }
2017 FixedArray* old_signature_tables =
2018 compiled_module_->ptr_to_signature_tables();
2019 DCHECK_EQ(old_signature_tables->length(), new_signature_tables->length());
2020 for (int i = 0, e = new_signature_tables->length(); i < e; ++i) {
2021 code_specialization->RelocateObject(
2022 handle(old_signature_tables->get(i), isolate_),
2023 handle(new_signature_tables->get(i), isolate_));
2024 }
2025
2201 compiled_module_->set_function_tables(new_function_tables); 2026 compiled_module_->set_function_tables(new_function_tables);
2202 compiled_module_->set_signature_tables(new_signature_tables); 2027 compiled_module_->set_signature_tables(new_signature_tables);
2203 } 2028 }
2204 2029
2205 void LoadTableSegments(Handle<FixedArray> code_table, 2030 void LoadTableSegments(Handle<FixedArray> code_table,
2206 Handle<WasmInstanceObject> instance) { 2031 Handle<WasmInstanceObject> instance) {
2207 int function_table_count = 2032 int function_table_count =
2208 static_cast<int>(module_->function_tables.size()); 2033 static_cast<int>(module_->function_tables.size());
2209 for (int index = 0; index < function_table_count; ++index) { 2034 for (int index = 0; index < function_table_count; ++index) {
2210 WasmIndirectFunctionTable& table = module_->function_tables[index]; 2035 WasmIndirectFunctionTable& table = module_->function_tables[index];
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2381 if (old_size != 0) { 2206 if (old_size != 0) {
2382 memcpy(new_mem_start, old_mem_start, old_size); 2207 memcpy(new_mem_start, old_mem_start, old_size);
2383 } 2208 }
2384 return new_buffer; 2209 return new_buffer;
2385 } 2210 }
2386 2211
2387 void UncheckedUpdateInstanceMemory(Isolate* isolate, 2212 void UncheckedUpdateInstanceMemory(Isolate* isolate,
2388 Handle<WasmInstanceObject> instance, 2213 Handle<WasmInstanceObject> instance,
2389 Address old_mem_start, uint32_t old_size) { 2214 Address old_mem_start, uint32_t old_size) {
2390 DCHECK(instance->has_memory_buffer()); 2215 DCHECK(instance->has_memory_buffer());
2391 Handle<JSArrayBuffer> new_buffer(instance->memory_buffer()); 2216 Handle<JSArrayBuffer> mem_buffer(instance->memory_buffer());
2392 uint32_t new_size = new_buffer->byte_length()->Number(); 2217 uint32_t new_size = mem_buffer->byte_length()->Number();
2393 DCHECK(new_size <= std::numeric_limits<uint32_t>::max()); 2218 Address new_mem_start = static_cast<Address>(mem_buffer->backing_store());
2394 Address new_mem_start = static_cast<Address>(new_buffer->backing_store());
2395 DCHECK_NOT_NULL(new_mem_start); 2219 DCHECK_NOT_NULL(new_mem_start);
2396 Handle<FixedArray> code_table = instance->compiled_module()->code_table(); 2220 Zone specialization_zone(isolate->allocator(), ZONE_NAME);
2397 RelocateMemoryReferencesInCode( 2221 CodeSpecialization code_specialization(isolate, &specialization_zone);
2398 code_table, instance->compiled_module()->module()->num_imported_functions, 2222 code_specialization.RelocateMemoryReferences(old_mem_start, old_size,
2399 old_mem_start, new_mem_start, old_size, new_size); 2223 new_mem_start, new_size);
2224 code_specialization.ApplyToWholeInstance(*instance);
2400 } 2225 }
2401 2226
2402 void DetachArrayBuffer(Isolate* isolate, Handle<JSArrayBuffer> buffer) { 2227 void DetachArrayBuffer(Isolate* isolate, Handle<JSArrayBuffer> buffer) {
2403 const bool has_guard_regions = 2228 const bool has_guard_regions =
2404 (!buffer.is_null() && buffer->has_guard_region()); 2229 (!buffer.is_null() && buffer->has_guard_region());
2405 void* backing_store = buffer->backing_store(); 2230 void* backing_store = buffer->backing_store();
2406 if (backing_store != nullptr) { 2231 if (backing_store != nullptr) {
2407 DCHECK(!buffer->is_neuterable()); 2232 DCHECK(!buffer->is_neuterable());
2408 int64_t byte_length = NumberToSize(buffer->byte_length()); 2233 int64_t byte_length = NumberToSize(buffer->byte_length());
2409 buffer->set_is_neuterable(true); 2234 buffer->set_is_neuterable(true);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
2527 } else { 2352 } else {
2528 return GrowWebAssemblyMemory(isolate, handle(instance_obj->memory_object()), 2353 return GrowWebAssemblyMemory(isolate, handle(instance_obj->memory_object()),
2529 pages); 2354 pages);
2530 } 2355 }
2531 } 2356 }
2532 2357
2533 void wasm::GrowDispatchTables(Isolate* isolate, 2358 void wasm::GrowDispatchTables(Isolate* isolate,
2534 Handle<FixedArray> dispatch_tables, 2359 Handle<FixedArray> dispatch_tables,
2535 uint32_t old_size, uint32_t count) { 2360 uint32_t old_size, uint32_t count) {
2536 DCHECK_EQ(0, dispatch_tables->length() % 4); 2361 DCHECK_EQ(0, dispatch_tables->length() % 4);
2362
2363 Zone specialization_zone(isolate->allocator(), ZONE_NAME);
2537 for (int i = 0; i < dispatch_tables->length(); i += 4) { 2364 for (int i = 0; i < dispatch_tables->length(); i += 4) {
2538 Handle<FixedArray> old_function_table( 2365 Handle<FixedArray> old_function_table(
2539 FixedArray::cast(dispatch_tables->get(i + 2))); 2366 FixedArray::cast(dispatch_tables->get(i + 2)));
2540 Handle<FixedArray> old_signature_table( 2367 Handle<FixedArray> old_signature_table(
2541 FixedArray::cast(dispatch_tables->get(i + 3))); 2368 FixedArray::cast(dispatch_tables->get(i + 3)));
2542 Handle<FixedArray> new_function_table = 2369 Handle<FixedArray> new_function_table =
2543 isolate->factory()->CopyFixedArrayAndGrow(old_function_table, count); 2370 isolate->factory()->CopyFixedArrayAndGrow(old_function_table, count);
2544 Handle<FixedArray> new_signature_table = 2371 Handle<FixedArray> new_signature_table =
2545 isolate->factory()->CopyFixedArrayAndGrow(old_signature_table, count); 2372 isolate->factory()->CopyFixedArrayAndGrow(old_signature_table, count);
2546 2373
2547 // Get code table for the instance
2548 Handle<WasmInstanceObject> instance(
2549 WasmInstanceObject::cast(dispatch_tables->get(i)));
2550 Handle<FixedArray> code_table(instance->compiled_module()->code_table());
2551
2552 // Relocate size references
2553 RelocateTableSizeReferences(code_table, old_size, old_size + count);
2554
2555 // Replace references of old tables with new tables.
2556 for (int j = 0; j < code_table->length(); ++j) {
2557 if (!code_table->get(j)->IsCode()) continue;
2558 Handle<Code> code = Handle<Code>(Code::cast(code_table->get(j)));
2559 ReplaceReferenceInCode(code, old_function_table, new_function_table);
2560 ReplaceReferenceInCode(code, old_signature_table, new_signature_table);
2561 }
2562
2563 // Update dispatch tables with new function/signature tables 2374 // Update dispatch tables with new function/signature tables
2564 dispatch_tables->set(i + 2, *new_function_table); 2375 dispatch_tables->set(i + 2, *new_function_table);
2565 dispatch_tables->set(i + 3, *new_signature_table); 2376 dispatch_tables->set(i + 3, *new_signature_table);
2377
2378 // Patch the code of the respective instance.
2379 CodeSpecialization code_specialization(isolate, &specialization_zone);
2380 code_specialization.PatchTableSize(old_size, old_size + count);
2381 code_specialization.RelocateObject(old_function_table, new_function_table);
2382 code_specialization.RelocateObject(old_signature_table,
2383 new_signature_table);
2384 code_specialization.ApplyToWholeInstance(
2385 WasmInstanceObject::cast(dispatch_tables->get(i)));
2566 } 2386 }
2567 } 2387 }
2568 2388
2569 void testing::ValidateInstancesChain(Isolate* isolate, 2389 void testing::ValidateInstancesChain(Isolate* isolate,
2570 Handle<WasmModuleObject> module_obj, 2390 Handle<WasmModuleObject> module_obj,
2571 int instance_count) { 2391 int instance_count) {
2572 CHECK_GE(instance_count, 0); 2392 CHECK_GE(instance_count, 0);
2573 DisallowHeapAllocation no_gc; 2393 DisallowHeapAllocation no_gc;
2574 WasmCompiledModule* compiled_module = module_obj->compiled_module(); 2394 WasmCompiledModule* compiled_module = module_obj->compiled_module();
2575 CHECK_EQ(JSObject::cast(compiled_module->ptr_to_weak_wasm_module()->value()), 2395 CHECK_EQ(JSObject::cast(compiled_module->ptr_to_weak_wasm_module()->value()),
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
2945 Handle<String> module_property_name = 2765 Handle<String> module_property_name =
2946 isolate->factory()->InternalizeUtf8String("module"); 2766 isolate->factory()->InternalizeUtf8String("module");
2947 Handle<String> instance_property_name = 2767 Handle<String> instance_property_name =
2948 isolate->factory()->InternalizeUtf8String("instance"); 2768 isolate->factory()->InternalizeUtf8String("instance");
2949 JSObject::AddProperty(ret, module_property_name, module, NONE); 2769 JSObject::AddProperty(ret, module_property_name, module, NONE);
2950 JSObject::AddProperty(ret, instance_property_name, 2770 JSObject::AddProperty(ret, instance_property_name,
2951 instance_object.ToHandleChecked(), NONE); 2771 instance_object.ToHandleChecked(), NONE);
2952 2772
2953 ResolvePromise(isolate, promise, ret); 2773 ResolvePromise(isolate, promise, ret);
2954 } 2774 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-code-specialization.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698