blob: 78bb646c78df386112ee023089c5e0e0128e2a62 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2006-2008 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
33#if V8_TARGET_ARCH_IA32
34#include "ia32/frames-ia32.h"
35#elif V8_TARGET_ARCH_X64
36#include "x64/frames-x64.h"
37#elif V8_TARGET_ARCH_ARM
38#include "arm/frames-arm.h"
Andrei Popescu31002712010-02-23 13:46:05 +000039#elif V8_TARGET_ARCH_MIPS
40#include "mips/frames-mips.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000041#else
42#error Unsupported target architecture.
43#endif
44
45namespace v8 {
46namespace internal {
47
48
49inline Address StackHandler::address() const {
50 return reinterpret_cast<Address>(const_cast<StackHandler*>(this));
51}
52
53
54inline StackHandler* StackHandler::next() const {
55 const int offset = StackHandlerConstants::kNextOffset;
56 return FromAddress(Memory::Address_at(address() + offset));
57}
58
59
60inline bool StackHandler::includes(Address address) const {
61 Address start = this->address();
62 Address end = start + StackHandlerConstants::kSize;
63 return start <= address && address <= end;
64}
65
66
Kristian Monsen80d68ea2010-09-08 11:05:35 +010067inline void StackHandler::Iterate(ObjectVisitor* v, Code* holder) const {
68 StackFrame::IteratePc(v, pc_address(), holder);
Steve Blocka7e24c12009-10-30 11:49:00 +000069}
70
71
72inline StackHandler* StackHandler::FromAddress(Address address) {
73 return reinterpret_cast<StackHandler*>(address);
74}
75
76
77inline StackHandler::State StackHandler::state() const {
78 const int offset = StackHandlerConstants::kStateOffset;
79 return static_cast<State>(Memory::int_at(address() + offset));
80}
81
82
Kristian Monsen80d68ea2010-09-08 11:05:35 +010083inline Address* StackHandler::pc_address() const {
Steve Blocka7e24c12009-10-30 11:49:00 +000084 const int offset = StackHandlerConstants::kPCOffset;
Kristian Monsen80d68ea2010-09-08 11:05:35 +010085 return reinterpret_cast<Address*>(address() + offset);
Steve Blocka7e24c12009-10-30 11:49:00 +000086}
87
88
89inline StackHandler* StackFrame::top_handler() const {
90 return iterator_->handler();
91}
92
93
94inline Object* StandardFrame::GetExpression(int index) const {
95 return Memory::Object_at(GetExpressionAddress(index));
96}
97
98
99inline void StandardFrame::SetExpression(int index, Object* value) {
100 Memory::Object_at(GetExpressionAddress(index)) = value;
101}
102
103
104inline Object* StandardFrame::context() const {
105 const int offset = StandardFrameConstants::kContextOffset;
106 return Memory::Object_at(fp() + offset);
107}
108
109
110inline Address StandardFrame::caller_fp() const {
111 return Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset);
112}
113
114
115inline Address StandardFrame::caller_pc() const {
116 return Memory::Address_at(ComputePCAddress(fp()));
117}
118
119
120inline Address StandardFrame::ComputePCAddress(Address fp) {
121 return fp + StandardFrameConstants::kCallerPCOffset;
122}
123
124
125inline bool StandardFrame::IsArgumentsAdaptorFrame(Address fp) {
126 Object* marker =
127 Memory::Object_at(fp + StandardFrameConstants::kContextOffset);
128 return marker == Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR);
129}
130
131
132inline bool StandardFrame::IsConstructFrame(Address fp) {
133 Object* marker =
134 Memory::Object_at(fp + StandardFrameConstants::kMarkerOffset);
135 return marker == Smi::FromInt(CONSTRUCT);
136}
137
138
139inline Object* JavaScriptFrame::receiver() const {
140 const int offset = JavaScriptFrameConstants::kReceiverOffset;
141 return Memory::Object_at(caller_sp() + offset);
142}
143
144
145inline void JavaScriptFrame::set_receiver(Object* value) {
146 const int offset = JavaScriptFrameConstants::kReceiverOffset;
147 Memory::Object_at(caller_sp() + offset) = value;
148}
149
150
151inline bool JavaScriptFrame::has_adapted_arguments() const {
152 return IsArgumentsAdaptorFrame(caller_fp());
153}
154
155
156inline Object* JavaScriptFrame::function() const {
157 Object* result = function_slot_object();
158 ASSERT(result->IsJSFunction());
159 return result;
160}
161
162
163template<typename Iterator>
164inline JavaScriptFrame* JavaScriptFrameIteratorTemp<Iterator>::frame() const {
165 // TODO(1233797): The frame hierarchy needs to change. It's
166 // problematic that we can't use the safe-cast operator to cast to
167 // the JavaScript frame type, because we may encounter arguments
168 // adaptor frames.
169 StackFrame* frame = iterator_.frame();
170 ASSERT(frame->is_java_script() || frame->is_arguments_adaptor());
171 return static_cast<JavaScriptFrame*>(frame);
172}
173
174
175template<typename Iterator>
176JavaScriptFrameIteratorTemp<Iterator>::JavaScriptFrameIteratorTemp(
177 StackFrame::Id id) {
178 while (!done()) {
179 Advance();
180 if (frame()->id() == id) return;
181 }
182}
183
184
185template<typename Iterator>
186void JavaScriptFrameIteratorTemp<Iterator>::Advance() {
187 do {
188 iterator_.Advance();
189 } while (!iterator_.done() && !iterator_.frame()->is_java_script());
190}
191
192
193template<typename Iterator>
194void JavaScriptFrameIteratorTemp<Iterator>::AdvanceToArgumentsFrame() {
195 if (!frame()->has_adapted_arguments()) return;
196 iterator_.Advance();
197 ASSERT(iterator_.frame()->is_arguments_adaptor());
198}
199
200
201template<typename Iterator>
202void JavaScriptFrameIteratorTemp<Iterator>::Reset() {
203 iterator_.Reset();
204 if (!done()) Advance();
205}
206
207
208} } // namespace v8::internal
209
210#endif // V8_FRAMES_INL_H_