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

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

Issue 2977113002: [wasm] Fix user properties for exported wasm functions and add extensive tests. (Closed)
Patch Set: Address nit Created 3 years, 5 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-objects.h ('k') | test/mjsunit/wasm/user-properties.js » ('j') | 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 "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
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->IsJSFunction()) return false;
490 Handle<JSFunction> js_function(JSFunction::cast(object));
491 if (Code::JS_TO_WASM_FUNCTION != js_function->code()->kind()) return false;
492
493 Handle<Symbol> symbol(
494 js_function->GetIsolate()->factory()->wasm_instance_symbol());
495 MaybeHandle<Object> maybe_result =
496 JSObject::GetPropertyOrElement(js_function, symbol);
497 Handle<Object> result;
498 if (!maybe_result.ToHandle(&result)) return false;
499 return result->IsWasmInstanceObject();
500 }
501
488 WasmExportedFunction* WasmExportedFunction::cast(Object* object) { 502 WasmExportedFunction* WasmExportedFunction::cast(Object* object) {
489 DCHECK(object && object->IsJSFunction()); 503 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); 504 return reinterpret_cast<WasmExportedFunction*>(object);
494 } 505 }
495 506
507 WasmInstanceObject* WasmExportedFunction::instance() {
508 DisallowHeapAllocation no_allocation;
509 Handle<Symbol> symbol(GetIsolate()->factory()->wasm_instance_symbol());
510 MaybeHandle<Object> result =
511 JSObject::GetPropertyOrElement(handle(this), symbol);
512 return WasmInstanceObject::cast(*(result.ToHandleChecked()));
513 }
514
515 int WasmExportedFunction::function_index() {
516 DisallowHeapAllocation no_allocation;
517 Handle<Symbol> symbol = GetIsolate()->factory()->wasm_function_index_symbol();
518 MaybeHandle<Object> result =
519 JSObject::GetPropertyOrElement(handle(this), symbol);
520 return result.ToHandleChecked()->Number();
521 }
522
496 Handle<WasmExportedFunction> WasmExportedFunction::New( 523 Handle<WasmExportedFunction> WasmExportedFunction::New(
497 Isolate* isolate, Handle<WasmInstanceObject> instance, 524 Isolate* isolate, Handle<WasmInstanceObject> instance,
498 MaybeHandle<String> maybe_name, int func_index, int arity, 525 MaybeHandle<String> maybe_name, int func_index, int arity,
499 Handle<Code> export_wrapper) { 526 Handle<Code> export_wrapper) {
527 DCHECK_EQ(Code::JS_TO_WASM_FUNCTION, export_wrapper->kind());
500 Handle<String> name; 528 Handle<String> name;
501 if (!maybe_name.ToHandle(&name)) { 529 if (!maybe_name.ToHandle(&name)) {
502 EmbeddedVector<char, 16> buffer; 530 EmbeddedVector<char, 16> buffer;
503 int length = SNPrintF(buffer, "%d", func_index); 531 int length = SNPrintF(buffer, "%d", func_index);
504 name = isolate->factory() 532 name = isolate->factory()
505 ->NewStringFromOneByte( 533 ->NewStringFromOneByte(
506 Vector<uint8_t>::cast(buffer.SubVector(0, length))) 534 Vector<uint8_t>::cast(buffer.SubVector(0, length)))
507 .ToHandleChecked(); 535 .ToHandleChecked();
508 } 536 }
509 DCHECK_EQ(Code::JS_TO_WASM_FUNCTION, export_wrapper->kind());
510 Handle<SharedFunctionInfo> shared = 537 Handle<SharedFunctionInfo> shared =
511 isolate->factory()->NewSharedFunctionInfo(name, export_wrapper, false); 538 isolate->factory()->NewSharedFunctionInfo(name, export_wrapper, false);
512 shared->set_length(arity); 539 shared->set_length(arity);
513 shared->set_internal_formal_parameter_count(arity); 540 shared->set_internal_formal_parameter_count(arity);
514 Handle<JSFunction> js_function = isolate->factory()->NewFunction( 541 Handle<JSFunction> js_function = isolate->factory()->NewFunction(
515 isolate->wasm_function_map(), name, export_wrapper); 542 isolate->sloppy_function_map(), name, export_wrapper);
516 543
517 Handle<WasmExportedFunction> function( 544 js_function->set_shared(*shared);
518 reinterpret_cast<WasmExportedFunction*>(*js_function), isolate); 545 Handle<Symbol> instance_symbol(isolate->factory()->wasm_instance_symbol());
546 JSObject::AddProperty(js_function, instance_symbol, instance, DONT_ENUM);
519 547
520 function->set_shared(*shared); 548 Handle<Symbol> function_index_symbol(
521 function->set_instance(*instance); 549 isolate->factory()->wasm_function_index_symbol());
522 function->set_function_index(func_index); 550 JSObject::AddProperty(js_function, function_index_symbol,
551 isolate->factory()->NewNumber(func_index), DONT_ENUM);
523 552
524 return Handle<WasmExportedFunction>::cast(function); 553 return Handle<WasmExportedFunction>::cast(js_function);
525 } 554 }
526 555
527 bool WasmSharedModuleData::IsWasmSharedModuleData(Object* object) { 556 bool WasmSharedModuleData::IsWasmSharedModuleData(Object* object) {
528 if (!object->IsFixedArray()) return false; 557 if (!object->IsFixedArray()) return false;
529 FixedArray* arr = FixedArray::cast(object); 558 FixedArray* arr = FixedArray::cast(object);
530 if (arr->length() != kFieldCount) return false; 559 if (arr->length() != kFieldCount) return false;
531 Isolate* isolate = arr->GetIsolate(); 560 Isolate* isolate = arr->GetIsolate();
532 if (!arr->get(kModuleWrapperIndex)->IsForeign()) return false; 561 if (!arr->get(kModuleWrapperIndex)->IsForeign()) return false;
533 if (!arr->get(kModuleBytesIndex)->IsUndefined(isolate) && 562 if (!arr->get(kModuleBytesIndex)->IsUndefined(isolate) &&
534 !arr->get(kModuleBytesIndex)->IsSeqOneByteString()) 563 !arr->get(kModuleBytesIndex)->IsSeqOneByteString())
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 Isolate* isolate, Handle<WasmInstanceObject> instance, Handle<Code> caller, 1405 Isolate* isolate, Handle<WasmInstanceObject> instance, Handle<Code> caller,
1377 int offset, int func_index, bool patch_caller) { 1406 int offset, int func_index, bool patch_caller) {
1378 isolate->set_context(*instance->compiled_module()->native_context()); 1407 isolate->set_context(*instance->compiled_module()->native_context());
1379 Object* orch_obj = 1408 Object* orch_obj =
1380 instance->compiled_module()->shared()->lazy_compilation_orchestrator(); 1409 instance->compiled_module()->shared()->lazy_compilation_orchestrator();
1381 LazyCompilationOrchestrator* orch = 1410 LazyCompilationOrchestrator* orch =
1382 Managed<LazyCompilationOrchestrator>::cast(orch_obj)->get(); 1411 Managed<LazyCompilationOrchestrator>::cast(orch_obj)->get();
1383 return orch->CompileLazy(isolate, instance, caller, offset, func_index, 1412 return orch->CompileLazy(isolate, instance, caller, offset, func_index,
1384 patch_caller); 1413 patch_caller);
1385 } 1414 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-objects.h ('k') | test/mjsunit/wasm/user-properties.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698