christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 Google Inc. 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 | #include "assembler-arm-inl.h" |
| 32 | |
| 33 | |
| 34 | namespace v8 { namespace internal { |
| 35 | |
| 36 | |
| 37 | StackFrame::Type StackFrame::ComputeType(State* state) { |
| 38 | ASSERT(state->fp != NULL); |
| 39 | if (state->pp == NULL) { |
| 40 | if (Memory::Address_at(state->fp + |
| 41 | EntryFrameConstants::kConstructMarkOffset) != 0) { |
| 42 | return ENTRY_CONSTRUCT; |
| 43 | } else { |
| 44 | return ENTRY; |
| 45 | } |
| 46 | } else if (StandardFrame::IsArgumentsAdaptorFrame(state->fp)) { |
| 47 | return ARGUMENTS_ADAPTOR; |
| 48 | } else if ( |
| 49 | Memory::Object_at(state->fp + |
| 50 | StandardFrameConstants::kFunctionOffset)->IsSmi()) { |
| 51 | return INTERNAL; |
| 52 | } else { |
| 53 | return JAVA_SCRIPT; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | |
| 58 | StackFrame::Type ExitFrame::GetStateForFramePointer(Address fp, State* state) { |
| 59 | if (fp == 0) return NONE; |
| 60 | // Compute frame type and stack pointer. |
| 61 | Address sp = fp + ExitFrameConstants::kSPDisplacement; |
| 62 | Type type; |
| 63 | if (Memory::Address_at(fp + ExitFrameConstants::kDebugMarkOffset) != 0) { |
| 64 | type = EXIT_DEBUG; |
| 65 | sp -= kNumJSCallerSaved * kPointerSize; |
| 66 | } else { |
| 67 | type = EXIT; |
| 68 | } |
| 69 | // Fill in the state. |
| 70 | state->sp = sp; |
| 71 | state->fp = fp; |
| 72 | state->pp = fp + ExitFrameConstants::kPPDisplacement; |
| 73 | state->pc_address = reinterpret_cast<Address*>(sp - 1 * kPointerSize); |
| 74 | return type; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | void ExitFrame::Iterate(ObjectVisitor* v) const { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame^] | 79 | // Do nothing |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | |
| 83 | int JavaScriptFrame::GetProvidedParametersCount() const { |
| 84 | const int offset = JavaScriptFrameConstants::kArgsLengthOffset; |
| 85 | int result = Memory::int_at(fp() + offset); |
| 86 | // We never remove extra parameters provided on the stack; we only |
| 87 | // fill in undefined values for parameters not provided. |
| 88 | ASSERT(0 <= result && result <= ComputeParametersCount()); |
| 89 | return result; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | Address JavaScriptFrame::GetCallerStackPointer() const { |
| 94 | return state_.pp; |
| 95 | } |
| 96 | |
| 97 | |
| 98 | Address ArgumentsAdaptorFrame::GetCallerStackPointer() const { |
| 99 | // Argument adaptor frames aren't used on ARM (yet). |
| 100 | UNIMPLEMENTED(); |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | Address InternalFrame::GetCallerStackPointer() const { |
| 106 | return state_.pp; |
| 107 | } |
| 108 | |
| 109 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 110 | Code* JavaScriptFrame::FindCode() const { |
| 111 | const int offset = StandardFrameConstants::kCodeOffset; |
| 112 | Object* code = Memory::Object_at(fp() + offset); |
| 113 | if (code == NULL) { |
| 114 | // The code object isn't set; find it and set it. |
| 115 | code = Heap::FindCodeObject(pc()); |
| 116 | ASSERT(!code->IsFailure()); |
| 117 | Memory::Object_at(fp() + offset) = code; |
| 118 | } |
| 119 | ASSERT(code != NULL); |
| 120 | return Code::cast(code); |
| 121 | } |
| 122 | |
| 123 | |
| 124 | } } // namespace v8::internal |