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

Side by Side Diff: src/virtual-frame-ia32.cc

Issue 9769: Add state to track the individual elements of the virtual frame.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
Patch Set: '' Created 12 years, 1 month 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 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 22 matching lines...) Expand all
33 33
34 namespace v8 { namespace internal { 34 namespace v8 { namespace internal {
35 35
36 // ------------------------------------------------------------------------- 36 // -------------------------------------------------------------------------
37 // VirtualFrame implementation. 37 // VirtualFrame implementation.
38 38
39 #define __ masm_-> 39 #define __ masm_->
40 40
41 VirtualFrame::VirtualFrame(CodeGenerator* cgen) 41 VirtualFrame::VirtualFrame(CodeGenerator* cgen)
42 : masm_(cgen->masm()), 42 : masm_(cgen->masm()),
43 elements_(cgen->scope()->num_parameters() + 5),
Erik Corry 2008/11/11 10:47:05 5?
Kevin Millikin (Chromium) 2008/11/11 11:37:31 You think that needs some explanation :)
44 virtual_frame_pointer_(-1),
45 virtual_stack_pointer_(-1),
43 parameter_count_(cgen->scope()->num_parameters()), 46 parameter_count_(cgen->scope()->num_parameters()),
44 frame_local_count_(cgen->scope()->num_stack_slots()), 47 local_count_(0) {
45 height_(0) { 48 // The virtual frame contains a receiver, the parameters, and a return
49 // address (all in memory) when it is created.
50 Adjust(parameter_count_ + 2);
46 } 51 }
47 52
48 53
49 VirtualFrame::VirtualFrame(VirtualFrame* original) 54 VirtualFrame::VirtualFrame(VirtualFrame* original)
50 : masm_(original->masm_), 55 : masm_(original->masm_),
56 elements_(original->elements_.length()),
57 virtual_frame_pointer_(original->virtual_frame_pointer_),
58 virtual_stack_pointer_(original->virtual_stack_pointer_),
51 parameter_count_(original->parameter_count_), 59 parameter_count_(original->parameter_count_),
52 frame_local_count_(original->frame_local_count_), 60 local_count_(original->local_count_) {
53 height_(original->height_) { 61 // Copy all the elements.
62 for (int i = 0; i <= virtual_stack_pointer_; i++) {
63 elements_.Add(original->elements_[i]);
64 }
65 }
66
67
68 void VirtualFrame::Adjust(int count) {
69 ASSERT(count >= 0);
70 for (int i = 0; i < count; i++) {
71 AddElement(Element());
72 }
54 } 73 }
55 74
56 75
57 void VirtualFrame::Forget(int count) { 76 void VirtualFrame::Forget(int count) {
58 ASSERT(count >= 0); 77 ASSERT(count >= 0);
59 ASSERT(height_ >= count); 78 ASSERT(virtual_stack_pointer_ >= count);
60 height_ -= count; 79 for (int i = 0; i < count; i++) {
80 RemoveElement();
81 }
61 } 82 }
62 83
63 84
64 void VirtualFrame::MergeTo(VirtualFrame* expected) { 85 void VirtualFrame::MergeTo(VirtualFrame* expected) {
65 ASSERT(masm_ == expected->masm_); 86 ASSERT(masm_ == expected->masm_);
66 ASSERT(frame_local_count_ == expected->frame_local_count_); 87 ASSERT(elements_.length() == expected->elements_.length());
88 ASSERT(virtual_frame_pointer_ == expected->virtual_frame_pointer_);
89 ASSERT(virtual_stack_pointer_ == expected->virtual_stack_pointer_);
67 ASSERT(parameter_count_ == expected->parameter_count_); 90 ASSERT(parameter_count_ == expected->parameter_count_);
68 ASSERT(height_ == expected->height_); 91 ASSERT(local_count_ == expected->local_count_);
92 for (int i = 0; i <= virtual_stack_pointer_; i++) {
93 ASSERT(elements_[i].matches(expected->elements_[i]));
94 }
69 } 95 }
70 96
71 97
72 void VirtualFrame::Enter() { 98 void VirtualFrame::Enter() {
73 Comment cmnt(masm_, "[ Enter JS frame"); 99 Comment cmnt(masm_, "[ Enter JS frame");
100 Adjust(1);
74 __ push(ebp); 101 __ push(ebp);
102
103 virtual_frame_pointer_ = virtual_stack_pointer_;
75 __ mov(ebp, Operand(esp)); 104 __ mov(ebp, Operand(esp));
76 105
77 // Store the context and the function in the frame. 106 // Store the context and the function in the frame.
107 Adjust(2);
78 __ push(esi); 108 __ push(esi);
79 __ push(edi); 109 __ push(edi);
80 110
81 // Clear the function slot when generating debug code. 111 // Clear the function slot when generating debug code.
82 if (FLAG_debug_code) { 112 if (FLAG_debug_code) {
83 __ Set(edi, Immediate(reinterpret_cast<int>(kZapValue))); 113 __ Set(edi, Immediate(reinterpret_cast<int>(kZapValue)));
84 } 114 }
85 } 115 }
86 116
87 117
88 void VirtualFrame::Exit() { 118 void VirtualFrame::Exit() {
89 Comment cmnt(masm_, "[ Exit JS frame"); 119 Comment cmnt(masm_, "[ Exit JS frame");
90 // Record the location of the JS exit code for patching when setting 120 // Record the location of the JS exit code for patching when setting
91 // break point. 121 // break point.
92 __ RecordJSReturn(); 122 __ RecordJSReturn();
93 123
94 // Avoid using the leave instruction here, because it is too 124 // Avoid using the leave instruction here, because it is too
95 // short. We need the return sequence to be a least the size of a 125 // short. We need the return sequence to be a least the size of a
96 // call instruction to support patching the exit code in the 126 // call instruction to support patching the exit code in the
97 // debugger. See VisitReturnStatement for the full return sequence. 127 // debugger. See VisitReturnStatement for the full return sequence.
98 __ mov(esp, Operand(ebp)); 128 __ mov(esp, Operand(ebp));
99 __ pop(ebp); 129 __ pop(ebp);
100 } 130 }
101 131
102 132
103 void VirtualFrame::AllocateLocals() { 133 void VirtualFrame::AllocateLocals(int count) {
104 if (frame_local_count_ > 0) { 134 ASSERT(height() == 0);
135 local_count_ = count;
136 Adjust(count);
137 if (count > 0) {
105 Comment cmnt(masm_, "[ Allocate space for locals"); 138 Comment cmnt(masm_, "[ Allocate space for locals");
106 __ Set(eax, Immediate(Factory::undefined_value())); 139 __ Set(eax, Immediate(Factory::undefined_value()));
107 for (int i = 0; i < frame_local_count_; i++) { 140 for (int i = 0; i < count; i++) {
108 __ push(eax); 141 __ push(eax);
109 } 142 }
110 } 143 }
111 } 144 }
112 145
146
147 void VirtualFrame::PushTryHandler(HandlerType type) {
148 // Grow the expression stack by handler size less two (the return address
149 // is already pushed by a call instruction, and PushTryHandler from the
150 // macro assembler will leave the top of stack in the eax register to be
151 // pushed separately).
152 Adjust(kHandlerSize - 2);
153 __ PushTryHandler(IN_JAVASCRIPT, type);
154 // TODO(1222589): remove the reliance of PushTryHandler on a cached TOS
155 Push(eax);
156 }
157
158
159 void VirtualFrame::CallStub(CodeStub* stub, int frame_arg_count) {
160 ASSERT(height() >= frame_arg_count);
161 Forget(frame_arg_count);
162 __ CallStub(stub);
163 }
164
165
166 void VirtualFrame::CallRuntime(Runtime::Function* f, int frame_arg_count) {
167 ASSERT(height() >= frame_arg_count);
168 Forget(frame_arg_count);
169 __ CallRuntime(f, frame_arg_count);
170 }
171
172
173 void VirtualFrame::CallRuntime(Runtime::FunctionId id, int frame_arg_count) {
174 ASSERT(height() >= frame_arg_count);
175 Forget(frame_arg_count);
176 __ CallRuntime(id, frame_arg_count);
177 }
178
179
180 void VirtualFrame::InvokeBuiltin(Builtins::JavaScript id,
181 InvokeFlag flag,
182 int frame_arg_count) {
183 ASSERT(height() >= frame_arg_count);
184 Forget(frame_arg_count);
185 __ InvokeBuiltin(id, flag);
186 }
187
188
189 void VirtualFrame::CallCode(Handle<Code> code,
190 RelocInfo::Mode rmode,
191 int frame_arg_count) {
192 ASSERT(height() >= frame_arg_count);
193 Forget(frame_arg_count);
194 __ call(code, rmode);
195 }
196
197
198 void VirtualFrame::Drop(int count) {
199 ASSERT(height() >= count);
200 Forget(count);
201 if (count > 0) {
202 __ add(Operand(esp), Immediate(count * kPointerSize));
203 }
204 }
205
206
207 void VirtualFrame::Drop() { Drop(1); }
208
209
210 void VirtualFrame::Pop(Register reg) {
211 Forget(1);
212 __ pop(reg);
213 }
214
215
216 void VirtualFrame::Pop(Operand operand) {
217 Forget(1);
218 __ pop(operand);
219 }
220
221
222 void VirtualFrame::Push(Register reg) {
223 Adjust(1);
224 __ push(reg);
225 }
226
227
228 void VirtualFrame::Push(Operand operand) {
229 Adjust(1);
230 __ push(operand);
231 }
232
233
234 void VirtualFrame::Push(Immediate immediate) {
235 Adjust(1);
236 __ push(immediate);
237 }
238
113 #undef __ 239 #undef __
114 240
115 } } // namespace v8::internal 241 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698