blob: b34a0abb15c6d95cdb21a12baffa608af97c33e6 [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.orga74f0da2008-12-03 16:05:52 +000032#ifdef ARM
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000033#include "frames-arm.h"
34#else
35#include "frames-ia32.h"
36#endif
37
38
39namespace v8 { namespace internal {
40
41
42inline Address StackHandler::address() const {
43 // NOTE: There's an obvious problem with the address of the NULL
44 // stack handler. Right now, it benefits us that the subtraction
45 // leads to a very high address (above everything else on the
46 // stack), but maybe we should stop relying on it?
47 const int displacement = StackHandlerConstants::kAddressDisplacement;
48 Address address = reinterpret_cast<Address>(const_cast<StackHandler*>(this));
49 return address + displacement;
50}
51
52
53inline StackHandler* StackHandler::next() const {
54 const int offset = StackHandlerConstants::kNextOffset;
55 return FromAddress(Memory::Address_at(address() + offset));
56}
57
58
59inline bool StackHandler::includes(Address address) const {
60 Address start = this->address();
61 Address end = start + StackHandlerConstants::kSize;
62 return start <= address && address <= end;
63}
64
65
66inline void StackHandler::Iterate(ObjectVisitor* v) const {
67 // Stack handlers do not contain any pointers that need to be
68 // traversed. The only field that have to worry about is the code
69 // field which is unused and should always be uninitialized.
70#ifdef DEBUG
71 const int offset = StackHandlerConstants::kCodeOffset;
72 Object* code = Memory::Object_at(address() + offset);
73 ASSERT(Smi::cast(code)->value() == StackHandler::kCodeNotPresent);
74#endif
75}
76
77
78inline StackHandler* StackHandler::FromAddress(Address address) {
79 return reinterpret_cast<StackHandler*>(address);
80}
81
82
83inline StackHandler::State StackHandler::state() const {
84 const int offset = StackHandlerConstants::kStateOffset;
85 return static_cast<State>(Memory::int_at(address() + offset));
86}
87
88
89inline Address StackHandler::pc() const {
90 const int offset = StackHandlerConstants::kPCOffset;
91 return Memory::Address_at(address() + offset);
92}
93
94
95inline void StackHandler::set_pc(Address value) {
96 const int offset = StackHandlerConstants::kPCOffset;
97 Memory::Address_at(address() + offset) = value;
98}
99
100
101inline StackHandler* StackFrame::top_handler() const {
102 return iterator_->handler();
103}
104
105
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000106inline Object* StandardFrame::GetExpression(int index) const {
107 return Memory::Object_at(GetExpressionAddress(index));
108}
109
110
111inline void StandardFrame::SetExpression(int index, Object* value) {
112 Memory::Object_at(GetExpressionAddress(index)) = value;
113}
114
115
116inline Object* StandardFrame::context() const {
117 const int offset = StandardFrameConstants::kContextOffset;
118 return Memory::Object_at(fp() + offset);
119}
120
121
122inline Address StandardFrame::caller_sp() const {
123 return pp();
124}
125
126
127inline Address StandardFrame::caller_fp() const {
128 return Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset);
129}
130
131
132inline Address StandardFrame::caller_pc() const {
133 return Memory::Address_at(ComputePCAddress(fp()));
134}
135
136
137inline Address StandardFrame::ComputePCAddress(Address fp) {
138 return fp + StandardFrameConstants::kCallerPCOffset;
139}
140
141
142inline bool StandardFrame::IsArgumentsAdaptorFrame(Address fp) {
143 int context = Memory::int_at(fp + StandardFrameConstants::kContextOffset);
144 return context == ArgumentsAdaptorFrame::SENTINEL;
145}
146
147
ager@chromium.org7c537e22008-10-16 08:43:32 +0000148inline bool StandardFrame::IsConstructFrame(Address fp) {
149 Object* marker =
150 Memory::Object_at(fp + StandardFrameConstants::kMarkerOffset);
151 return marker == Smi::FromInt(CONSTRUCT);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000152}
153
154
155inline Object* JavaScriptFrame::receiver() const {
156 const int offset = JavaScriptFrameConstants::kReceiverOffset;
157 return Memory::Object_at(pp() + offset);
158}
159
160
161inline void JavaScriptFrame::set_receiver(Object* value) {
162 const int offset = JavaScriptFrameConstants::kReceiverOffset;
163 Memory::Object_at(pp() + offset) = value;
164}
165
166
167inline bool JavaScriptFrame::has_adapted_arguments() const {
168 return IsArgumentsAdaptorFrame(caller_fp());
169}
170
171
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000172inline JavaScriptFrame* JavaScriptFrameIterator::frame() const {
173 // TODO(1233797): The frame hierarchy needs to change. It's
174 // problematic that we can't use the safe-cast operator to cast to
175 // the JavaScript frame type, because we may encounter arguments
176 // adaptor frames.
177 StackFrame* frame = iterator_.frame();
178 ASSERT(frame->is_java_script() || frame->is_arguments_adaptor());
179 return static_cast<JavaScriptFrame*>(frame);
180}
181
182
183} } // namespace v8::internal
184
185#endif // V8_FRAMES_INL_H_