V8 Project
frames-inl.h
Go to the documentation of this file.
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_MIPS
21 #include "src/mips/frames-mips.h" // NOLINT
22 #elif V8_TARGET_ARCH_MIPS64
23 #include "src/mips64/frames-mips64.h" // NOLINT
24 #elif V8_TARGET_ARCH_X87
25 #include "src/x87/frames-x87.h" // NOLINT
26 #else
27 #error Unsupported target architecture.
28 #endif
29 
30 namespace v8 {
31 namespace internal {
32 
33 
34 inline Address StackHandler::address() const {
35  return reinterpret_cast<Address>(const_cast<StackHandler*>(this));
36 }
37 
38 
39 inline StackHandler* StackHandler::next() const {
40  const int offset = StackHandlerConstants::kNextOffset;
41  return FromAddress(Memory::Address_at(address() + offset));
42 }
43 
44 
45 inline bool StackHandler::includes(Address address) const {
46  Address start = this->address();
48  return start <= address && address <= end;
49 }
50 
51 
52 inline void StackHandler::Iterate(ObjectVisitor* v, Code* holder) const {
53  v->VisitPointer(context_address());
54  v->VisitPointer(code_address());
55 }
56 
57 
58 inline StackHandler* StackHandler::FromAddress(Address address) {
59  return reinterpret_cast<StackHandler*>(address);
60 }
61 
62 
63 inline bool StackHandler::is_js_entry() const {
64  return kind() == JS_ENTRY;
65 }
66 
67 
68 inline bool StackHandler::is_catch() const {
69  return kind() == CATCH;
70 }
71 
72 
73 inline bool StackHandler::is_finally() const {
74  return kind() == FINALLY;
75 }
76 
77 
78 inline StackHandler::Kind StackHandler::kind() const {
79  const int offset = StackHandlerConstants::kStateOffset;
80  return KindField::decode(Memory::unsigned_at(address() + offset));
81 }
82 
83 
84 inline unsigned StackHandler::index() const {
85  const int offset = StackHandlerConstants::kStateOffset;
86  return IndexField::decode(Memory::unsigned_at(address() + offset));
87 }
88 
89 
90 inline Object** StackHandler::context_address() const {
91  const int offset = StackHandlerConstants::kContextOffset;
92  return reinterpret_cast<Object**>(address() + offset);
93 }
94 
95 
96 inline Object** StackHandler::code_address() const {
97  const int offset = StackHandlerConstants::kCodeOffset;
98  return reinterpret_cast<Object**>(address() + offset);
99 }
100 
101 
103  : iterator_(iterator), isolate_(iterator_->isolate()) {
104 }
105 
106 
107 inline StackHandler* StackFrame::top_handler() const {
108  return iterator_->handler();
109 }
110 
111 
112 inline Code* StackFrame::LookupCode() const {
113  return GetContainingCode(isolate(), pc());
114 }
115 
116 
117 inline Code* StackFrame::GetContainingCode(Isolate* isolate, Address pc) {
118  return isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code;
119 }
120 
121 
122 inline Address* StackFrame::ResolveReturnAddressLocation(Address* pc_address) {
123  if (return_address_location_resolver_ == NULL) {
124  return pc_address;
125  } else {
126  return reinterpret_cast<Address*>(
127  return_address_location_resolver_(
128  reinterpret_cast<uintptr_t>(pc_address)));
129  }
130 }
131 
132 
133 inline EntryFrame::EntryFrame(StackFrameIteratorBase* iterator)
134  : StackFrame(iterator) {
135 }
136 
137 
139  StackFrameIteratorBase* iterator)
140  : EntryFrame(iterator) {
141 }
142 
143 
145  : StackFrame(iterator) {
146 }
147 
148 
150  : StackFrame(iterator) {
151 }
152 
153 
154 inline Object* StandardFrame::GetExpression(int index) const {
156 }
157 
158 
159 inline void StandardFrame::SetExpression(int index, Object* value) {
160  Memory::Object_at(GetExpressionAddress(index)) = value;
161 }
162 
163 
165  const int offset = StandardFrameConstants::kContextOffset;
166  return Memory::Object_at(fp() + offset);
167 }
168 
169 
172 }
173 
174 
177 }
178 
179 
182 }
183 
184 
187 }
188 
189 
191  Object* marker =
194 }
195 
196 
198  Object* marker =
200  return marker == Smi::FromInt(StackFrame::CONSTRUCT);
201 }
202 
203 
205  : StandardFrame(iterator) {
206 }
207 
208 
210  int param_count = ComputeParametersCount();
211  DCHECK(-1 <= index && index < param_count);
212  int parameter_offset = (param_count - index - 1) * kPointerSize;
213  return caller_sp() + parameter_offset;
214 }
215 
216 
218  return Memory::Object_at(GetParameterSlot(index));
219 }
220 
221 
222 inline Address JavaScriptFrame::GetOperandSlot(int index) const {
225  DCHECK_EQ(type(), JAVA_SCRIPT);
227  DCHECK_LE(0, index);
228  // Operand stack grows down.
229  return base - index * kPointerSize;
230 }
231 
232 
233 inline Object* JavaScriptFrame::GetOperand(int index) const {
234  return Memory::Object_at(GetOperandSlot(index));
235 }
236 
237 
240  // Base points to low address of first operand and stack grows down, so add
241  // kPointerSize to get the actual stack size.
242  intptr_t stack_size_in_bytes = (base + kPointerSize) - sp();
243  DCHECK(IsAligned(stack_size_in_bytes, kPointerSize));
244  DCHECK(type() == JAVA_SCRIPT);
245  DCHECK(stack_size_in_bytes >= 0);
246  return static_cast<int>(stack_size_in_bytes >> kPointerSizeLog2);
247 }
248 
249 
251  return GetParameter(-1);
252 }
253 
254 
256  Memory::Object_at(GetParameterSlot(-1)) = value;
257 }
258 
259 
262 }
263 
264 
266  return JSFunction::cast(function_slot_object());
267 }
268 
269 
271  : StandardFrame(iterator) {
272 }
273 
274 
276  : JavaScriptFrame(iterator) {
277 }
278 
279 
281  StackFrameIteratorBase* iterator) : JavaScriptFrame(iterator) {
282 }
283 
284 
286  : StandardFrame(iterator) {
287 }
288 
289 
291  StackFrameIteratorBase* iterator) : StandardFrame(iterator) {
292 }
293 
294 
296  : InternalFrame(iterator) {
297 }
298 
299 
300 inline JavaScriptFrameIterator::JavaScriptFrameIterator(
301  Isolate* isolate)
302  : iterator_(isolate) {
303  if (!done()) Advance();
304 }
305 
306 
307 inline JavaScriptFrameIterator::JavaScriptFrameIterator(
308  Isolate* isolate, ThreadLocalTop* top)
309  : iterator_(isolate, top) {
310  if (!done()) Advance();
311 }
312 
313 
314 inline JavaScriptFrame* JavaScriptFrameIterator::frame() const {
315  // TODO(1233797): The frame hierarchy needs to change. It's
316  // problematic that we can't use the safe-cast operator to cast to
317  // the JavaScript frame type, because we may encounter arguments
318  // adaptor frames.
319  StackFrame* frame = iterator_.frame();
320  DCHECK(frame->is_java_script() || frame->is_arguments_adaptor());
321  return static_cast<JavaScriptFrame*>(frame);
322 }
323 
324 
326  DCHECK(!done());
327  DCHECK(frame_->is_java_script() || frame_->is_exit());
328  return frame_;
329 }
330 
331 
332 } } // namespace v8::internal
333 
334 #endif // V8_FRAMES_INL_H_
Isolate represents an isolated instance of the V8 engine.
Definition: v8.h:4356
A single JavaScript stack frame.
Definition: v8.h:1358
ArgumentsAdaptorFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:280
ConstructFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:295
EntryConstructFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:138
ExitFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:144
InternalFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:285
Object * receiver() const
Definition: frames-inl.h:250
void set_receiver(Object *value)
Definition: frames-inl.h:255
Object * function_slot_object() const
Definition: frames-arm.h:149
bool has_adapted_arguments() const
Definition: frames-inl.h:260
Address GetParameterSlot(int index) const
Definition: frames-inl.h:209
JavaScriptFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:204
Address GetOperandSlot(int index) const
Definition: frames-inl.h:222
Object * GetParameter(int index) const
Definition: frames-inl.h:217
Object * GetOperand(int index) const
Definition: frames-inl.h:233
JSFunction * function() const
Definition: frames-inl.h:265
virtual Type type() const
Definition: frames.h:552
int ComputeParametersCount() const
Definition: frames.h:562
static Object *& Object_at(Address addr)
Definition: v8memory.h:60
static Address & Address_at(Address addr)
Definition: v8memory.h:56
static unsigned & unsigned_at(Address addr)
Definition: v8memory.h:40
OptimizedFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:275
static Smi * FromInt(int value)
Definition: objects-inl.h:1321
static const int kCodeOffset
Definition: frames.h:72
static const int kContextOffset
Definition: frames.h:74
static const int kNextOffset
Definition: frames.h:71
static const int kStateOffset
Definition: frames.h:73
static const int kContextOffset
Definition: frames.h:162
static const int kConstantPoolOffset
Definition: frames.h:163
static const int kCallerPCOffset
Definition: frames.h:166
static const int kMarkerOffset
Definition: frames.h:161
static const int kCallerFPOffset
Definition: frames.h:165
Object * context() const
Definition: frames-inl.h:164
Address GetExpressionAddress(int n) const
Definition: frames.cc:563
StandardFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:149
static Address ComputeConstantPoolAddress(Address fp)
Definition: frames-inl.h:185
static bool IsArgumentsAdaptorFrame(Address fp)
Definition: frames-inl.h:190
Address caller_pc() const
Definition: frames-inl.h:175
Address caller_fp() const
Definition: frames-inl.h:170
Object * GetExpression(int index) const
Definition: frames-inl.h:154
static Address ComputePCAddress(Address fp)
Definition: frames-inl.h:180
void SetExpression(int index, Object *value)
Definition: frames-inl.h:159
static bool IsConstructFrame(Address fp)
Definition: frames-inl.h:197
StubFailureTrampolineFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:290
StubFrame(StackFrameIteratorBase *iterator)
Definition: frames-inl.h:270
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define DCHECK_LE(v1, v2)
Definition: logging.h:210
#define DCHECK(condition)
Definition: logging.h:205
#define DCHECK_LT(v1, v2)
Definition: logging.h:209
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206
HANDLE HANDLE LPSTACKFRAME64 StackFrame
const int kPointerSize
Definition: globals.h:129
bool IsAddressAligned(Address addr, intptr_t alignment, int offset=0)
Definition: utils.h:129
const Register fp
kSerializedDataOffset Object
Definition: objects-inl.h:5322
const Register sp
const int kPointerSizeLog2
Definition: globals.h:147
const Register pc
byte * Address
Definition: globals.h:101
bool IsAligned(T value, U alignment)
Definition: utils.h:123
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20