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

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

Issue 2626253002: [wasm] Set and store breakpoints in wasm (Closed)
Patch Set: Remove CheckBreakPoints methods Created 3 years, 11 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') | 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 "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/base/iterator.h"
8 #include "src/debug/debug-interface.h" 9 #include "src/debug/debug-interface.h"
9 #include "src/wasm/module-decoder.h" 10 #include "src/wasm/module-decoder.h"
10 #include "src/wasm/wasm-module.h" 11 #include "src/wasm/wasm-module.h"
11 #include "src/wasm/wasm-text.h" 12 #include "src/wasm/wasm-text.h"
12 13
13 #define TRACE(...) \ 14 #define TRACE(...) \
14 do { \ 15 do { \
15 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \ 16 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \
16 } while (false) 17 } while (false)
17 18
(...skipping 12 matching lines...) Expand all
30 DEFINE_GETTER0(getter, Container, name, field, type) \ 31 DEFINE_GETTER0(getter, Container, name, field, type) \
31 void Container::set_##name(type* value) { return setter(field, value); } 32 void Container::set_##name(type* value) { return setter(field, value); }
32 33
33 #define DEFINE_OPTIONAL_ACCESSORS0(getter, setter, Container, name, field, \ 34 #define DEFINE_OPTIONAL_ACCESSORS0(getter, setter, Container, name, field, \
34 type) \ 35 type) \
35 DEFINE_ACCESSORS0(getter, setter, Container, name, field, type) \ 36 DEFINE_ACCESSORS0(getter, setter, Container, name, field, type) \
36 bool Container::has_##name() { \ 37 bool Container::has_##name() { \
37 return !getter(field)->IsUndefined(GetIsolate()); \ 38 return !getter(field)->IsUndefined(GetIsolate()); \
38 } 39 }
39 40
41 #define DEFINE_OPTIONAL_GETTER0(getter, Container, name, field, type) \
42 DEFINE_GETTER0(getter, Container, name, field, type) \
43 bool Container::has_##name() { \
44 return !getter(field)->IsUndefined(GetIsolate()); \
45 }
46
47 #define DEFINE_GETTER0(getter, Container, name, field, type) \
48 type* Container::name() { return type::cast(getter(field)); }
49
40 #define DEFINE_OBJ_GETTER(Container, name, field, type) \ 50 #define DEFINE_OBJ_GETTER(Container, name, field, type) \
41 DEFINE_GETTER0(GetInternalField, Container, name, field, type) 51 DEFINE_GETTER0(GetInternalField, Container, name, field, type)
42 #define DEFINE_OBJ_ACCESSORS(Container, name, field, type) \ 52 #define DEFINE_OBJ_ACCESSORS(Container, name, field, type) \
43 DEFINE_ACCESSORS0(GetInternalField, SetInternalField, Container, name, \ 53 DEFINE_ACCESSORS0(GetInternalField, SetInternalField, Container, name, \
44 field, type) 54 field, type)
45 #define DEFINE_OPTIONAL_OBJ_ACCESSORS(Container, name, field, type) \ 55 #define DEFINE_OPTIONAL_OBJ_ACCESSORS(Container, name, field, type) \
46 DEFINE_OPTIONAL_ACCESSORS0(GetInternalField, SetInternalField, Container, \ 56 DEFINE_OPTIONAL_ACCESSORS0(GetInternalField, SetInternalField, Container, \
47 name, field, type) 57 name, field, type)
48 #define DEFINE_ARR_GETTER(Container, name, field, type) \ 58 #define DEFINE_ARR_GETTER(Container, name, field, type) \
49 DEFINE_GETTER0(get, Container, name, field, type) 59 DEFINE_GETTER0(get, Container, name, field, type)
50 #define DEFINE_ARR_ACCESSORS(Container, name, field, type) \ 60 #define DEFINE_ARR_ACCESSORS(Container, name, field, type) \
51 DEFINE_ACCESSORS0(get, set, Container, name, field, type) 61 DEFINE_ACCESSORS0(get, set, Container, name, field, type)
52 #define DEFINE_OPTIONAL_ARR_ACCESSORS(Container, name, field, type) \ 62 #define DEFINE_OPTIONAL_ARR_ACCESSORS(Container, name, field, type) \
53 DEFINE_OPTIONAL_ACCESSORS0(get, set, Container, name, field, type) 63 DEFINE_OPTIONAL_ACCESSORS0(get, set, Container, name, field, type)
64 #define DEFINE_OPTIONAL_ARR_GETTER(Container, name, field, type) \
65 DEFINE_OPTIONAL_GETTER0(get, Container, name, field, type)
54 66
55 namespace { 67 namespace {
56 68
57 uint32_t SafeUint32(Object* value) { 69 uint32_t SafeUint32(Object* value) {
58 if (value->IsSmi()) { 70 if (value->IsSmi()) {
59 int32_t val = Smi::cast(value)->value(); 71 int32_t val = Smi::cast(value)->value();
60 CHECK_GE(val, 0); 72 CHECK_GE(val, 0);
61 return static_cast<uint32_t>(val); 73 return static_cast<uint32_t>(val);
62 } 74 }
63 DCHECK(value->IsHeapNumber()); 75 DCHECK(value->IsHeapNumber());
64 HeapNumber* num = HeapNumber::cast(value); 76 HeapNumber* num = HeapNumber::cast(value);
65 CHECK_GE(num->value(), 0.0); 77 CHECK_GE(num->value(), 0.0);
66 CHECK_LE(num->value(), kMaxUInt32); 78 CHECK_LE(num->value(), kMaxUInt32);
67 return static_cast<uint32_t>(num->value()); 79 return static_cast<uint32_t>(num->value());
68 } 80 }
69 81
70 int32_t SafeInt32(Object* value) { 82 int32_t SafeInt32(Object* value) {
71 if (value->IsSmi()) { 83 if (value->IsSmi()) {
72 return Smi::cast(value)->value(); 84 return Smi::cast(value)->value();
73 } 85 }
74 DCHECK(value->IsHeapNumber()); 86 DCHECK(value->IsHeapNumber());
75 HeapNumber* num = HeapNumber::cast(value); 87 HeapNumber* num = HeapNumber::cast(value);
76 CHECK_GE(num->value(), Smi::kMinValue); 88 CHECK_GE(num->value(), Smi::kMinValue);
77 CHECK_LE(num->value(), Smi::kMaxValue); 89 CHECK_LE(num->value(), Smi::kMaxValue);
78 return static_cast<int32_t>(num->value()); 90 return static_cast<int32_t>(num->value());
79 } 91 }
80 92
93 // An iterator that returns first the module itself, then all modules linked via
94 // next, then all linked via prev.
95 class CompiledModulesIterator
96 : public std::iterator<std::input_iterator_tag,
97 Handle<WasmCompiledModule>> {
98 public:
99 CompiledModulesIterator(Isolate* isolate,
100 Handle<WasmCompiledModule> start_module, bool at_end)
101 : isolate_(isolate),
102 start_module_(start_module),
103 current_(at_end ? Handle<WasmCompiledModule>::null() : start_module) {}
104
105 Handle<WasmCompiledModule> operator*() const {
106 DCHECK(!current_.is_null());
107 return current_;
108 }
109
110 void operator++() { Advance(); }
111
112 bool operator!=(const CompiledModulesIterator& other) {
113 DCHECK(start_module_.is_identical_to(other.start_module_));
114 return !current_.is_identical_to(other.current_);
115 }
116
117 private:
118 void Advance() {
119 DCHECK(!current_.is_null());
120 if (!is_backwards_) {
121 if (current_->has_weak_next_instance()) {
122 WeakCell* weak_next = current_->ptr_to_weak_next_instance();
123 if (!weak_next->cleared()) {
124 current_ =
125 handle(WasmCompiledModule::cast(weak_next->value()), isolate_);
126 return;
127 }
128 }
129 // No more modules in next-links, now try the previous-links.
130 is_backwards_ = true;
131 current_ = start_module_;
132 }
133 if (current_->has_weak_prev_instance()) {
134 WeakCell* weak_prev = current_->ptr_to_weak_prev_instance();
135 if (!weak_prev->cleared()) {
136 current_ =
137 handle(WasmCompiledModule::cast(weak_prev->value()), isolate_);
138 return;
139 }
140 }
141 current_ = Handle<WasmCompiledModule>::null();
142 }
143
144 friend class CompiledModuleInstancesIterator;
145 Isolate* isolate_;
146 Handle<WasmCompiledModule> start_module_;
147 Handle<WasmCompiledModule> current_;
148 bool is_backwards_ = false;
149 };
150
151 // An iterator based on the CompiledModulesIterator, but it returns all live
152 // instances, not the WasmCompiledModules itself.
153 class CompiledModuleInstancesIterator
154 : public std::iterator<std::input_iterator_tag,
155 Handle<WasmInstanceObject>> {
156 public:
157 CompiledModuleInstancesIterator(Isolate* isolate,
158 Handle<WasmCompiledModule> start_module,
159 bool at_end)
160 : it(isolate, start_module, at_end) {
161 while (NeedToAdvance()) ++it;
162 }
163
164 Handle<WasmInstanceObject> operator*() {
165 return handle(
166 WasmInstanceObject::cast((*it)->weak_owning_instance()->value()),
167 it.isolate_);
168 }
169
170 void operator++() {
171 do {
172 ++it;
173 } while (NeedToAdvance());
174 }
175
176 bool operator!=(const CompiledModuleInstancesIterator& other) {
177 return it != other.it;
178 }
179
180 private:
181 bool NeedToAdvance() {
182 return !it.current_.is_null() &&
183 (!it.current_->has_weak_owning_instance() ||
184 it.current_->ptr_to_weak_owning_instance()->cleared());
185 }
186 CompiledModulesIterator it;
187 };
188
189 v8::base::iterator_range<CompiledModuleInstancesIterator>
190 iterate_compiled_module_instance_chain(
191 Isolate* isolate, Handle<WasmCompiledModule> compiled_module) {
192 return {CompiledModuleInstancesIterator(isolate, compiled_module, false),
193 CompiledModuleInstancesIterator(isolate, compiled_module, true)};
194 }
195
196 #ifdef DEBUG
197 bool IsBreakablePosition(Handle<WasmCompiledModule> compiled_module,
198 int func_index, int offset_in_func) {
199 DisallowHeapAllocation no_gc;
200 AccountingAllocator alloc;
201 Zone tmp(&alloc, ZONE_NAME);
202 BodyLocalDecls locals(&tmp);
203 const byte* module_start = compiled_module->module_bytes()->GetChars();
204 WasmFunction& func = compiled_module->module()->functions[func_index];
205 BytecodeIterator iterator(module_start + func.code_start_offset,
206 module_start + func.code_end_offset, &locals);
207 DCHECK_LT(0, locals.encoded_size);
208 uint32_t found_position = 0;
209 for (uint32_t offset : iterator.offsets()) {
210 if (offset > static_cast<uint32_t>(offset_in_func)) break;
211 if (offset == static_cast<uint32_t>(offset_in_func)) return true;
212 }
213 return false;
214 }
215 #endif // DEBUG
216
81 } // namespace 217 } // namespace
82 218
83 Handle<WasmModuleObject> WasmModuleObject::New( 219 Handle<WasmModuleObject> WasmModuleObject::New(
84 Isolate* isolate, Handle<WasmCompiledModule> compiled_module) { 220 Isolate* isolate, Handle<WasmCompiledModule> compiled_module) {
85 ModuleOrigin origin = compiled_module->module()->origin; 221 ModuleOrigin origin = compiled_module->module()->origin;
86 222
87 Handle<JSObject> module_object; 223 Handle<JSObject> module_object;
88 if (origin == ModuleOrigin::kWasmOrigin) { 224 if (origin == ModuleOrigin::kWasmOrigin) {
89 Handle<JSFunction> module_cons( 225 Handle<JSFunction> module_cons(
90 isolate->native_context()->wasm_module_constructor()); 226 isolate->native_context()->wasm_module_constructor());
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 if (arr->length() != kFieldCount) return false; 512 if (arr->length() != kFieldCount) return false;
377 Isolate* isolate = arr->GetIsolate(); 513 Isolate* isolate = arr->GetIsolate();
378 if (!arr->get(kModuleWrapper)->IsForeign()) return false; 514 if (!arr->get(kModuleWrapper)->IsForeign()) return false;
379 if (!arr->get(kModuleBytes)->IsUndefined(isolate) && 515 if (!arr->get(kModuleBytes)->IsUndefined(isolate) &&
380 !arr->get(kModuleBytes)->IsSeqOneByteString()) 516 !arr->get(kModuleBytes)->IsSeqOneByteString())
381 return false; 517 return false;
382 if (!arr->get(kScript)->IsScript()) return false; 518 if (!arr->get(kScript)->IsScript()) return false;
383 if (!arr->get(kAsmJsOffsetTable)->IsUndefined(isolate) && 519 if (!arr->get(kAsmJsOffsetTable)->IsUndefined(isolate) &&
384 !arr->get(kAsmJsOffsetTable)->IsByteArray()) 520 !arr->get(kAsmJsOffsetTable)->IsByteArray())
385 return false; 521 return false;
522 if (!arr->get(kBreakPointInfos)->IsUndefined(isolate) &&
523 !arr->get(kBreakPointInfos)->IsFixedArray())
524 return false;
386 return true; 525 return true;
387 } 526 }
388 527
389 WasmSharedModuleData* WasmSharedModuleData::cast(Object* object) { 528 WasmSharedModuleData* WasmSharedModuleData::cast(Object* object) {
390 DCHECK(IsWasmSharedModuleData(object)); 529 DCHECK(IsWasmSharedModuleData(object));
391 return reinterpret_cast<WasmSharedModuleData*>(object); 530 return reinterpret_cast<WasmSharedModuleData*>(object);
392 } 531 }
393 532
394 wasm::WasmModule* WasmSharedModuleData::module() { 533 wasm::WasmModule* WasmSharedModuleData::module() {
395 return reinterpret_cast<WasmModuleWrapper*>(get(kModuleWrapper))->get(); 534 return reinterpret_cast<WasmModuleWrapper*>(get(kModuleWrapper))->get();
396 } 535 }
397 536
398 DEFINE_OPTIONAL_ARR_ACCESSORS(WasmSharedModuleData, module_bytes, kModuleBytes, 537 DEFINE_OPTIONAL_ARR_ACCESSORS(WasmSharedModuleData, module_bytes, kModuleBytes,
399 SeqOneByteString); 538 SeqOneByteString);
400 DEFINE_ARR_GETTER(WasmSharedModuleData, script, kScript, Script); 539 DEFINE_ARR_GETTER(WasmSharedModuleData, script, kScript, Script);
401 DEFINE_OPTIONAL_ARR_ACCESSORS(WasmSharedModuleData, asm_js_offset_table, 540 DEFINE_OPTIONAL_ARR_ACCESSORS(WasmSharedModuleData, asm_js_offset_table,
402 kAsmJsOffsetTable, ByteArray); 541 kAsmJsOffsetTable, ByteArray);
542 DEFINE_OPTIONAL_ARR_GETTER(WasmSharedModuleData, breakpoint_infos,
543 kBreakPointInfos, FixedArray);
403 544
404 Handle<WasmSharedModuleData> WasmSharedModuleData::New( 545 Handle<WasmSharedModuleData> WasmSharedModuleData::New(
405 Isolate* isolate, Handle<Foreign> module_wrapper, 546 Isolate* isolate, Handle<Foreign> module_wrapper,
406 Handle<SeqOneByteString> module_bytes, Handle<Script> script, 547 Handle<SeqOneByteString> module_bytes, Handle<Script> script,
407 Handle<ByteArray> asm_js_offset_table) { 548 Handle<ByteArray> asm_js_offset_table) {
408 Handle<FixedArray> arr = 549 Handle<FixedArray> arr =
409 isolate->factory()->NewFixedArray(kFieldCount, TENURED); 550 isolate->factory()->NewFixedArray(kFieldCount, TENURED);
410 551
411 arr->set(kModuleWrapper, *module_wrapper); 552 arr->set(kModuleWrapper, *module_wrapper);
412 if (!module_bytes.is_null()) { 553 if (!module_bytes.is_null()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 module = const_cast<WasmModule*>(result.val); 593 module = const_cast<WasmModule*>(result.val);
453 } 594 }
454 595
455 Handle<WasmModuleWrapper> module_wrapper = 596 Handle<WasmModuleWrapper> module_wrapper =
456 WasmModuleWrapper::New(isolate, module); 597 WasmModuleWrapper::New(isolate, module);
457 598
458 shared->set(kModuleWrapper, *module_wrapper); 599 shared->set(kModuleWrapper, *module_wrapper);
459 DCHECK(WasmSharedModuleData::IsWasmSharedModuleData(*shared)); 600 DCHECK(WasmSharedModuleData::IsWasmSharedModuleData(*shared));
460 } 601 }
461 602
603 namespace {
604
605 int GetBreakpointPos(Isolate* isolate, Object* break_point_info_or_undef) {
606 if (break_point_info_or_undef->IsUndefined(isolate)) return kMaxInt;
607 return BreakPointInfo::cast(break_point_info_or_undef)->source_position();
608 }
609
610 int FindBreakpointInfoInsertPos(Isolate* isolate,
611 Handle<FixedArray> breakpoint_infos,
612 int position) {
613 // Find insert location via binary search, taking care of undefined values on
614 // the right. Position is always greater than zero.
615 DCHECK_LT(0, position);
616
617 int left = 0; // inclusive
618 int right = breakpoint_infos->length(); // exclusive
619 while (right - left > 1) {
620 int mid = left + (right - left) / 2;
621 Object* mid_obj = breakpoint_infos->get(mid);
622 if (GetBreakpointPos(isolate, mid_obj) <= position) {
623 left = mid;
624 } else {
625 right = mid;
626 }
627 }
628
629 int left_pos = GetBreakpointPos(isolate, breakpoint_infos->get(left));
630 return left_pos < position ? left + 1 : left;
631 }
632
633 } // namespace
634
635 void WasmSharedModuleData::AddBreakpoint(Handle<WasmSharedModuleData> shared,
636 int position,
637 Handle<Object> break_point_object) {
638 Isolate* isolate = shared->GetIsolate();
639 Handle<FixedArray> breakpoint_infos;
640 if (shared->has_breakpoint_infos()) {
641 breakpoint_infos = handle(shared->breakpoint_infos(), isolate);
642 } else {
643 breakpoint_infos = isolate->factory()->NewFixedArray(4, TENURED);
644 shared->set(kBreakPointInfos, *breakpoint_infos);
645 }
646
647 int insert_pos =
648 FindBreakpointInfoInsertPos(isolate, breakpoint_infos, position);
649
650 // If a BreakPointInfo object already exists for this position, add the new
651 // breakpoint object and return.
652 if (insert_pos < breakpoint_infos->length() &&
653 GetBreakpointPos(isolate, breakpoint_infos->get(insert_pos)) ==
654 position) {
655 Handle<BreakPointInfo> old_info(
656 BreakPointInfo::cast(breakpoint_infos->get(insert_pos)), isolate);
657 BreakPointInfo::SetBreakPoint(old_info, break_point_object);
658 return;
659 }
660
661 // Enlarge break positions array if necessary.
662 bool need_realloc = !breakpoint_infos->get(breakpoint_infos->length() - 1)
663 ->IsUndefined(isolate);
664 Handle<FixedArray> new_breakpoint_infos = breakpoint_infos;
665 if (need_realloc) {
666 new_breakpoint_infos = isolate->factory()->NewFixedArray(
667 2 * breakpoint_infos->length(), TENURED);
668 shared->set(kBreakPointInfos, *new_breakpoint_infos);
669 // Copy over the entries [0, insert_pos).
670 for (int i = 0; i < insert_pos; ++i)
671 new_breakpoint_infos->set(i, breakpoint_infos->get(i));
672 }
673
674 // Move elements [insert_pos+1, ...] up by one.
675 for (int i = insert_pos + 1; i < breakpoint_infos->length(); ++i) {
676 Object* entry = breakpoint_infos->get(i);
677 if (entry->IsUndefined(isolate)) break;
678 new_breakpoint_infos->set(i + 1, entry);
679 }
680
681 // Generate new BreakpointInfo.
682 Handle<BreakPointInfo> breakpoint_info =
683 isolate->factory()->NewBreakPointInfo(position);
684 BreakPointInfo::SetBreakPoint(breakpoint_info, break_point_object);
685
686 // Now insert new position at insert_pos.
687 new_breakpoint_infos->set(insert_pos, *breakpoint_info);
688 }
689
690 void WasmSharedModuleData::SetBreakpointsOnNewInstance(
691 Handle<WasmSharedModuleData> shared, Handle<WasmInstanceObject> instance) {
692 if (!shared->has_breakpoint_infos()) return;
693 Isolate* isolate = shared->GetIsolate();
694 Handle<WasmCompiledModule> compiled_module(instance->compiled_module(),
695 isolate);
696 Handle<WasmDebugInfo> debug_info =
697 WasmInstanceObject::GetOrCreateDebugInfo(instance);
698
699 Handle<FixedArray> breakpoint_infos(shared->breakpoint_infos(), isolate);
700 // If the array exists, it should not be empty.
701 DCHECK_LT(0, breakpoint_infos->length());
702
703 for (int i = 0, e = breakpoint_infos->length(); i < e; ++i) {
704 Handle<Object> obj(breakpoint_infos->get(i), isolate);
705 if (obj->IsUndefined(isolate)) {
706 for (; i < e; ++i) {
707 DCHECK(breakpoint_infos->get(i)->IsUndefined(isolate));
708 }
709 break;
710 }
711 Handle<BreakPointInfo> breakpoint_info = Handle<BreakPointInfo>::cast(obj);
712 int position = breakpoint_info->source_position();
713
714 // Find the function for this breakpoint, and set the breakpoint.
715 int func_index = compiled_module->GetContainingFunction(position);
716 DCHECK_LE(0, func_index);
717 WasmFunction& func = compiled_module->module()->functions[func_index];
718 int offset_in_func = position - func.code_start_offset;
719 WasmDebugInfo::SetBreakpoint(debug_info, func_index, offset_in_func);
720 }
721 }
722
462 Handle<WasmCompiledModule> WasmCompiledModule::New( 723 Handle<WasmCompiledModule> WasmCompiledModule::New(
463 Isolate* isolate, Handle<WasmSharedModuleData> shared) { 724 Isolate* isolate, Handle<WasmSharedModuleData> shared) {
464 Handle<FixedArray> ret = 725 Handle<FixedArray> ret =
465 isolate->factory()->NewFixedArray(PropertyIndices::Count, TENURED); 726 isolate->factory()->NewFixedArray(PropertyIndices::Count, TENURED);
466 // WasmCompiledModule::cast would fail since fields are not set yet. 727 // WasmCompiledModule::cast would fail since fields are not set yet.
467 Handle<WasmCompiledModule> compiled_module( 728 Handle<WasmCompiledModule> compiled_module(
468 reinterpret_cast<WasmCompiledModule*>(*ret), isolate); 729 reinterpret_cast<WasmCompiledModule*>(*ret), isolate);
469 compiled_module->InitId(); 730 compiled_module->InitId();
470 compiled_module->set_shared(shared); 731 compiled_module->set_shared(shared);
471 compiled_module->set_native_context(isolate->native_context()); 732 compiled_module->set_native_context(isolate->native_context());
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 DCHECK_EQ(end_func_index, func_idx); 1086 DCHECK_EQ(end_func_index, func_idx);
826 break; 1087 break;
827 } 1088 }
828 if (total_offset < start_offset) continue; 1089 if (total_offset < start_offset) continue;
829 locations->push_back(v8::debug::Location(func_idx, offset)); 1090 locations->push_back(v8::debug::Location(func_idx, offset));
830 } 1091 }
831 } 1092 }
832 return true; 1093 return true;
833 } 1094 }
834 1095
1096 bool WasmCompiledModule::SetBreakPoint(
1097 Handle<WasmCompiledModule> compiled_module, int* position,
1098 Handle<Object> break_point_object) {
1099 Isolate* isolate = compiled_module->GetIsolate();
1100
1101 // Find the function for this breakpoint.
1102 int func_index = compiled_module->GetContainingFunction(*position);
1103 if (func_index < 0) return false;
1104 WasmFunction& func = compiled_module->module()->functions[func_index];
1105 int offset_in_func = *position - func.code_start_offset;
1106
1107 // According to the current design, we should only be called with valid
1108 // breakable positions.
1109 DCHECK(IsBreakablePosition(compiled_module, func_index, offset_in_func));
1110
1111 // Insert new break point into break_positions of shared module data.
1112 WasmSharedModuleData::AddBreakpoint(compiled_module->shared(), *position,
1113 break_point_object);
1114
1115 // Iterate over all instances of this module and tell them to set this new
1116 // breakpoint.
1117 for (Handle<WasmInstanceObject> instance :
1118 iterate_compiled_module_instance_chain(isolate, compiled_module)) {
1119 Handle<WasmDebugInfo> debug_info =
1120 WasmInstanceObject::GetOrCreateDebugInfo(instance);
1121 WasmDebugInfo::SetBreakpoint(debug_info, func_index, offset_in_func);
1122 }
1123
1124 return true;
1125 }
1126
835 Handle<WasmInstanceWrapper> WasmInstanceWrapper::New( 1127 Handle<WasmInstanceWrapper> WasmInstanceWrapper::New(
836 Isolate* isolate, Handle<WasmInstanceObject> instance) { 1128 Isolate* isolate, Handle<WasmInstanceObject> instance) {
837 Handle<FixedArray> array = 1129 Handle<FixedArray> array =
838 isolate->factory()->NewFixedArray(kWrapperPropertyCount, TENURED); 1130 isolate->factory()->NewFixedArray(kWrapperPropertyCount, TENURED);
839 Handle<WasmInstanceWrapper> instance_wrapper( 1131 Handle<WasmInstanceWrapper> instance_wrapper(
840 reinterpret_cast<WasmInstanceWrapper*>(*array), isolate); 1132 reinterpret_cast<WasmInstanceWrapper*>(*array), isolate);
841 instance_wrapper->set_instance_object(instance, isolate); 1133 instance_wrapper->set_instance_object(instance, isolate);
842 return instance_wrapper; 1134 return instance_wrapper;
843 } 1135 }
844 1136
(...skipping 10 matching lines...) Expand all
855 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) 1147 !array->get(kPreviousInstanceWrapper)->IsFixedArray())
856 return false; 1148 return false;
857 return true; 1149 return true;
858 } 1150 }
859 1151
860 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance, 1152 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance,
861 Isolate* isolate) { 1153 Isolate* isolate) {
862 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance); 1154 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance);
863 set(kWrapperInstanceObject, *cell); 1155 set(kWrapperInstanceObject, *cell);
864 } 1156 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698