blob: d26198ae1eccafafbe5775aa633413029c97a874 [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#include "v8.h"
29
30#include "frames-inl.h"
ager@chromium.org3a37e9b2009-04-27 09:26:21 +000031#include "arm/assembler-arm-inl.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000032
33
34namespace v8 { namespace internal {
35
36
37StackFrame::Type StackFrame::ComputeType(State* state) {
38 ASSERT(state->fp != NULL);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000039 if (StandardFrame::IsArgumentsAdaptorFrame(state->fp)) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000040 return ARGUMENTS_ADAPTOR;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000041 }
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000042 // The marker and function offsets overlap. If the marker isn't a
43 // smi then the frame is a JavaScript frame -- and the marker is
44 // really the function.
45 const int offset = StandardFrameConstants::kMarkerOffset;
46 Object* marker = Memory::Object_at(state->fp + offset);
47 if (!marker->IsSmi()) return JAVA_SCRIPT;
48 return static_cast<StackFrame::Type>(Smi::cast(marker)->value());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000049}
50
51
52StackFrame::Type ExitFrame::GetStateForFramePointer(Address fp, State* state) {
53 if (fp == 0) return NONE;
54 // Compute frame type and stack pointer.
55 Address sp = fp + ExitFrameConstants::kSPDisplacement;
56 Type type;
57 if (Memory::Address_at(fp + ExitFrameConstants::kDebugMarkOffset) != 0) {
58 type = EXIT_DEBUG;
59 sp -= kNumJSCallerSaved * kPointerSize;
60 } else {
61 type = EXIT;
62 }
63 // Fill in the state.
64 state->sp = sp;
65 state->fp = fp;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000066 state->pc_address = reinterpret_cast<Address*>(sp - 1 * kPointerSize);
67 return type;
68}
69
70
71void ExitFrame::Iterate(ObjectVisitor* v) const {
kasper.lund7276f142008-07-30 08:49:36 +000072 // Do nothing
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000073}
74
75
76int JavaScriptFrame::GetProvidedParametersCount() const {
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000077 return ComputeParametersCount();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000078}
79
80
81Address JavaScriptFrame::GetCallerStackPointer() const {
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000082 int arguments;
kasperl@chromium.orgd1e3e722009-04-14 13:38:25 +000083 if (Heap::gc_state() != Heap::NOT_IN_GC || disable_heap_access_) {
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000084 // The arguments for cooked frames are traversed as if they were
85 // expression stack elements of the calling frame. The reason for
86 // this rather strange decision is that we cannot access the
87 // function during mark-compact GCs when the stack is cooked.
88 // In fact accessing heap objects (like function->shared() below)
89 // at all during GC is problematic.
90 arguments = 0;
91 } else {
92 // Compute the number of arguments by getting the number of formal
93 // parameters of the function. We must remember to take the
94 // receiver into account (+1).
95 JSFunction* function = JSFunction::cast(this->function());
96 arguments = function->shared()->formal_parameter_count() + 1;
97 }
98 const int offset = StandardFrameConstants::kCallerSPOffset;
99 return fp() + offset + (arguments * kPointerSize);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000100}
101
102
103Address ArgumentsAdaptorFrame::GetCallerStackPointer() const {
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000104 const int arguments = Smi::cast(GetExpression(0))->value();
105 const int offset = StandardFrameConstants::kCallerSPOffset;
106 return fp() + offset + (arguments + 1) * kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000107}
108
109
110Address InternalFrame::GetCallerStackPointer() const {
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000111 // Internal frames have no arguments. The stack pointer of the
112 // caller is at a fixed offset from the frame pointer.
113 return fp() + StandardFrameConstants::kCallerSPOffset;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000114}
115
116
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000117} } // namespace v8::internal