• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2009 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 #include "v8.h"
29 
30 #include "frames-inl.h"
31 
32 namespace v8 {
33 namespace internal {
34 
35 
ComputeType(State * state)36 StackFrame::Type StackFrame::ComputeType(State* state) {
37   ASSERT(state->fp != NULL);
38   if (StandardFrame::IsArgumentsAdaptorFrame(state->fp)) {
39     return ARGUMENTS_ADAPTOR;
40   }
41   // The marker and function offsets overlap. If the marker isn't a
42   // smi then the frame is a JavaScript frame -- and the marker is
43   // really the function.
44   const int offset = StandardFrameConstants::kMarkerOffset;
45   Object* marker = Memory::Object_at(state->fp + offset);
46   if (!marker->IsSmi()) return JAVA_SCRIPT;
47   return static_cast<StackFrame::Type>(Smi::cast(marker)->value());
48 }
49 
50 
GetStateForFramePointer(Address fp,State * state)51 StackFrame::Type ExitFrame::GetStateForFramePointer(Address fp, State* state) {
52   if (fp == 0) return NONE;
53   // Compute the stack pointer.
54   Address sp = Memory::Address_at(fp + ExitFrameConstants::kSPOffset);
55   // Fill in the state.
56   state->fp = fp;
57   state->sp = sp;
58   state->pc_address = reinterpret_cast<Address*>(sp - 1 * kPointerSize);
59   // Determine frame type.
60   return EXIT;
61 }
62 
GetProvidedParametersCount() const63 int JavaScriptFrame::GetProvidedParametersCount() const {
64   return ComputeParametersCount();
65 }
66 
67 
Iterate(ObjectVisitor * v) const68 void ExitFrame::Iterate(ObjectVisitor* v) const {
69   v->VisitPointer(&code_slot());
70   // The arguments are traversed as part of the expression stack of
71   // the calling frame.
72 }
73 
GetCallerStackPointer() const74 byte* InternalFrame::GetCallerStackPointer() const {
75   // Internal frames have no arguments. The stack pointer of the
76   // caller is at a fixed offset from the frame pointer.
77   return fp() + StandardFrameConstants::kCallerSPOffset;
78 }
79 
GetCallerStackPointer() const80 byte* JavaScriptFrame::GetCallerStackPointer() const {
81   int arguments;
82   if (Heap::gc_state() != Heap::NOT_IN_GC || disable_heap_access_) {
83     // The arguments for cooked frames are traversed as if they were
84     // expression stack elements of the calling frame. The reason for
85     // this rather strange decision is that we cannot access the
86     // function during mark-compact GCs when the stack is cooked.
87     // In fact accessing heap objects (like function->shared() below)
88     // at all during GC is problematic.
89     arguments = 0;
90   } else {
91     // Compute the number of arguments by getting the number of formal
92     // parameters of the function. We must remember to take the
93     // receiver into account (+1).
94     JSFunction* function = JSFunction::cast(this->function());
95     arguments = function->shared()->formal_parameter_count() + 1;
96   }
97   const int offset = StandardFrameConstants::kCallerSPOffset;
98   return fp() + offset + (arguments * kPointerSize);
99 }
100 
101 
GetCallerStackPointer() const102 byte* ArgumentsAdaptorFrame::GetCallerStackPointer() const {
103   const int arguments = Smi::cast(GetExpression(0))->value();
104   const int offset = StandardFrameConstants::kCallerSPOffset;
105   return fp() + offset + (arguments + 1) * kPointerSize;
106 }
107 
108 
109 } }  // namespace v8::internal
110