v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
frames-inl.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_FRAMES_INL_H_
29 #define V8_FRAMES_INL_H_
30 
31 #include "frames.h"
32 #include "isolate.h"
33 #include "v8memory.h"
34 
35 #if V8_TARGET_ARCH_IA32
36 #include "ia32/frames-ia32.h"
37 #elif V8_TARGET_ARCH_X64
38 #include "x64/frames-x64.h"
39 #elif V8_TARGET_ARCH_ARM64
40 #include "arm64/frames-arm64.h"
41 #elif V8_TARGET_ARCH_ARM
42 #include "arm/frames-arm.h"
43 #elif V8_TARGET_ARCH_MIPS
44 #include "mips/frames-mips.h"
45 #else
46 #error Unsupported target architecture.
47 #endif
48 
49 namespace v8 {
50 namespace internal {
51 
52 
53 inline Address StackHandler::address() const {
54  return reinterpret_cast<Address>(const_cast<StackHandler*>(this));
55 }
56 
57 
58 inline StackHandler* StackHandler::next() const {
59  const int offset = StackHandlerConstants::kNextOffset;
60  return FromAddress(Memory::Address_at(address() + offset));
61 }
62 
63 
64 inline bool StackHandler::includes(Address address) const {
65  Address start = this->address();
67  return start <= address && address <= end;
68 }
69 
70 
71 inline void StackHandler::Iterate(ObjectVisitor* v, Code* holder) const {
72  v->VisitPointer(context_address());
73  v->VisitPointer(code_address());
74 }
75 
76 
77 inline StackHandler* StackHandler::FromAddress(Address address) {
78  return reinterpret_cast<StackHandler*>(address);
79 }
80 
81 
82 inline bool StackHandler::is_js_entry() const {
83  return kind() == JS_ENTRY;
84 }
85 
86 
87 inline bool StackHandler::is_catch() const {
88  return kind() == CATCH;
89 }
90 
91 
92 inline bool StackHandler::is_finally() const {
93  return kind() == FINALLY;
94 }
95 
96 
97 inline StackHandler::Kind StackHandler::kind() const {
98  const int offset = StackHandlerConstants::kStateOffset;
99  return KindField::decode(Memory::unsigned_at(address() + offset));
100 }
101 
102 
103 inline unsigned StackHandler::index() const {
104  const int offset = StackHandlerConstants::kStateOffset;
105  return IndexField::decode(Memory::unsigned_at(address() + offset));
106 }
107 
108 
109 inline Object** StackHandler::context_address() const {
110  const int offset = StackHandlerConstants::kContextOffset;
111  return reinterpret_cast<Object**>(address() + offset);
112 }
113 
114 
115 inline Object** StackHandler::code_address() const {
116  const int offset = StackHandlerConstants::kCodeOffset;
117  return reinterpret_cast<Object**>(address() + offset);
118 }
119 
120 
121 inline StackFrame::StackFrame(StackFrameIteratorBase* iterator)
122  : iterator_(iterator), isolate_(iterator_->isolate()) {
123 }
124 
125 
126 inline StackHandler* StackFrame::top_handler() const {
127  return iterator_->handler();
128 }
129 
130 
131 inline Code* StackFrame::LookupCode() const {
132  return GetContainingCode(isolate(), pc());
133 }
134 
135 
136 inline Code* StackFrame::GetContainingCode(Isolate* isolate, Address pc) {
137  return isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code;
138 }
139 
140 
141 inline Address* StackFrame::ResolveReturnAddressLocation(Address* pc_address) {
142  if (return_address_location_resolver_ == NULL) {
143  return pc_address;
144  } else {
145  return reinterpret_cast<Address*>(
146  return_address_location_resolver_(
147  reinterpret_cast<uintptr_t>(pc_address)));
148  }
149 }
150 
151 
152 inline EntryFrame::EntryFrame(StackFrameIteratorBase* iterator)
153  : StackFrame(iterator) {
154 }
155 
156 
158  StackFrameIteratorBase* iterator)
159  : EntryFrame(iterator) {
160 }
161 
162 
163 inline ExitFrame::ExitFrame(StackFrameIteratorBase* iterator)
164  : StackFrame(iterator) {
165 }
166 
167 
168 inline StandardFrame::StandardFrame(StackFrameIteratorBase* iterator)
169  : StackFrame(iterator) {
170 }
171 
172 
173 inline Object* StandardFrame::GetExpression(int index) const {
175 }
176 
177 
178 inline void StandardFrame::SetExpression(int index, Object* value) {
179  Memory::Object_at(GetExpressionAddress(index)) = value;
180 }
181 
182 
184  const int offset = StandardFrameConstants::kContextOffset;
185  return Memory::Object_at(fp() + offset);
186 }
187 
188 
191 }
192 
193 
196 }
197 
198 
201 }
202 
203 
206 }
207 
208 
210  Object* marker =
213 }
214 
215 
217  Object* marker =
219  return marker == Smi::FromInt(StackFrame::CONSTRUCT);
220 }
221 
222 
223 inline JavaScriptFrame::JavaScriptFrame(StackFrameIteratorBase* iterator)
224  : StandardFrame(iterator) {
225 }
226 
227 
229  int param_count = ComputeParametersCount();
230  ASSERT(-1 <= index && index < param_count);
231  int parameter_offset = (param_count - index - 1) * kPointerSize;
232  return caller_sp() + parameter_offset;
233 }
234 
235 
237  return Memory::Object_at(GetParameterSlot(index));
238 }
239 
240 
241 inline Address JavaScriptFrame::GetOperandSlot(int index) const {
244  ASSERT_EQ(type(), JAVA_SCRIPT);
246  ASSERT_LE(0, index);
247  // Operand stack grows down.
248  return base - index * kPointerSize;
249 }
250 
251 
252 inline Object* JavaScriptFrame::GetOperand(int index) const {
253  return Memory::Object_at(GetOperandSlot(index));
254 }
255 
256 
259  // Base points to low address of first operand and stack grows down, so add
260  // kPointerSize to get the actual stack size.
261  intptr_t stack_size_in_bytes = (base + kPointerSize) - sp();
262  ASSERT(IsAligned(stack_size_in_bytes, kPointerSize));
263  ASSERT(type() == JAVA_SCRIPT);
264  ASSERT(stack_size_in_bytes >= 0);
265  return static_cast<int>(stack_size_in_bytes >> kPointerSizeLog2);
266 }
267 
268 
270  return GetParameter(-1);
271 }
272 
273 
275  Memory::Object_at(GetParameterSlot(-1)) = value;
276 }
277 
278 
281 }
282 
283 
285  return JSFunction::cast(function_slot_object());
286 }
287 
288 
289 inline StubFrame::StubFrame(StackFrameIteratorBase* iterator)
290  : StandardFrame(iterator) {
291 }
292 
293 
294 inline OptimizedFrame::OptimizedFrame(StackFrameIteratorBase* iterator)
295  : JavaScriptFrame(iterator) {
296 }
297 
298 
300  StackFrameIteratorBase* iterator) : JavaScriptFrame(iterator) {
301 }
302 
303 
304 inline InternalFrame::InternalFrame(StackFrameIteratorBase* iterator)
305  : StandardFrame(iterator) {
306 }
307 
308 
310  StackFrameIteratorBase* iterator) : StandardFrame(iterator) {
311 }
312 
313 
314 inline ConstructFrame::ConstructFrame(StackFrameIteratorBase* iterator)
315  : InternalFrame(iterator) {
316 }
317 
318 
319 inline JavaScriptFrameIterator::JavaScriptFrameIterator(
320  Isolate* isolate)
321  : iterator_(isolate) {
322  if (!done()) Advance();
323 }
324 
325 
326 inline JavaScriptFrameIterator::JavaScriptFrameIterator(
327  Isolate* isolate, ThreadLocalTop* top)
328  : iterator_(isolate, top) {
329  if (!done()) Advance();
330 }
331 
332 
333 inline JavaScriptFrame* JavaScriptFrameIterator::frame() const {
334  // TODO(1233797): The frame hierarchy needs to change. It's
335  // problematic that we can't use the safe-cast operator to cast to
336  // the JavaScript frame type, because we may encounter arguments
337  // adaptor frames.
338  StackFrame* frame = iterator_.frame();
339  ASSERT(frame->is_java_script() || frame->is_arguments_adaptor());
340  return static_cast<JavaScriptFrame*>(frame);
341 }
342 
343 
345  ASSERT(!done());
346  ASSERT(frame_->is_java_script() || frame_->is_exit());
347  return frame_;
348 }
349 
350 
351 } } // namespace v8::internal
352 
353 #endif // V8_FRAMES_INL_H_
byte * Address
Definition: globals.h:186
Object * context() const
Definition: frames-inl.h:183
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
static Object *& Object_at(Address addr)
Definition: v8memory.h:83
static const int kStateOffset
Definition: frames.h:96
bool IsAddressAligned(Address addr, intptr_t alignment, int offset=0)
Definition: utils.h:217
ConstructFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:314
static const int kCodeOffset
Definition: frames.h:95
static Smi * FromInt(int value)
Definition: objects-inl.h:1209
static Address ComputeConstantPoolAddress(Address fp)
Definition: frames-inl.h:204
Address GetParameterSlot(int index) const
Definition: frames-inl.h:228
static bool IsArgumentsAdaptorFrame(Address fp)
Definition: frames-inl.h:209
Address GetExpressionAddress(int n) const
Definition: frames.cc:586
kSerializedDataOffset Object
Definition: objects-inl.h:5016
Address caller_fp() const
Definition: frames-inl.h:189
Object * GetExpression(int index) const
Definition: frames-inl.h:173
EntryConstructFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:157
#define ASSERT(condition)
Definition: checks.h:329
static const int kContextOffset
Definition: frames.h:185
const int kPointerSizeLog2
Definition: globals.h:281
static const int kNextOffset
Definition: frames.h:94
ExitFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:163
static const int kCallerFPOffset
Definition: frames.h:188
ArgumentsAdaptorFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:299
int ComputeParametersCount() const
Definition: frames.h:585
Object * receiver() const
Definition: frames-inl.h:269
const Register sp
HANDLE HANDLE LPSTACKFRAME64 StackFrame
InternalFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:304
static Address ComputePCAddress(Address fp)
Definition: frames-inl.h:199
const int kPointerSize
Definition: globals.h:268
void SetExpression(int index, Object *value)
Definition: frames-inl.h:178
static Address & Address_at(Address addr)
Definition: v8memory.h:79
int ComputeOperandsCount() const
Definition: frames-inl.h:257
bool IsAligned(T value, U alignment)
Definition: utils.h:211
static const int kConstantPoolOffset
Definition: frames.h:186
const Register pc
#define ASSERT_LE(v1, v2)
Definition: checks.h:334
static const int kCallerPCOffset
Definition: frames.h:189
void set_receiver(Object *value)
Definition: frames-inl.h:274
static const int kMarkerOffset
Definition: frames.h:184
Address caller_pc() const
Definition: frames-inl.h:194
StubFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:289
#define ASSERT_LT(v1, v2)
Definition: checks.h:333
StubFailureTrampolineFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:309
static const int kContextOffset
Definition: frames.h:97
Object * GetOperand(int index) const
Definition: frames-inl.h:252
JavaScriptFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:223
#define ASSERT_EQ(v1, v2)
Definition: checks.h:330
static bool IsConstructFrame(Address fp)
Definition: frames-inl.h:216
static unsigned & unsigned_at(Address addr)
Definition: v8memory.h:63
virtual Type type() const
Definition: frames.h:575
Address GetOperandSlot(int index) const
Definition: frames-inl.h:241
const Register fp
StandardFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:168
Object * GetParameter(int index) const
Definition: frames-inl.h:236
Definition: frames.h:387
bool has_adapted_arguments() const
Definition: frames-inl.h:279
JSFunction * function() const
Definition: frames-inl.h:284
OptimizedFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:294
static JSFunction * cast(Object *obj)