]> git.saurik.com Git - apple/javascriptcore.git/blame - interpreter/CallFrame.cpp
JavaScriptCore-7600.1.4.17.5.tar.gz
[apple/javascriptcore.git] / interpreter / CallFrame.cpp
CommitLineData
b37bf2e1 1/*
81345200 2 * Copyright (C) 2008, 2013, 2014 Apple Inc. All Rights Reserved.
b37bf2e1
A
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
9dae56ea 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
b37bf2e1
A
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
9dae56ea 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
b37bf2e1
A
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
9dae56ea
A
26#include "config.h"
27#include "CallFrame.h"
b37bf2e1 28
81345200 29#include "CallFrameInlines.h"
9dae56ea 30#include "CodeBlock.h"
ba379fdc 31#include "Interpreter.h"
81345200
A
32#include "JSActivation.h"
33#include "JSCInlines.h"
34#include "VMEntryScope.h"
35#include <wtf/StringPrintStream.h>
b37bf2e1 36
9dae56ea 37namespace JSC {
b37bf2e1 38
ba379fdc 39#ifndef NDEBUG
93a37866 40JSStack* CallFrame::stack()
14957cd0 41{
93a37866 42 return &interpreter()->stack();
14957cd0
A
43}
44
ba379fdc
A
45#endif
46
6fe7ccc8 47#if USE(JSVALUE32_64)
81345200 48unsigned CallFrame::locationAsBytecodeOffset() const
6fe7ccc8
A
49{
50 ASSERT(codeBlock());
81345200 51 ASSERT(hasLocationAsBytecodeOffset());
6fe7ccc8
A
52 return currentVPC() - codeBlock()->instructions().begin();
53}
54
81345200 55void CallFrame::setLocationAsBytecodeOffset(unsigned offset)
6fe7ccc8
A
56{
57 ASSERT(codeBlock());
58 setCurrentVPC(codeBlock()->instructions().begin() + offset);
81345200 59 ASSERT(hasLocationAsBytecodeOffset());
6fe7ccc8
A
60}
61#else
62Instruction* CallFrame::currentVPC() const
63{
81345200 64 return codeBlock()->instructions().begin() + locationAsBytecodeOffset();
6fe7ccc8
A
65}
66void CallFrame::setCurrentVPC(Instruction* vpc)
67{
81345200 68 setLocationAsBytecodeOffset(vpc - codeBlock()->instructions().begin());
6fe7ccc8
A
69}
70#endif
71
72#if ENABLE(DFG_JIT)
81345200 73unsigned CallFrame::bytecodeOffsetFromCodeOriginIndex()
6fe7ccc8 74{
81345200
A
75 ASSERT(hasLocationAsCodeOriginIndex());
76 CodeBlock* codeBlock = this->codeBlock();
77 ASSERT(codeBlock);
6fe7ccc8 78
6fe7ccc8 79 CodeOrigin codeOrigin;
81345200
A
80 unsigned index = locationAsCodeOriginIndex();
81 ASSERT(codeBlock->canGetCodeOrigin(index));
82 codeOrigin = codeBlock->codeOrigin(index);
6fe7ccc8 83
6fe7ccc8 84 for (InlineCallFrame* inlineCallFrame = codeOrigin.inlineCallFrame; inlineCallFrame;) {
81345200
A
85 if (inlineCallFrame->baselineCodeBlock() == codeBlock)
86 return codeOrigin.bytecodeIndex;
87
88 codeOrigin = inlineCallFrame->caller;
89 inlineCallFrame = codeOrigin.inlineCallFrame;
6fe7ccc8 90 }
81345200 91 return codeOrigin.bytecodeIndex;
6fe7ccc8 92}
81345200
A
93
94#endif // ENABLE(DFG_JIT)
95
96unsigned CallFrame::bytecodeOffset()
6fe7ccc8 97{
93a37866 98 if (!codeBlock())
6fe7ccc8 99 return 0;
81345200
A
100#if ENABLE(DFG_JIT)
101 if (hasLocationAsCodeOriginIndex())
102 return bytecodeOffsetFromCodeOriginIndex();
103#endif
104 return locationAsBytecodeOffset();
6fe7ccc8 105}
93a37866 106
81345200 107CodeOrigin CallFrame::codeOrigin()
93a37866 108{
81345200
A
109 if (!codeBlock())
110 return CodeOrigin(0);
111#if ENABLE(DFG_JIT)
112 if (hasLocationAsCodeOriginIndex()) {
113 unsigned index = locationAsCodeOriginIndex();
114 ASSERT(codeBlock()->canGetCodeOrigin(index));
115 return codeBlock()->codeOrigin(index);
116 }
6fe7ccc8 117#endif
81345200
A
118 return CodeOrigin(locationAsBytecodeOffset());
119}
6fe7ccc8 120
81345200 121Register* CallFrame::topOfFrameInternal()
6fe7ccc8
A
122{
123 CodeBlock* codeBlock = this->codeBlock();
124 ASSERT(codeBlock);
81345200
A
125 return registers() + codeBlock->stackPointerOffset();
126}
127
128JSGlobalObject* CallFrame::vmEntryGlobalObject()
129{
130 if (this == lexicalGlobalObject()->globalExec())
131 return lexicalGlobalObject();
132
133 // For any ExecState that's not a globalExec, the
134 // dynamic global object must be set since code is running
135 ASSERT(vm().entryScope);
136 return vm().entryScope->globalObject();
137}
138
139JSActivation* CallFrame::activation() const
140{
141 CodeBlock* codeBlock = this->codeBlock();
142 RELEASE_ASSERT(codeBlock->needsActivation());
143 VirtualRegister activationRegister = codeBlock->activationRegister();
144 return registers()[activationRegister.offset()].Register::activation();
145}
146
147void CallFrame::setActivation(JSActivation* activation)
148{
149 CodeBlock* codeBlock = this->codeBlock();
150 RELEASE_ASSERT(codeBlock->needsActivation());
151 VirtualRegister activationRegister = codeBlock->activationRegister();
152 registers()[activationRegister.offset()] = activation;
153}
154
155void CallFrame::dump(PrintStream& out)
156{
157 if (CodeBlock* codeBlock = this->codeBlock()) {
158 out.print(codeBlock->inferredName(), "#", codeBlock->hashAsStringIfPossible(), " [", codeBlock->jitType(), "]");
159
160 out.print("(");
161 thisValue().dumpForBacktrace(out);
162
163 for (size_t i = 0; i < argumentCount(); ++i) {
164 out.print(", ");
165 JSValue value = argument(i);
166 value.dumpForBacktrace(out);
167 }
168
169 out.print(")");
170
171 return;
172 }
173
174 out.print(returnPC());
6fe7ccc8
A
175}
176
81345200
A
177const char* CallFrame::describeFrame()
178{
179 const size_t bufferSize = 200;
180 static char buffer[bufferSize + 1];
181
182 WTF::StringPrintStream stringStream;
183
184 dump(stringStream);
185
186 strncpy(buffer, stringStream.toCString().data(), bufferSize);
187 buffer[bufferSize] = '\0';
188
189 return buffer;
9dae56ea 190}
81345200
A
191
192} // namespace JSC