OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 <unordered_map> | 5 #include <unordered_map> |
6 | 6 |
7 #include "src/assembler-inl.h" | 7 #include "src/assembler-inl.h" |
8 #include "src/assert-scope.h" | 8 #include "src/assert-scope.h" |
9 #include "src/compiler/wasm-compiler.h" | 9 #include "src/compiler/wasm-compiler.h" |
10 #include "src/debug/debug-scopes.h" | 10 #include "src/debug/debug-scopes.h" |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 isolate_->factory()->NewJSArrayWithElements(local_scope); | 532 isolate_->factory()->NewJSArrayWithElements(local_scope); |
533 Handle<FixedArray> all_scopes = isolate_->factory()->NewFixedArray(2); | 533 Handle<FixedArray> all_scopes = isolate_->factory()->NewFixedArray(2); |
534 all_scopes->set(0, *global_jsarr); | 534 all_scopes->set(0, *global_jsarr); |
535 all_scopes->set(1, *local_jsarr); | 535 all_scopes->set(1, *local_jsarr); |
536 return isolate_->factory()->NewJSArrayWithElements(all_scopes); | 536 return isolate_->factory()->NewJSArrayWithElements(all_scopes); |
537 } | 537 } |
538 }; | 538 }; |
539 | 539 |
540 InterpreterHandle* GetOrCreateInterpreterHandle( | 540 InterpreterHandle* GetOrCreateInterpreterHandle( |
541 Isolate* isolate, Handle<WasmDebugInfo> debug_info) { | 541 Isolate* isolate, Handle<WasmDebugInfo> debug_info) { |
542 Handle<Object> handle(debug_info->get(WasmDebugInfo::kInterpreterHandle), | 542 Handle<Object> handle(debug_info->get(WasmDebugInfo::kInterpreterHandleIndex), |
543 isolate); | 543 isolate); |
544 if (handle->IsUndefined(isolate)) { | 544 if (handle->IsUndefined(isolate)) { |
545 InterpreterHandle* cpp_handle = new InterpreterHandle(isolate, *debug_info); | 545 InterpreterHandle* cpp_handle = new InterpreterHandle(isolate, *debug_info); |
546 handle = Managed<InterpreterHandle>::New(isolate, cpp_handle); | 546 handle = Managed<InterpreterHandle>::New(isolate, cpp_handle); |
547 debug_info->set(WasmDebugInfo::kInterpreterHandle, *handle); | 547 debug_info->set(WasmDebugInfo::kInterpreterHandleIndex, *handle); |
548 } | 548 } |
549 | 549 |
550 return Handle<Managed<InterpreterHandle>>::cast(handle)->get(); | 550 return Handle<Managed<InterpreterHandle>>::cast(handle)->get(); |
551 } | 551 } |
552 | 552 |
553 InterpreterHandle* GetInterpreterHandle(WasmDebugInfo* debug_info) { | 553 InterpreterHandle* GetInterpreterHandle(WasmDebugInfo* debug_info) { |
554 Object* handle_obj = debug_info->get(WasmDebugInfo::kInterpreterHandle); | 554 Object* handle_obj = debug_info->get(WasmDebugInfo::kInterpreterHandleIndex); |
555 DCHECK(!handle_obj->IsUndefined(debug_info->GetIsolate())); | 555 DCHECK(!handle_obj->IsUndefined(debug_info->GetIsolate())); |
556 return Managed<InterpreterHandle>::cast(handle_obj)->get(); | 556 return Managed<InterpreterHandle>::cast(handle_obj)->get(); |
557 } | 557 } |
558 | 558 |
559 InterpreterHandle* GetInterpreterHandleOrNull(WasmDebugInfo* debug_info) { | 559 InterpreterHandle* GetInterpreterHandleOrNull(WasmDebugInfo* debug_info) { |
560 Object* handle_obj = debug_info->get(WasmDebugInfo::kInterpreterHandle); | 560 Object* handle_obj = debug_info->get(WasmDebugInfo::kInterpreterHandleIndex); |
561 if (handle_obj->IsUndefined(debug_info->GetIsolate())) return nullptr; | 561 if (handle_obj->IsUndefined(debug_info->GetIsolate())) return nullptr; |
562 return Managed<InterpreterHandle>::cast(handle_obj)->get(); | 562 return Managed<InterpreterHandle>::cast(handle_obj)->get(); |
563 } | 563 } |
564 | 564 |
565 int GetNumFunctions(WasmInstanceObject* instance) { | 565 int GetNumFunctions(WasmInstanceObject* instance) { |
566 size_t num_functions = | 566 size_t num_functions = |
567 instance->compiled_module()->module()->functions.size(); | 567 instance->compiled_module()->module()->functions.size(); |
568 DCHECK_GE(kMaxInt, num_functions); | 568 DCHECK_GE(kMaxInt, num_functions); |
569 return static_cast<int>(num_functions); | 569 return static_cast<int>(num_functions); |
570 } | 570 } |
571 | 571 |
572 Handle<FixedArray> GetOrCreateInterpretedFunctions( | 572 Handle<FixedArray> GetOrCreateInterpretedFunctions( |
573 Isolate* isolate, Handle<WasmDebugInfo> debug_info) { | 573 Isolate* isolate, Handle<WasmDebugInfo> debug_info) { |
574 Handle<Object> obj(debug_info->get(WasmDebugInfo::kInterpretedFunctions), | 574 Handle<Object> obj(debug_info->get(WasmDebugInfo::kInterpretedFunctionsIndex), |
575 isolate); | 575 isolate); |
576 if (!obj->IsUndefined(isolate)) return Handle<FixedArray>::cast(obj); | 576 if (!obj->IsUndefined(isolate)) return Handle<FixedArray>::cast(obj); |
577 | 577 |
578 Handle<FixedArray> new_arr = isolate->factory()->NewFixedArray( | 578 Handle<FixedArray> new_arr = isolate->factory()->NewFixedArray( |
579 GetNumFunctions(debug_info->wasm_instance())); | 579 GetNumFunctions(debug_info->wasm_instance())); |
580 debug_info->set(WasmDebugInfo::kInterpretedFunctions, *new_arr); | 580 debug_info->set(WasmDebugInfo::kInterpretedFunctionsIndex, *new_arr); |
581 return new_arr; | 581 return new_arr; |
582 } | 582 } |
583 | 583 |
584 using CodeRelocationMap = IdentityMap<Handle<Code>, FreeStoreAllocationPolicy>; | 584 using CodeRelocationMap = IdentityMap<Handle<Code>, FreeStoreAllocationPolicy>; |
585 | 585 |
586 void RedirectCallsitesInCode(Code* code, CodeRelocationMap& map) { | 586 void RedirectCallsitesInCode(Code* code, CodeRelocationMap& map) { |
587 DisallowHeapAllocation no_gc; | 587 DisallowHeapAllocation no_gc; |
588 for (RelocIterator it(code, RelocInfo::kCodeTargetMask); !it.done(); | 588 for (RelocIterator it(code, RelocInfo::kCodeTargetMask); !it.done(); |
589 it.next()) { | 589 it.next()) { |
590 DCHECK(RelocInfo::IsCodeTarget(it.rinfo()->rmode())); | 590 DCHECK(RelocInfo::IsCodeTarget(it.rinfo()->rmode())); |
(...skipping 24 matching lines...) Expand all Loading... |
615 RedirectCallsitesInCode(code, map); | 615 RedirectCallsitesInCode(code, map); |
616 } | 616 } |
617 } | 617 } |
618 | 618 |
619 } // namespace | 619 } // namespace |
620 | 620 |
621 Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) { | 621 Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) { |
622 DCHECK(!instance->has_debug_info()); | 622 DCHECK(!instance->has_debug_info()); |
623 Factory* factory = instance->GetIsolate()->factory(); | 623 Factory* factory = instance->GetIsolate()->factory(); |
624 Handle<FixedArray> arr = factory->NewFixedArray(kFieldCount, TENURED); | 624 Handle<FixedArray> arr = factory->NewFixedArray(kFieldCount, TENURED); |
625 arr->set(kWrapperTracerHeader, Smi::kZero); | 625 arr->set(kInstanceIndex, *instance); |
626 arr->set(kInstance, *instance); | |
627 Handle<WasmDebugInfo> debug_info = Handle<WasmDebugInfo>::cast(arr); | 626 Handle<WasmDebugInfo> debug_info = Handle<WasmDebugInfo>::cast(arr); |
628 instance->set_debug_info(*debug_info); | 627 instance->set_debug_info(*debug_info); |
629 return debug_info; | 628 return debug_info; |
630 } | 629 } |
631 | 630 |
632 WasmInterpreter* WasmDebugInfo::SetupForTesting( | 631 WasmInterpreter* WasmDebugInfo::SetupForTesting( |
633 Handle<WasmInstanceObject> instance_obj, WasmInstance* instance) { | 632 Handle<WasmInstanceObject> instance_obj, WasmInstance* instance) { |
634 Handle<WasmDebugInfo> debug_info = WasmDebugInfo::New(instance_obj); | 633 Handle<WasmDebugInfo> debug_info = WasmDebugInfo::New(instance_obj); |
635 Isolate* isolate = instance_obj->GetIsolate(); | 634 Isolate* isolate = instance_obj->GetIsolate(); |
636 InterpreterHandle* cpp_handle = | 635 InterpreterHandle* cpp_handle = |
637 new InterpreterHandle(isolate, *debug_info, instance); | 636 new InterpreterHandle(isolate, *debug_info, instance); |
638 Handle<Object> handle = Managed<InterpreterHandle>::New(isolate, cpp_handle); | 637 Handle<Object> handle = Managed<InterpreterHandle>::New(isolate, cpp_handle); |
639 debug_info->set(kInterpreterHandle, *handle); | 638 debug_info->set(kInterpreterHandleIndex, *handle); |
640 return cpp_handle->interpreter(); | 639 return cpp_handle->interpreter(); |
641 } | 640 } |
642 | 641 |
643 bool WasmDebugInfo::IsDebugInfo(Object* object) { | 642 bool WasmDebugInfo::IsWasmDebugInfo(Object* object) { |
644 if (!object->IsFixedArray()) return false; | 643 if (!object->IsFixedArray()) return false; |
645 FixedArray* arr = FixedArray::cast(object); | 644 FixedArray* arr = FixedArray::cast(object); |
646 if (arr->length() != kFieldCount) return false; | 645 if (arr->length() != kFieldCount) return false; |
647 if (!IsWasmInstance(arr->get(kInstance))) return false; | 646 if (!arr->get(kInstanceIndex)->IsWasmInstanceObject()) return false; |
648 Isolate* isolate = arr->GetIsolate(); | 647 Isolate* isolate = arr->GetIsolate(); |
649 if (!arr->get(kInterpreterHandle)->IsUndefined(isolate) && | 648 if (!arr->get(kInterpreterHandleIndex)->IsUndefined(isolate) && |
650 !arr->get(kInterpreterHandle)->IsForeign()) | 649 !arr->get(kInterpreterHandleIndex)->IsForeign()) |
651 return false; | 650 return false; |
652 return true; | 651 return true; |
653 } | 652 } |
654 | 653 |
655 WasmDebugInfo* WasmDebugInfo::cast(Object* object) { | 654 WasmDebugInfo* WasmDebugInfo::cast(Object* object) { |
656 DCHECK(IsDebugInfo(object)); | 655 DCHECK(IsWasmDebugInfo(object)); |
657 return reinterpret_cast<WasmDebugInfo*>(object); | 656 return reinterpret_cast<WasmDebugInfo*>(object); |
658 } | 657 } |
659 | 658 |
660 WasmInstanceObject* WasmDebugInfo::wasm_instance() { | 659 WasmInstanceObject* WasmDebugInfo::wasm_instance() { |
661 return WasmInstanceObject::cast(get(kInstance)); | 660 return WasmInstanceObject::cast(get(kInstanceIndex)); |
662 } | 661 } |
663 | 662 |
664 void WasmDebugInfo::SetBreakpoint(Handle<WasmDebugInfo> debug_info, | 663 void WasmDebugInfo::SetBreakpoint(Handle<WasmDebugInfo> debug_info, |
665 int func_index, int offset) { | 664 int func_index, int offset) { |
666 Isolate* isolate = debug_info->GetIsolate(); | 665 Isolate* isolate = debug_info->GetIsolate(); |
667 InterpreterHandle* handle = GetOrCreateInterpreterHandle(isolate, debug_info); | 666 InterpreterHandle* handle = GetOrCreateInterpreterHandle(isolate, debug_info); |
668 RedirectToInterpreter(debug_info, Vector<int>(&func_index, 1)); | 667 RedirectToInterpreter(debug_info, Vector<int>(&func_index, 1)); |
669 const WasmFunction* func = &handle->module()->functions[func_index]; | 668 const WasmFunction* func = &handle->module()->functions[func_index]; |
670 handle->interpreter()->SetBreakpoint(func, offset, true); | 669 handle->interpreter()->SetBreakpoint(func, offset, true); |
671 } | 670 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 interp_handle->UpdateMemory(new_memory); | 734 interp_handle->UpdateMemory(new_memory); |
736 } | 735 } |
737 | 736 |
738 // static | 737 // static |
739 Handle<JSArray> WasmDebugInfo::GetScopeDetails(Handle<WasmDebugInfo> debug_info, | 738 Handle<JSArray> WasmDebugInfo::GetScopeDetails(Handle<WasmDebugInfo> debug_info, |
740 Address frame_pointer, | 739 Address frame_pointer, |
741 int frame_index) { | 740 int frame_index) { |
742 InterpreterHandle* interp_handle = GetInterpreterHandle(*debug_info); | 741 InterpreterHandle* interp_handle = GetInterpreterHandle(*debug_info); |
743 return interp_handle->GetScopeDetails(frame_pointer, frame_index, debug_info); | 742 return interp_handle->GetScopeDetails(frame_pointer, frame_index, debug_info); |
744 } | 743 } |
OLD | NEW |