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.
5 #ifndef V8_FRAMES_INL_H_
6 #define V8_FRAMES_INL_H_
8 #include "src/frames.h"
9 #include "src/isolate.h"
10 #include "src/v8memory.h"
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
29 #error Unsupported target architecture.
36 inline Address StackHandler::address() const {
37 return reinterpret_cast<Address>(const_cast<StackHandler*>(this));
41 inline StackHandler* StackHandler::next() const {
42 const int offset = StackHandlerConstants::kNextOffset;
43 return FromAddress(Memory::Address_at(address() + offset));
47 inline StackHandler* StackHandler::FromAddress(Address address) {
48 return reinterpret_cast<StackHandler*>(address);
52 inline StackFrame::StackFrame(StackFrameIteratorBase* iterator)
53 : iterator_(iterator), isolate_(iterator_->isolate()) {
57 inline StackHandler* StackFrame::top_handler() const {
58 return iterator_->handler();
62 inline Code* StackFrame::LookupCode() const {
63 return GetContainingCode(isolate(), pc());
67 inline Code* StackFrame::GetContainingCode(Isolate* isolate, Address pc) {
68 return isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code;
72 inline Address* StackFrame::ResolveReturnAddressLocation(Address* pc_address) {
73 if (return_address_location_resolver_ == NULL) {
76 return reinterpret_cast<Address*>(
77 return_address_location_resolver_(
78 reinterpret_cast<uintptr_t>(pc_address)));
83 inline EntryFrame::EntryFrame(StackFrameIteratorBase* iterator)
84 : StackFrame(iterator) {
88 inline EntryConstructFrame::EntryConstructFrame(
89 StackFrameIteratorBase* iterator)
90 : EntryFrame(iterator) {
94 inline ExitFrame::ExitFrame(StackFrameIteratorBase* iterator)
95 : StackFrame(iterator) {
99 inline StandardFrame::StandardFrame(StackFrameIteratorBase* iterator)
100 : StackFrame(iterator) {
104 inline Object* StandardFrame::GetExpression(int index) const {
105 return Memory::Object_at(GetExpressionAddress(index));
109 inline void StandardFrame::SetExpression(int index, Object* value) {
110 Memory::Object_at(GetExpressionAddress(index)) = value;
114 inline Object* StandardFrame::context() const {
115 const int offset = StandardFrameConstants::kContextOffset;
116 return Memory::Object_at(fp() + offset);
120 inline Address StandardFrame::caller_fp() const {
121 return Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset);
125 inline Address StandardFrame::caller_pc() const {
126 return Memory::Address_at(ComputePCAddress(fp()));
130 inline Address StandardFrame::ComputePCAddress(Address fp) {
131 return fp + StandardFrameConstants::kCallerPCOffset;
135 inline Address StandardFrame::ComputeConstantPoolAddress(Address fp) {
136 return fp + StandardFrameConstants::kConstantPoolOffset;
140 inline bool StandardFrame::IsArgumentsAdaptorFrame(Address fp) {
142 Memory::Object_at(fp + StandardFrameConstants::kContextOffset);
143 return marker == Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR);
147 inline bool StandardFrame::IsConstructFrame(Address fp) {
149 Memory::Object_at(fp + StandardFrameConstants::kMarkerOffset);
150 return marker == Smi::FromInt(StackFrame::CONSTRUCT);
154 inline JavaScriptFrame::JavaScriptFrame(StackFrameIteratorBase* iterator)
155 : StandardFrame(iterator) {
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;
167 Object* JavaScriptFrame::GetParameter(int index) const {
168 return Memory::Object_at(GetParameterSlot(index));
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());
178 // Operand stack grows down.
179 return base - index * kPointerSize;
183 inline Object* JavaScriptFrame::GetOperand(int index) const {
184 return Memory::Object_at(GetOperandSlot(index));
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);
200 inline Object* JavaScriptFrame::receiver() const {
201 return GetParameter(-1);
205 inline void JavaScriptFrame::set_receiver(Object* value) {
206 Memory::Object_at(GetParameterSlot(-1)) = value;
210 inline bool JavaScriptFrame::has_adapted_arguments() const {
211 return IsArgumentsAdaptorFrame(caller_fp());
215 inline JSFunction* JavaScriptFrame::function() const {
216 return JSFunction::cast(function_slot_object());
220 inline StubFrame::StubFrame(StackFrameIteratorBase* iterator)
221 : StandardFrame(iterator) {
225 inline OptimizedFrame::OptimizedFrame(StackFrameIteratorBase* iterator)
226 : JavaScriptFrame(iterator) {
230 inline ArgumentsAdaptorFrame::ArgumentsAdaptorFrame(
231 StackFrameIteratorBase* iterator) : JavaScriptFrame(iterator) {
235 inline InternalFrame::InternalFrame(StackFrameIteratorBase* iterator)
236 : StandardFrame(iterator) {
240 inline StubFailureTrampolineFrame::StubFailureTrampolineFrame(
241 StackFrameIteratorBase* iterator) : StandardFrame(iterator) {
245 inline ConstructFrame::ConstructFrame(StackFrameIteratorBase* iterator)
246 : InternalFrame(iterator) {
250 inline JavaScriptFrameIterator::JavaScriptFrameIterator(
252 : iterator_(isolate) {
253 if (!done()) Advance();
257 inline JavaScriptFrameIterator::JavaScriptFrameIterator(
258 Isolate* isolate, ThreadLocalTop* top)
259 : iterator_(isolate, top) {
260 if (!done()) Advance();
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
269 StackFrame* frame = iterator_.frame();
270 DCHECK(frame->is_java_script() || frame->is_arguments_adaptor());
271 return static_cast<JavaScriptFrame*>(frame);
275 inline StackFrame* SafeStackFrameIterator::frame() const {
277 DCHECK(frame_->is_java_script() || frame_->is_exit());
282 } } // namespace v8::internal
284 #endif // V8_FRAMES_INL_H_