blob: 28be4306613ad1aa6ffc1c4064459587974d0a93 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// 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"
ager@chromium.org9085a012009-05-11 19:22:57 +000032
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
ager@chromium.org3a37e9b2009-04-27 09:26:21 +000038#include "arm/frames-arm.h"
ager@chromium.org5ec48922009-05-05 07:25:34 +000039#endif
40
kasperl@chromium.org71affb52009-05-26 05:44:31 +000041namespace v8 {
42namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000043
44
45inline Address StackHandler::address() const {
46 // NOTE: There's an obvious problem with the address of the NULL
47 // stack handler. Right now, it benefits us that the subtraction
48 // leads to a very high address (above everything else on the
49 // stack), but maybe we should stop relying on it?
50 const int displacement = StackHandlerConstants::kAddressDisplacement;
51 Address address = reinterpret_cast<Address>(const_cast<StackHandler*>(this));
52 return address + displacement;
53}
54
55
56inline StackHandler* StackHandler::next() const {
57 const int offset = StackHandlerConstants::kNextOffset;
58 return FromAddress(Memory::Address_at(address() + offset));
59}
60
61
62inline bool StackHandler::includes(Address address) const {
63 Address start = this->address();
64 Address end = start + StackHandlerConstants::kSize;
65 return start <= address && address <= end;
66}
67
68
69inline void StackHandler::Iterate(ObjectVisitor* v) const {
70 // Stack handlers do not contain any pointers that need to be
71 // traversed. The only field that have to worry about is the code
72 // field which is unused and should always be uninitialized.
73#ifdef DEBUG
74 const int offset = StackHandlerConstants::kCodeOffset;
75 Object* code = Memory::Object_at(address() + offset);
76 ASSERT(Smi::cast(code)->value() == StackHandler::kCodeNotPresent);
77#endif
78}
79
80
81inline StackHandler* StackHandler::FromAddress(Address address) {
82 return reinterpret_cast<StackHandler*>(address);
83}
84
85
86inline StackHandler::State StackHandler::state() const {
87 const int offset = StackHandlerConstants::kStateOffset;
88 return static_cast<State>(Memory::int_at(address() + offset));
89}
90
91
92inline Address StackHandler::pc() const {
93 const int offset = StackHandlerConstants::kPCOffset;
94 return Memory::Address_at(address() + offset);
95}
96
97
98inline void StackHandler::set_pc(Address value) {
99 const int offset = StackHandlerConstants::kPCOffset;
100 Memory::Address_at(address() + offset) = value;
101}
102
103
104inline StackHandler* StackFrame::top_handler() const {
105 return iterator_->handler();
106}
107
108
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000109inline Object* StandardFrame::GetExpression(int index) const {
110 return Memory::Object_at(GetExpressionAddress(index));
111}
112
113
114inline void StandardFrame::SetExpression(int index, Object* value) {
115 Memory::Object_at(GetExpressionAddress(index)) = value;
116}
117
118
119inline Object* StandardFrame::context() const {
120 const int offset = StandardFrameConstants::kContextOffset;
121 return Memory::Object_at(fp() + offset);
122}
123
124
125inline Address StandardFrame::caller_sp() const {
126 return pp();
127}
128
129
130inline Address StandardFrame::caller_fp() const {
131 return Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset);
132}
133
134
135inline Address StandardFrame::caller_pc() const {
136 return Memory::Address_at(ComputePCAddress(fp()));
137}
138
139
140inline Address StandardFrame::ComputePCAddress(Address fp) {
141 return fp + StandardFrameConstants::kCallerPCOffset;
142}
143
144
145inline bool StandardFrame::IsArgumentsAdaptorFrame(Address fp) {
146 int context = Memory::int_at(fp + StandardFrameConstants::kContextOffset);
147 return context == ArgumentsAdaptorFrame::SENTINEL;
148}
149
150
ager@chromium.org7c537e22008-10-16 08:43:32 +0000151inline bool StandardFrame::IsConstructFrame(Address fp) {
152 Object* marker =
153 Memory::Object_at(fp + StandardFrameConstants::kMarkerOffset);
154 return marker == Smi::FromInt(CONSTRUCT);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000155}
156
157
158inline Object* JavaScriptFrame::receiver() const {
159 const int offset = JavaScriptFrameConstants::kReceiverOffset;
160 return Memory::Object_at(pp() + offset);
161}
162
163
164inline void JavaScriptFrame::set_receiver(Object* value) {
165 const int offset = JavaScriptFrameConstants::kReceiverOffset;
166 Memory::Object_at(pp() + offset) = value;
167}
168
169
170inline bool JavaScriptFrame::has_adapted_arguments() const {
171 return IsArgumentsAdaptorFrame(caller_fp());
172}
173
174
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000175inline Object* JavaScriptFrame::function() const {
176 Object* result = function_slot_object();
177 ASSERT(result->IsJSFunction());
178 return result;
179}
180
181
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000182template<typename Iterator>
183inline JavaScriptFrame* JavaScriptFrameIteratorTemp<Iterator>::frame() const {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000184 // TODO(1233797): The frame hierarchy needs to change. It's
185 // problematic that we can't use the safe-cast operator to cast to
186 // the JavaScript frame type, because we may encounter arguments
187 // adaptor frames.
188 StackFrame* frame = iterator_.frame();
189 ASSERT(frame->is_java_script() || frame->is_arguments_adaptor());
190 return static_cast<JavaScriptFrame*>(frame);
191}
192
193
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000194template<typename Iterator>
195JavaScriptFrameIteratorTemp<Iterator>::JavaScriptFrameIteratorTemp(
196 StackFrame::Id id) {
197 while (!done()) {
198 Advance();
199 if (frame()->id() == id) return;
200 }
201}
202
203
204template<typename Iterator>
205void JavaScriptFrameIteratorTemp<Iterator>::Advance() {
206 do {
207 iterator_.Advance();
208 } while (!iterator_.done() && !iterator_.frame()->is_java_script());
209}
210
211
212template<typename Iterator>
213void JavaScriptFrameIteratorTemp<Iterator>::AdvanceToArgumentsFrame() {
214 if (!frame()->has_adapted_arguments()) return;
215 iterator_.Advance();
216 ASSERT(iterator_.frame()->is_arguments_adaptor());
217}
218
219
220template<typename Iterator>
221void JavaScriptFrameIteratorTemp<Iterator>::Reset() {
222 iterator_.Reset();
223 if (!done()) Advance();
224}
225
226
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000227} } // namespace v8::internal
228
229#endif // V8_FRAMES_INL_H_