deps: update v8 to 4.3.61.21
[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 StackHandler* StackHandler::FromAddress(Address address) {
48   return reinterpret_cast<StackHandler*>(address);
49 }
50
51
52 inline StackFrame::StackFrame(StackFrameIteratorBase* iterator)
53     : iterator_(iterator), isolate_(iterator_->isolate()) {
54 }
55
56
57 inline StackHandler* StackFrame::top_handler() const {
58   return iterator_->handler();
59 }
60
61
62 inline Code* StackFrame::LookupCode() const {
63   return GetContainingCode(isolate(), pc());
64 }
65
66
67 inline Code* StackFrame::GetContainingCode(Isolate* isolate, Address pc) {
68   return isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code;
69 }
70
71
72 inline Address* StackFrame::ResolveReturnAddressLocation(Address* pc_address) {
73   if (return_address_location_resolver_ == NULL) {
74     return pc_address;
75   } else {
76     return reinterpret_cast<Address*>(
77         return_address_location_resolver_(
78             reinterpret_cast<uintptr_t>(pc_address)));
79   }
80 }
81
82
83 inline EntryFrame::EntryFrame(StackFrameIteratorBase* iterator)
84     : StackFrame(iterator) {
85 }
86
87
88 inline EntryConstructFrame::EntryConstructFrame(
89     StackFrameIteratorBase* iterator)
90     : EntryFrame(iterator) {
91 }
92
93
94 inline ExitFrame::ExitFrame(StackFrameIteratorBase* iterator)
95     : StackFrame(iterator) {
96 }
97
98
99 inline StandardFrame::StandardFrame(StackFrameIteratorBase* iterator)
100     : StackFrame(iterator) {
101 }
102
103
104 inline Object* StandardFrame::GetExpression(int index) const {
105   return Memory::Object_at(GetExpressionAddress(index));
106 }
107
108
109 inline void StandardFrame::SetExpression(int index, Object* value) {
110   Memory::Object_at(GetExpressionAddress(index)) = value;
111 }
112
113
114 inline Object* StandardFrame::context() const {
115   const int offset = StandardFrameConstants::kContextOffset;
116   return Memory::Object_at(fp() + offset);
117 }
118
119
120 inline Address StandardFrame::caller_fp() const {
121   return Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset);
122 }
123
124
125 inline Address StandardFrame::caller_pc() const {
126   return Memory::Address_at(ComputePCAddress(fp()));
127 }
128
129
130 inline Address StandardFrame::ComputePCAddress(Address fp) {
131   return fp + StandardFrameConstants::kCallerPCOffset;
132 }
133
134
135 inline Address StandardFrame::ComputeConstantPoolAddress(Address fp) {
136   return fp + StandardFrameConstants::kConstantPoolOffset;
137 }
138
139
140 inline bool StandardFrame::IsArgumentsAdaptorFrame(Address fp) {
141   Object* marker =
142       Memory::Object_at(fp + StandardFrameConstants::kContextOffset);
143   return marker == Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR);
144 }
145
146
147 inline bool StandardFrame::IsConstructFrame(Address fp) {
148   Object* marker =
149       Memory::Object_at(fp + StandardFrameConstants::kMarkerOffset);
150   return marker == Smi::FromInt(StackFrame::CONSTRUCT);
151 }
152
153
154 inline JavaScriptFrame::JavaScriptFrame(StackFrameIteratorBase* iterator)
155     : StandardFrame(iterator) {
156 }
157
158
159 Address JavaScriptFrame::GetParameterSlot(int index) const {
160   int param_count = ComputeParametersCount();
161   DCHECK(-1 <= index && index < param_count);
162   int parameter_offset = (param_count - index - 1) * kPointerSize;
163   return caller_sp() + parameter_offset;
164 }
165
166
167 Object* JavaScriptFrame::GetParameter(int index) const {
168   return Memory::Object_at(GetParameterSlot(index));
169 }
170
171
172 inline Address JavaScriptFrame::GetOperandSlot(int index) const {
173   Address base = fp() + JavaScriptFrameConstants::kLocal0Offset;
174   DCHECK(IsAddressAligned(base, kPointerSize));
175   DCHECK_EQ(type(), JAVA_SCRIPT);
176   DCHECK_LT(index, ComputeOperandsCount());
177   DCHECK_LE(0, index);
178   // Operand stack grows down.
179   return base - index * kPointerSize;
180 }
181
182
183 inline Object* JavaScriptFrame::GetOperand(int index) const {
184   return Memory::Object_at(GetOperandSlot(index));
185 }
186
187
188 inline int JavaScriptFrame::ComputeOperandsCount() const {
189   Address base = fp() + JavaScriptFrameConstants::kLocal0Offset;
190   // Base points to low address of first operand and stack grows down, so add
191   // kPointerSize to get the actual stack size.
192   intptr_t stack_size_in_bytes = (base + kPointerSize) - sp();
193   DCHECK(IsAligned(stack_size_in_bytes, kPointerSize));
194   DCHECK(type() == JAVA_SCRIPT);
195   DCHECK(stack_size_in_bytes >= 0);
196   return static_cast<int>(stack_size_in_bytes >> kPointerSizeLog2);
197 }
198
199
200 inline Object* JavaScriptFrame::receiver() const {
201   return GetParameter(-1);
202 }
203
204
205 inline void JavaScriptFrame::set_receiver(Object* value) {
206   Memory::Object_at(GetParameterSlot(-1)) = value;
207 }
208
209
210 inline bool JavaScriptFrame::has_adapted_arguments() const {
211   return IsArgumentsAdaptorFrame(caller_fp());
212 }
213
214
215 inline JSFunction* JavaScriptFrame::function() const {
216   return JSFunction::cast(function_slot_object());
217 }
218
219
220 inline StubFrame::StubFrame(StackFrameIteratorBase* iterator)
221     : StandardFrame(iterator) {
222 }
223
224
225 inline OptimizedFrame::OptimizedFrame(StackFrameIteratorBase* iterator)
226     : JavaScriptFrame(iterator) {
227 }
228
229
230 inline ArgumentsAdaptorFrame::ArgumentsAdaptorFrame(
231     StackFrameIteratorBase* iterator) : JavaScriptFrame(iterator) {
232 }
233
234
235 inline InternalFrame::InternalFrame(StackFrameIteratorBase* iterator)
236     : StandardFrame(iterator) {
237 }
238
239
240 inline StubFailureTrampolineFrame::StubFailureTrampolineFrame(
241     StackFrameIteratorBase* iterator) : StandardFrame(iterator) {
242 }
243
244
245 inline ConstructFrame::ConstructFrame(StackFrameIteratorBase* iterator)
246     : InternalFrame(iterator) {
247 }
248
249
250 inline JavaScriptFrameIterator::JavaScriptFrameIterator(
251     Isolate* isolate)
252     : iterator_(isolate) {
253   if (!done()) Advance();
254 }
255
256
257 inline JavaScriptFrameIterator::JavaScriptFrameIterator(
258     Isolate* isolate, ThreadLocalTop* top)
259     : iterator_(isolate, top) {
260   if (!done()) Advance();
261 }
262
263
264 inline JavaScriptFrame* JavaScriptFrameIterator::frame() const {
265   // TODO(1233797): The frame hierarchy needs to change. It's
266   // problematic that we can't use the safe-cast operator to cast to
267   // the JavaScript frame type, because we may encounter arguments
268   // adaptor frames.
269   StackFrame* frame = iterator_.frame();
270   DCHECK(frame->is_java_script() || frame->is_arguments_adaptor());
271   return static_cast<JavaScriptFrame*>(frame);
272 }
273
274
275 inline StackFrame* SafeStackFrameIterator::frame() const {
276   DCHECK(!done());
277   DCHECK(frame_->is_java_script() || frame_->is_exit());
278   return frame_;
279 }
280
281
282 } }  // namespace v8::internal
283
284 #endif  // V8_FRAMES_INL_H_