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

Side by Side Diff: vm/stack_frame.cc

Issue 10173008: Simplify representation of stack frames. Remove the special types DartFrame/StubFrame and instead u… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/stack_frame.h" 5 #include "vm/stack_frame.h"
6 6
7 #include "vm/isolate.h" 7 #include "vm/isolate.h"
8 #include "vm/object.h" 8 #include "vm/object.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 #include "vm/os.h" 10 #include "vm/os.h"
11 #include "vm/raw_object.h" 11 #include "vm/raw_object.h"
12 #include "vm/stub_code.h" 12 #include "vm/stub_code.h"
13 #include "vm/visitor.h" 13 #include "vm/visitor.h"
14 14
15 namespace dart { 15 namespace dart {
16 16
17 bool StackFrame::FindRawCodeVisitor::FindObject(RawObject* obj) { 17 bool StackFrame::FindRawCodeVisitor::FindObject(RawObject* obj) {
18 return RawInstructions::ContainsPC(obj, pc_); 18 return RawInstructions::ContainsPC(obj, pc_);
19 } 19 }
20 20
21 21
22 bool StackFrame::IsStubFrame() const {
23 if (Dart::vm_isolate()->heap()->CodeContains(pc())) {
24 return true; // Common stub code is generated in the VM heap.
25 }
26 // We add a no gc scope to ensure that the code below does not trigger
27 // a GC as we are handling raw object references here. It is possible
28 // that the code is called while a GC is in progress, that is ok.
29 NoGCScope no_gc;
30 Isolate* isolate = Isolate::Current();
31 RawCode* code = StackFrame::LookupCode(isolate, pc());
32 return (code != Code::null() && code->ptr()->function_ == Function::null());
33 }
34
35
22 void StackFrame::Print() const { 36 void StackFrame::Print() const {
23 OS::Print("[%-8s : sp(%p) ]\n", GetName(), sp()); 37 OS::Print("[%-8s : sp(%p) ]\n", GetName(), sp());
24 } 38 }
25 39
26 40
27 RawCode* StackFrame::LookupCode(Isolate* isolate, uword pc) { 41 RawCode* StackFrame::LookupCode(Isolate* isolate, uword pc) {
28 // TODO(asiva): Need to add a data structure for storing a (pc, code 42 // TODO(asiva): Need to add a data structure for storing a (pc, code
29 // object) map in order to do a quick lookup and avoid having to 43 // object) map in order to do a quick lookup and avoid having to
30 // traverse the code heap. 44 // traverse the code heap.
31 ASSERT(isolate != NULL); 45 ASSERT(isolate != NULL);
(...skipping 18 matching lines...) Expand all
50 void EntryFrame::VisitObjectPointers(ObjectPointerVisitor* visitor) { 64 void EntryFrame::VisitObjectPointers(ObjectPointerVisitor* visitor) {
51 // Visit objects between SP and (FP - callee_save_area). 65 // Visit objects between SP and (FP - callee_save_area).
52 ASSERT(visitor != NULL); 66 ASSERT(visitor != NULL);
53 RawObject** start = reinterpret_cast<RawObject**>(sp()); 67 RawObject** start = reinterpret_cast<RawObject**>(sp());
54 RawObject** end = reinterpret_cast<RawObject**>( 68 RawObject** end = reinterpret_cast<RawObject**>(
55 fp() - kWordSize + ExitLinkOffset()); 69 fp() - kWordSize + ExitLinkOffset());
56 visitor->VisitPointers(start, end); 70 visitor->VisitPointers(start, end);
57 } 71 }
58 72
59 73
60 void DartFrame::VisitObjectPointers(ObjectPointerVisitor* visitor) { 74 void StackFrame::VisitObjectPointers(ObjectPointerVisitor* visitor) {
61 // NOTE: This code runs while GC is in progress and runs within 75 // NOTE: This code runs while GC is in progress and runs within
62 // a NoHandleScope block. Hence it is not ok to use regular Zone or 76 // a NoHandleScope block. Hence it is not ok to use regular Zone or
63 // Scope handles. We use direct stack handles, the raw pointers in 77 // Scope handles. We use direct stack handles, the raw pointers in
64 // these handles are not traversed. The use of handles is mainly to 78 // these handles are not traversed. The use of handles is mainly to
65 // be able to reuse the handle based code and avoid having to add 79 // be able to reuse the handle based code and avoid having to add
66 // helper functions to the raw object interface. 80 // helper functions to the raw object interface.
67 NoGCScope no_gc; 81 NoGCScope no_gc;
68 Code code; 82 Code code;
69 code = LookupDartCode(); 83 code = LookupDartCode();
70 ASSERT(!code.IsNull()); 84 if (!code.IsNull()) {
71 Array maps; 85 Array maps;
72 maps = Array::null(); 86 maps = Array::null();
73 Stackmap map; 87 Stackmap map;
74 map = code.GetStackmap(pc(), &maps, &map); 88 map = code.GetStackmap(pc(), &maps, &map);
75 if (map.IsNull()) { 89 if (!map.IsNull()) {
76 // No stack maps are present in the code object which means this 90 // A stack map is present in the code object, use the stack map to visit
77 // frame relies on tagged pointers and hence we visit each entry 91 // frame slots which are marked as having objects.
78 // on the frame between SP and FP. 92 intptr_t bit_offset = map.MinimumBitOffset();
79 ASSERT(visitor != NULL); 93 intptr_t end_bit_offset = map.MaximumBitOffset();
80 visitor->VisitPointers(reinterpret_cast<RawObject**>(sp()), 94 while (bit_offset <= end_bit_offset) {
81 reinterpret_cast<RawObject**>(fp() - kWordSize)); 95 uword addr = (fp() - ((bit_offset + 1) * kWordSize));
82 return; 96 ASSERT(addr >= sp());
97 if (map.IsObject(bit_offset)) {
98 visitor->VisitPointer(reinterpret_cast<RawObject**>(addr));
99 }
100 bit_offset += 1;
101 }
102 return;
103 }
83 } 104 }
84 // A stack map is present in the code object, use the stack map to visit 105 // No stack maps are present in the code object which means this
85 // frame slots which are marked as having objects. 106 // frame relies on tagged pointers and hence we visit each entry
86 intptr_t bit_offset = map.MinimumBitOffset(); 107 // on the frame between SP and FP.
87 intptr_t end_bit_offset = map.MaximumBitOffset(); 108 ASSERT(visitor != NULL);
88 while (bit_offset <= end_bit_offset) { 109 visitor->VisitPointers(reinterpret_cast<RawObject**>(sp()),
89 uword addr = (fp() - ((bit_offset + 1) * kWordSize)); 110 reinterpret_cast<RawObject**>(fp() - kWordSize));
90 ASSERT(addr >= sp());
91 if (map.IsObject(bit_offset)) {
92 visitor->VisitPointer(reinterpret_cast<RawObject**>(addr));
93 }
94 bit_offset += 1;
95 }
96 } 111 }
97 112
98 113
99 RawFunction* DartFrame::LookupDartFunction() const { 114 RawFunction* StackFrame::LookupDartFunction() const {
100 const Code& code = Code::Handle(LookupDartCode()); 115 const Code& code = Code::Handle(LookupDartCode());
101 if (!code.IsNull()) { 116 if (!code.IsNull()) {
102 return code.function(); 117 return code.function();
103 } 118 }
104 return Function::null(); 119 return Function::null();
105 } 120 }
106 121
107 122
108 RawCode* DartFrame::LookupDartCode() const { 123 RawCode* StackFrame::LookupDartCode() const {
109 // We add a no gc scope to ensure that the code below does not trigger 124 // We add a no gc scope to ensure that the code below does not trigger
110 // a GC as we are handling raw object references here. It is possible 125 // a GC as we are handling raw object references here. It is possible
111 // that the code is called while a GC is in progress, that is ok. 126 // that the code is called while a GC is in progress, that is ok.
112 NoGCScope no_gc; 127 NoGCScope no_gc;
113 Isolate* isolate = Isolate::Current(); 128 Isolate* isolate = Isolate::Current();
114 RawCode* code = StackFrame::LookupCode(isolate, pc()); 129 RawCode* code = StackFrame::LookupCode(isolate, pc());
115 ASSERT(code != Code::null() && code->ptr()->function_ != Function::null()); 130 if (code != Code::null() && code->ptr()->function_ != Function::null()) {
srdjan 2012/04/24 23:19:41 Parenthesis needed
siva 2012/04/25 01:14:20 Done.
116 return code; 131 return code;
132 }
133 return Code::null();
117 } 134 }
118 135
119 136
120 bool DartFrame::FindExceptionHandler(uword* handler_pc) const { 137 bool StackFrame::FindExceptionHandler(uword* handler_pc) const {
121 const Code& code = Code::Handle(LookupDartCode()); 138 const Code& code = Code::Handle(LookupDartCode());
122 ASSERT(!code.IsNull()); 139 if (code.IsNull()) {
140 return false; // Stub frames do not have exception handlers.
141 }
123 142
124 // First try to find pc descriptor for the current pc. 143 // First try to find pc descriptor for the current pc.
125 intptr_t try_index = -1; 144 intptr_t try_index = -1;
126 const PcDescriptors& descriptors = 145 const PcDescriptors& descriptors =
127 PcDescriptors::Handle(code.pc_descriptors()); 146 PcDescriptors::Handle(code.pc_descriptors());
128 for (intptr_t i = 0; i < descriptors.Length(); i++) { 147 for (intptr_t i = 0; i < descriptors.Length(); i++) {
129 if (static_cast<uword>(descriptors.PC(i)) == pc() && 148 if (static_cast<uword>(descriptors.PC(i)) == pc() &&
130 descriptors.TryIndex(i) != -1) { 149 descriptors.TryIndex(i) != -1) {
131 try_index = descriptors.TryIndex(i); 150 try_index = descriptors.TryIndex(i);
132 break; 151 break;
133 } 152 }
134 } 153 }
135 if (try_index != -1) { 154 if (try_index != -1) {
136 // We found a pc descriptor, now try to see if we have an 155 // We found a pc descriptor, now try to see if we have an
137 // exception catch handler for this try index. 156 // exception catch handler for this try index.
138 const ExceptionHandlers& handlers = 157 const ExceptionHandlers& handlers =
139 ExceptionHandlers::Handle(code.exception_handlers()); 158 ExceptionHandlers::Handle(code.exception_handlers());
140 for (intptr_t j = 0; j < handlers.Length(); j++) { 159 for (intptr_t j = 0; j < handlers.Length(); j++) {
141 if (handlers.TryIndex(j) == try_index) { 160 if (handlers.TryIndex(j) == try_index) {
142 *handler_pc = handlers.HandlerPC(j); 161 *handler_pc = handlers.HandlerPC(j);
143 return true; 162 return true;
144 } 163 }
145 } 164 }
146 } 165 }
147 return false; 166 return false;
148 } 167 }
149 168
150 169
151 bool StubFrame::IsValid() const { 170 bool StackFrame::IsValid() const {
152 // We add a no gc scope to ensure that the code below does not trigger 171 if (IsEntryFrame() || IsExitFrame()) {
153 // a GC as we are handling raw object references here. It is possible 172 return true;
154 // that the code is called while a GC is in progress, that is ok. 173 }
155 NoGCScope no_gc;
156 Isolate* isolate = Isolate::Current();
157 if (Dart::vm_isolate()->heap()->CodeContains(pc())) { 174 if (Dart::vm_isolate()->heap()->CodeContains(pc())) {
158 return true; // Common stub code is generated in the VM heap. 175 return true; // Common stub code is generated in the VM heap.
159 } 176 }
160 RawCode* code = StackFrame::LookupCode(isolate, pc()); 177 return (StackFrame::LookupCode(Isolate::Current(), pc()) != Code::null());
161 return (code != Code::null() && code->ptr()->function_ == Function::null());
162 }
163
164
165 void StubFrame::VisitObjectPointers(ObjectPointerVisitor* visitor) {
166 // Visit objects between SP and FP.
167 ASSERT(visitor != NULL);
168 visitor->VisitPointers(reinterpret_cast<RawObject**>(sp()),
169 reinterpret_cast<RawObject**>(fp() - kWordSize));
170 } 178 }
171 179
172 180
173 StackFrameIterator::StackFrameIterator(bool validate) 181 StackFrameIterator::StackFrameIterator(bool validate)
174 : validate_(validate), entry_(), exit_(), current_frame_(NULL) { 182 : validate_(validate), entry_(), exit_(), current_frame_(NULL) {
175 SetupLastExitFrameData(); // Setup data for last exit frame. 183 SetupLastExitFrameData(); // Setup data for last exit frame.
176 } 184 }
177 185
178 186
179 StackFrame* StackFrameIterator::NextFrame() { 187 StackFrame* StackFrameIterator::NextFrame() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // corresponding entry frame for that set of dart/stub frames. 221 // corresponding entry frame for that set of dart/stub frames.
214 current_frame_ = 222 current_frame_ =
215 (frames_.HasNext()) ? frames_.NextFrame(validate_) : NextEntryFrame(); 223 (frames_.HasNext()) ? frames_.NextFrame(validate_) : NextEntryFrame();
216 return current_frame_; 224 return current_frame_;
217 } 225 }
218 226
219 227
220 StackFrame* StackFrameIterator::FrameSetIterator::NextFrame(bool validate) { 228 StackFrame* StackFrameIterator::FrameSetIterator::NextFrame(bool validate) {
221 StackFrame* frame; 229 StackFrame* frame;
222 ASSERT(HasNext()); 230 ASSERT(HasNext());
223 if (from_stub_exitframe_) { 231 frame = &stack_frame_;
224 frame = &stub_frame_;
225 } else {
226 frame = &dart_frame_;
227 }
228 frame->sp_ = sp_; 232 frame->sp_ = sp_;
229 frame->fp_ = fp_; 233 frame->fp_ = fp_;
230 sp_ = frame->GetCallerSp(); 234 sp_ = frame->GetCallerSp();
231 fp_ = frame->GetCallerFp(); 235 fp_ = frame->GetCallerFp();
232 from_stub_exitframe_ = false;
233 ASSERT((validate == kDontValidateFrames) || frame->IsValid()); 236 ASSERT((validate == kDontValidateFrames) || frame->IsValid());
234 return frame; 237 return frame;
235 } 238 }
236 239
237 240
238 ExitFrame* StackFrameIterator::NextExitFrame() { 241 ExitFrame* StackFrameIterator::NextExitFrame() {
239 exit_.sp_ = frames_.sp_; 242 exit_.sp_ = frames_.sp_;
240 exit_.fp_ = frames_.fp_; 243 exit_.fp_ = frames_.fp_;
241 frames_.sp_ = exit_.GetCallerSp(); 244 frames_.sp_ = exit_.GetCallerSp();
242 frames_.fp_ = exit_.GetCallerFp(); 245 frames_.fp_ = exit_.GetCallerFp();
243 ASSERT(exit_.IsValid()); 246 ASSERT(exit_.IsValid());
244 return &exit_; 247 return &exit_;
245 } 248 }
246 249
247 250
248 EntryFrame* StackFrameIterator::NextEntryFrame() { 251 EntryFrame* StackFrameIterator::NextEntryFrame() {
249 ASSERT(!frames_.HasNext()); 252 ASSERT(!frames_.HasNext());
250 entry_.sp_ = frames_.sp_; 253 entry_.sp_ = frames_.sp_;
251 entry_.fp_ = frames_.fp_; 254 entry_.fp_ = frames_.fp_;
252 SetupNextExitFrameData(); // Setup data for next exit frame in chain. 255 SetupNextExitFrameData(); // Setup data for next exit frame in chain.
253 ASSERT(entry_.IsValid()); 256 ASSERT(entry_.IsValid());
254 return &entry_; 257 return &entry_;
255 } 258 }
256 259
257 } // namespace dart 260 } // namespace dart
OLDNEW
« vm/code_generator.cc ('K') | « vm/stack_frame.h ('k') | vm/stack_frame_ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698