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 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 } | 478 } |
479 uint32_t compiled_max_pages = compiled_module()->module()->max_mem_pages; | 479 uint32_t compiled_max_pages = compiled_module()->module()->max_mem_pages; |
480 Isolate* isolate = GetIsolate(); | 480 Isolate* isolate = GetIsolate(); |
481 assert(compiled_module()->module()->is_wasm()); | 481 assert(compiled_module()->module()->is_wasm()); |
482 isolate->counters()->wasm_wasm_max_mem_pages_count()->AddSample( | 482 isolate->counters()->wasm_wasm_max_mem_pages_count()->AddSample( |
483 compiled_max_pages); | 483 compiled_max_pages); |
484 if (compiled_max_pages != 0) return compiled_max_pages; | 484 if (compiled_max_pages != 0) return compiled_max_pages; |
485 return FLAG_wasm_max_mem_pages; | 485 return FLAG_wasm_max_mem_pages; |
486 } | 486 } |
487 | 487 |
488 bool WasmExportedFunction::IsWasmExportedFunction(Object* object) { | |
489 if (!object) return false; | |
Igor Sheludko
2017/07/18 17:32:39
This check is not necessary. IsJSFunction() will d
titzer
2017/07/18 18:07:40
Done.
| |
490 if (!object->IsJSFunction()) return false; | |
491 Handle<JSFunction> js_function(JSFunction::cast(object)); | |
492 if (Code::JS_TO_WASM_FUNCTION != js_function->code()->kind()) return false; | |
493 | |
494 Handle<Symbol> symbol(js_function->GetHeap()->wasm_instance_symbol()); | |
Igor Sheludko
2017/07/18 17:32:38
This way we will reuse an existing handle instead
titzer
2017/07/18 18:07:40
Done.
| |
495 MaybeHandle<Object> result = | |
496 JSObject::GetPropertyOrElement(js_function, symbol); | |
497 if (result.is_null()) return false; | |
498 return result.ToHandleChecked()->IsWasmInstanceObject(); | |
Igor Sheludko
2017/07/18 17:32:38
Canonical way of using MaybeHandles would look lik
titzer
2017/07/18 18:07:40
Done.
| |
499 } | |
500 | |
488 WasmExportedFunction* WasmExportedFunction::cast(Object* object) { | 501 WasmExportedFunction* WasmExportedFunction::cast(Object* object) { |
489 DCHECK(object && object->IsJSFunction()); | 502 DCHECK(IsWasmExportedFunction(object)); |
490 DCHECK_EQ(Code::JS_TO_WASM_FUNCTION, | |
491 JSFunction::cast(object)->code()->kind()); | |
492 // TODO(titzer): brand check for WasmExportedFunction. | |
493 return reinterpret_cast<WasmExportedFunction*>(object); | 503 return reinterpret_cast<WasmExportedFunction*>(object); |
494 } | 504 } |
495 | 505 |
506 WasmInstanceObject* WasmExportedFunction::instance() { | |
507 Handle<Symbol> symbol(GetHeap()->wasm_instance_symbol()); | |
Igor Sheludko
2017/07/18 17:32:38
GetInstance()->wasm_instance_symbol() to avoid han
titzer
2017/07/18 18:07:40
Done.
| |
508 MaybeHandle<Object> result = | |
509 JSObject::GetPropertyOrElement(handle(this), symbol); | |
Igor Sheludko
2017/07/18 17:32:38
You are calling handlified code from non-handlifie
titzer
2017/07/18 18:07:40
Done.
| |
510 return WasmInstanceObject::cast(*(result.ToHandleChecked())); | |
511 } | |
512 | |
513 int WasmExportedFunction::function_index() { | |
514 Handle<Symbol> symbol(GetHeap()->wasm_function_index_symbol()); | |
Igor Sheludko
2017/07/18 17:32:38
Same here.
titzer
2017/07/18 18:07:40
Done.
| |
515 MaybeHandle<Object> result = | |
516 JSObject::GetPropertyOrElement(handle(this), symbol); | |
Igor Sheludko
2017/07/18 17:32:38
And here. If the index field ever become an inobje
titzer
2017/07/18 18:07:40
I've added a DisallowHeapAllocation here.
| |
517 return result.ToHandleChecked()->Number(); | |
518 } | |
519 | |
496 Handle<WasmExportedFunction> WasmExportedFunction::New( | 520 Handle<WasmExportedFunction> WasmExportedFunction::New( |
497 Isolate* isolate, Handle<WasmInstanceObject> instance, | 521 Isolate* isolate, Handle<WasmInstanceObject> instance, |
498 MaybeHandle<String> maybe_name, int func_index, int arity, | 522 MaybeHandle<String> maybe_name, int func_index, int arity, |
499 Handle<Code> export_wrapper) { | 523 Handle<Code> export_wrapper) { |
524 DCHECK_EQ(Code::JS_TO_WASM_FUNCTION, export_wrapper->kind()); | |
500 Handle<String> name; | 525 Handle<String> name; |
501 if (!maybe_name.ToHandle(&name)) { | 526 if (!maybe_name.ToHandle(&name)) { |
502 EmbeddedVector<char, 16> buffer; | 527 EmbeddedVector<char, 16> buffer; |
503 int length = SNPrintF(buffer, "%d", func_index); | 528 int length = SNPrintF(buffer, "%d", func_index); |
504 name = isolate->factory() | 529 name = isolate->factory() |
505 ->NewStringFromOneByte( | 530 ->NewStringFromOneByte( |
506 Vector<uint8_t>::cast(buffer.SubVector(0, length))) | 531 Vector<uint8_t>::cast(buffer.SubVector(0, length))) |
507 .ToHandleChecked(); | 532 .ToHandleChecked(); |
508 } | 533 } |
509 DCHECK_EQ(Code::JS_TO_WASM_FUNCTION, export_wrapper->kind()); | |
510 Handle<SharedFunctionInfo> shared = | 534 Handle<SharedFunctionInfo> shared = |
511 isolate->factory()->NewSharedFunctionInfo(name, export_wrapper, false); | 535 isolate->factory()->NewSharedFunctionInfo(name, export_wrapper, false); |
512 shared->set_length(arity); | 536 shared->set_length(arity); |
513 shared->set_internal_formal_parameter_count(arity); | 537 shared->set_internal_formal_parameter_count(arity); |
514 Handle<JSFunction> js_function = isolate->factory()->NewFunction( | 538 Handle<JSFunction> js_function = isolate->factory()->NewFunction( |
515 isolate->wasm_function_map(), name, export_wrapper); | 539 handle(isolate->native_context()->sloppy_function_map()), name, |
Igor Sheludko
2017/07/18 17:32:38
Just isolate->sloppy_function_map() to make it nic
titzer
2017/07/18 18:07:40
Done.
| |
540 export_wrapper); | |
516 | 541 |
517 Handle<WasmExportedFunction> function( | 542 js_function->set_shared(*shared); |
518 reinterpret_cast<WasmExportedFunction*>(*js_function), isolate); | 543 Handle<Symbol> instance_symbol(isolate->heap()->wasm_instance_symbol()); |
544 JSObject::AddProperty(js_function, instance_symbol, instance, DONT_ENUM); | |
519 | 545 |
520 function->set_shared(*shared); | 546 Handle<Symbol> function_index_symbol( |
521 function->set_instance(*instance); | 547 isolate->heap()->wasm_function_index_symbol()); |
Igor Sheludko
2017/07/18 17:32:39
s/heap()->// to avoid handle creation.
titzer
2017/07/18 18:07:40
Done.
| |
522 function->set_function_index(func_index); | 548 JSObject::AddProperty(js_function, function_index_symbol, |
549 isolate->factory()->NewNumber(func_index), DONT_ENUM); | |
523 | 550 |
524 return Handle<WasmExportedFunction>::cast(function); | 551 return Handle<WasmExportedFunction>::cast(js_function); |
525 } | 552 } |
526 | 553 |
527 bool WasmSharedModuleData::IsWasmSharedModuleData(Object* object) { | 554 bool WasmSharedModuleData::IsWasmSharedModuleData(Object* object) { |
528 if (!object->IsFixedArray()) return false; | 555 if (!object->IsFixedArray()) return false; |
529 FixedArray* arr = FixedArray::cast(object); | 556 FixedArray* arr = FixedArray::cast(object); |
530 if (arr->length() != kFieldCount) return false; | 557 if (arr->length() != kFieldCount) return false; |
531 Isolate* isolate = arr->GetIsolate(); | 558 Isolate* isolate = arr->GetIsolate(); |
532 if (!arr->get(kModuleWrapperIndex)->IsForeign()) return false; | 559 if (!arr->get(kModuleWrapperIndex)->IsForeign()) return false; |
533 if (!arr->get(kModuleBytesIndex)->IsUndefined(isolate) && | 560 if (!arr->get(kModuleBytesIndex)->IsUndefined(isolate) && |
534 !arr->get(kModuleBytesIndex)->IsSeqOneByteString()) | 561 !arr->get(kModuleBytesIndex)->IsSeqOneByteString()) |
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1376 Isolate* isolate, Handle<WasmInstanceObject> instance, Handle<Code> caller, | 1403 Isolate* isolate, Handle<WasmInstanceObject> instance, Handle<Code> caller, |
1377 int offset, int func_index, bool patch_caller) { | 1404 int offset, int func_index, bool patch_caller) { |
1378 isolate->set_context(*instance->compiled_module()->native_context()); | 1405 isolate->set_context(*instance->compiled_module()->native_context()); |
1379 Object* orch_obj = | 1406 Object* orch_obj = |
1380 instance->compiled_module()->shared()->lazy_compilation_orchestrator(); | 1407 instance->compiled_module()->shared()->lazy_compilation_orchestrator(); |
1381 LazyCompilationOrchestrator* orch = | 1408 LazyCompilationOrchestrator* orch = |
1382 Managed<LazyCompilationOrchestrator>::cast(orch_obj)->get(); | 1409 Managed<LazyCompilationOrchestrator>::cast(orch_obj)->get(); |
1383 return orch->CompileLazy(isolate, instance, caller, offset, func_index, | 1410 return orch->CompileLazy(isolate, instance, caller, offset, func_index, |
1384 patch_caller); | 1411 patch_caller); |
1385 } | 1412 } |
OLD | NEW |