824c1a762046f7f24fbdfbb1c9b7150542732764
[platform/upstream/nodejs.git] / deps / v8 / src / frames-inl.h
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_FRAMES_INL_H_
6 #define V8_FRAMES_INL_H_
7
8 #include "src/frames.h"
9 #include "src/isolate.h"
10 #include "src/v8memory.h"
11
12 #if V8_TARGET_ARCH_IA32
13 #include "src/ia32/frames-ia32.h"  // NOLINT
14 #elif V8_TARGET_ARCH_X64
15 #include "src/x64/frames-x64.h"  // NOLINT
16 #elif V8_TARGET_ARCH_ARM64
17 #include "src/arm64/frames-arm64.h"  // NOLINT
18 #elif V8_TARGET_ARCH_ARM
19 #include "src/arm/frames-arm.h"  // NOLINT
20 #elif V8_TARGET_ARCH_PPC
21 #include "src/ppc/frames-ppc.h"  // NOLINT
22 #elif V8_TARGET_ARCH_MIPS
23 #include "src/mips/frames-mips.h"  // NOLINT
24 #elif V8_TARGET_ARCH_MIPS64
25 #include "src/mips64/frames-mips64.h"  // NOLINT
26 #elif V8_TARGET_ARCH_X87
27 #include "src/x87/frames-x87.h"  // NOLINT
28 #else
29 #error Unsupported target architecture.
30 #endif
31
32 namespace v8 {
33 namespace internal {
34
35
36 inline Address StackHandler::address() const {
37   return reinterpret_cast<Address>(const_cast<StackHandler*>(this));
38 }
39
40
41 inline StackHandler* StackHandler::next() const {
42   const int offset = StackHandlerConstants::kNextOffset;
43   return FromAddress(Memory::Address_at(address() + offset));
44 }
45
46
47 inline bool StackHandler::includes(Address address) const {
48   Address start = this->address();
49   Address end = start + StackHandlerConstants::kSize;
50   return start <= address && address <= end;
51 }
52
53
54 inline void StackHandler::Iterate(ObjectVisitor* v, Code* holder) const {
55   v->VisitPointer(context_address());
56   v->VisitPointer(code_address());
57 }
58
59
60 inline StackHandler* StackHandler::FromAddress(Address address) {
61   return reinterpret_cast<StackHandler*>(address);
62 }
63
64
65 inline bool StackHandler::is_js_entry() const {
66   return kind() == JS_ENTRY;
67 }
68
69
70 inline bool StackHandler::is_catch() const {
71   return kind() == CATCH;
72 }
73
74
75 inline bool StackHandler::is_finally() const {
76   return kind() == FINALLY;
77 }
78
79
80 inline StackHandler::Kind StackHandler::kind() const {
81   const int offset = StackHandlerConstants::kStateIntOffset;
82   return KindField::decode(Memory::unsigned_at(address() + offset));
83 }
84
85
86 inline unsigned StackHandler::index() const {
87   const int offset = StackHandlerConstants::kStateIntOffset;
88   return IndexField::decode(Memory::unsigned_at(address() + offset));
89 }
90
91
92 inline Object** StackHandler::context_address() const {
93   const int offset = StackHandlerConstants::kContextOffset;
94   return reinterpret_cast<Object**>(address() + offset);
95 }
96
97
98 inline Object** StackHandler::code_address() const {
99   const int offset = StackHandlerConstants::kCodeOffset;
100   return reinterpret_cast<Object**>(address() + offset);
101 }
102
103
104 inline StackFrame::StackFrame(StackFrameIteratorBase* iterator)
105     : iterator_(iterator), isolate_(iterator_->isolate()) {
106 }
107
108
109 inline StackHandler* StackFrame::top_handler() const {
110   return iterator_->handler();
111 }
112
113
114 inline Code* StackFrame::LookupCode() const {
115   return GetContainingCode(isolate(), pc());
116 }
117
118
119 inline Code* StackFrame::GetContainingCode(Isolate* isolate, Address pc) {
120   return isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code;
121 }
122
123
124 inline Address* StackFrame::ResolveReturnAddressLocation(Address* pc_address) {
125   if (return_address_location_resolver_ == NULL) {
126     return pc_address;
127   } else {
128     return reinterpret_cast<Address*>(
129         return_address_location_resolver_(
130             reinterpret_cast<uintptr_t>(pc_address)));
131   }
132 }
133
134
135 inline EntryFrame::EntryFrame(StackFrameIteratorBase* iterator)
136     : StackFrame(iterator) {
137 }
138
139
140 inline EntryConstructFrame::EntryConstructFrame(
141     StackFrameIteratorBase* iterator)
142     : EntryFrame(iterator) {
143 }
144
145
146 inline ExitFrame::ExitFrame(StackFrameIteratorBase* iterator)
147     : StackFrame(iterator) {
148 }
149
150
151 inline StandardFrame::StandardFrame(StackFrameIteratorBase* iterator)
152     : StackFrame(iterator) {
153 }
154
155
156 inline Object* StandardFrame::GetExpression(int index) const {
157   return Memory::Object_at(GetExpressionAddress(index));
158 }
159
160
161 inline void StandardFrame::SetExpression(int index, Object* value) {
162   Memory::Object_at(GetExpressionAddress(index)) = value;
163 }
164
165
166 inline Object* StandardFrame::context() const {
167   const int offset = StandardFrameConstants::kContextOffset;
168   return Memory::Object_at(fp() + offset);
169 }
170
171
172 inline Address StandardFrame::caller_fp() const {
173   return Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset);
174 }
175
176
177 inline Address StandardFrame::caller_pc() const {
178   return Memory::Address_at(ComputePCAddress(fp()));
179 }
180
181
182 inline Address StandardFrame::ComputePCAddress(Address fp) {
183   return fp + StandardFrameConstants::kCallerPCOffset;
184 }
185
186
187 inline Address StandardFrame::ComputeConstantPoolAddress(Address fp) {
188   return fp + StandardFrameConstants::kConstantPoolOffset;
189 }
190
191
192 inline bool StandardFrame::IsArgumentsAdaptorFrame(Address fp) {
193   Object* marker =
194       Memory::Object_at(fp + StandardFrameConstants::kContextOffset);
195   return marker == Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR);
196 }
197
198
199 inline bool StandardFrame::IsConstructFrame(Address fp) {
200   Object* marker =
201       Memory::Object_at(fp + StandardFrameConstants::kMarkerOffset);
202   return marker == Smi::FromInt(StackFrame::CONSTRUCT);
203 }
204
205
206 inline JavaScriptFrame::JavaScriptFrame(StackFrameIteratorBase* iterator)
207     : StandardFrame(iterator) {
208 }
209
210
211 Address JavaScriptFrame::GetParameterSlot(int index) const {
212   int param_count = ComputeParametersCount();
213   DCHECK(-1 <= index && index < param_count);
214   int parameter_offset = (param_count - index - 1) * kPointerSize;
215   return caller_sp() + parameter_offset;
216 }
217
218
219 Object* JavaScriptFrame::GetParameter(int index) const {
220   return Memory::Object_at(GetParameterSlot(index));
221 }
222
223
224 inline Address JavaScriptFrame::GetOperandSlot(int index) const {
225   Address base = fp() + JavaScriptFrameConstants::kLocal0Offset;
226   DCHECK(IsAddressAligned(base, kPointerSize));
227   DCHECK_EQ(type(), JAVA_SCRIPT);
228   DCHECK_LT(index, ComputeOperandsCount());
229   DCHECK_LE(0, index);
230   // Operand stack grows down.
231   return base - index * kPointerSize;
232 }
233
234
235 inline Object* JavaScriptFrame::GetOperand(int index) const {
236   return Memory::Object_at(GetOperandSlot(index));
237 }
238
239
240 inline int JavaScriptFrame::ComputeOperandsCount() const {
241   Address base = fp() + JavaScriptFrameConstants::kLocal0Offset;
242   // Base points to low address of first operand and stack grows down, so add
243   // kPointerSize to get the actual stack size.
244   intptr_t stack_size_in_bytes = (base + kPointerSize) - sp();
245   DCHECK(IsAligned(stack_size_in_bytes, kPointerSize));
246   DCHECK(type() == JAVA_SCRIPT);
247   DCHECK(stack_size_in_bytes >= 0);
248   return static_cast<int>(stack_size_in_bytes >> kPointerSizeLog2);
249 }
250
251
252 inline Object* JavaScriptFrame::receiver() const {
253   return GetParameter(-1);
254 }
255
256
257 inline void JavaScriptFrame::set_receiver(Object* value) {
258   Memory::Object_at(GetParameterSlot(-1)) = value;
259 }
260
261
262 inline bool JavaScriptFrame::has_adapted_arguments() const {
263   return IsArgumentsAdaptorFrame(caller_fp());
264 }
265
266
267 inline JSFunction* JavaScriptFrame::function() const {
268   return JSFunction::cast(function_slot_object());
269 }
270
271
272 inline StubFrame::StubFrame(StackFrameIteratorBase* iterator)
273     : StandardFrame(iterator) {
274 }
275
276
277 inline OptimizedFrame::OptimizedFrame(StackFrameIteratorBase* iterator)
278     : JavaScriptFrame(iterator) {
279 }
280
281
282 inline ArgumentsAdaptorFrame::ArgumentsAdaptorFrame(
283     StackFrameIteratorBase* iterator) : JavaScriptFrame(iterator) {
284 }
285
286
287 inline InternalFrame::InternalFrame(StackFrameIteratorBase* iterator)
288     : StandardFrame(iterator) {
289 }
290
291
292 inline StubFailureTrampolineFrame::StubFailureTrampolineFrame(
293     StackFrameIteratorBase* iterator) : StandardFrame(iterator) {
294 }
295
296
297 inline ConstructFrame::ConstructFrame(StackFrameIteratorBase* iterator)
298     : InternalFrame(iterator) {
299 }
300
301
302 inline JavaScriptFrameIterator::JavaScriptFrameIterator(
303     Isolate* isolate)
304     : iterator_(isolate) {
305   if (!done()) Advance();
306 }
307
308
309 inline JavaScriptFrameIterator::JavaScriptFrameIterator(
310     Isolate* isolate, ThreadLocalTop* top)
311     : iterator_(isolate, top) {
312   if (!done()) Advance();
313 }
314
315
316 inline JavaScriptFrame* JavaScriptFrameIterator::frame() const {
317   // TODO(1233797): The frame hierarchy needs to change. It's
318   // problematic that we can't use the safe-cast operator to cast to
319   // the JavaScript frame type, because we may encounter arguments
320   // adaptor frames.
321   StackFrame* frame = iterator_.frame();
322   DCHECK(frame->is_java_script() || frame->is_arguments_adaptor());
323   return static_cast<JavaScriptFrame*>(frame);
324 }
325
326
327 inline StackFrame* SafeStackFrameIterator::frame() const {
328   DCHECK(!done());
329   DCHECK(frame_->is_java_script() || frame_->is_exit());
330   return frame_;
331 }
332
333
334 } }  // namespace v8::internal
335
336 #endif  // V8_FRAMES_INL_H_