1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
/*
* Copyright (C) 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef JITStubCall_h
#define JITStubCall_h
#include "MacroAssemblerCodeRef.h"
#if ENABLE(JIT)
namespace JSC {
class JITStubCall {
public:
JITStubCall(JIT* jit, JSObject* (JIT_STUB *stub)(STUB_ARGS_DECLARATION))
: m_jit(jit)
, m_stub(stub)
#if USE(JSVALUE32_64) || !ASSERT_DISABLED
, m_returnType(Cell)
#endif
, m_stackIndex(JITSTACKFRAME_ARGS_INDEX)
{
}
JITStubCall(JIT* jit, JSPropertyNameIterator* (JIT_STUB *stub)(STUB_ARGS_DECLARATION))
: m_jit(jit)
, m_stub(stub)
#if USE(JSVALUE32_64) || !ASSERT_DISABLED
, m_returnType(Cell)
#endif
, m_stackIndex(JITSTACKFRAME_ARGS_INDEX)
{
}
JITStubCall(JIT* jit, void* (JIT_STUB *stub)(STUB_ARGS_DECLARATION))
: m_jit(jit)
, m_stub(stub)
#if USE(JSVALUE32_64) || !ASSERT_DISABLED
, m_returnType(VoidPtr)
#endif
, m_stackIndex(JITSTACKFRAME_ARGS_INDEX)
{
}
JITStubCall(JIT* jit, int (JIT_STUB *stub)(STUB_ARGS_DECLARATION))
: m_jit(jit)
, m_stub(stub)
#if USE(JSVALUE32_64) || !ASSERT_DISABLED
, m_returnType(Int)
#endif
, m_stackIndex(JITSTACKFRAME_ARGS_INDEX)
{
}
JITStubCall(JIT* jit, bool (JIT_STUB *stub)(STUB_ARGS_DECLARATION))
: m_jit(jit)
, m_stub(stub)
#if USE(JSVALUE32_64) || !ASSERT_DISABLED
, m_returnType(Int)
#endif
, m_stackIndex(JITSTACKFRAME_ARGS_INDEX)
{
}
JITStubCall(JIT* jit, void (JIT_STUB *stub)(STUB_ARGS_DECLARATION))
: m_jit(jit)
, m_stub(stub)
#if USE(JSVALUE32_64) || !ASSERT_DISABLED
, m_returnType(Void)
#endif
, m_stackIndex(JITSTACKFRAME_ARGS_INDEX)
{
}
JITStubCall(JIT* jit, EncodedJSValue (JIT_STUB *stub)(STUB_ARGS_DECLARATION))
: m_jit(jit)
, m_stub(stub)
#if USE(JSVALUE32_64) || !ASSERT_DISABLED
, m_returnType(Value)
#endif
, m_stackIndex(JITSTACKFRAME_ARGS_INDEX)
{
}
// Arguments are added first to last.
void skipArgument()
{
m_stackIndex += stackIndexStep;
}
void addArgument(JIT::TrustedImm32 argument)
{
m_jit->poke(argument, m_stackIndex);
m_stackIndex += stackIndexStep;
}
void addArgument(JIT::Imm32 argument)
{
m_jit->poke(argument, m_stackIndex);
m_stackIndex += stackIndexStep;
}
void addArgument(JIT::TrustedImmPtr argument)
{
m_jit->poke(argument, m_stackIndex);
m_stackIndex += stackIndexStep;
}
void addArgument(JIT::ImmPtr argument)
{
m_jit->poke(argument, m_stackIndex);
m_stackIndex += stackIndexStep;
}
void addArgument(JIT::RegisterID argument)
{
#if USE(JSVALUE32_64)
m_jit->poke(argument, m_stackIndex);
#else
m_jit->poke64(argument, m_stackIndex);
#endif
m_stackIndex += stackIndexStep;
}
#if USE(JSVALUE32_64)
void addArgument(const JSValue& value)
{
m_jit->poke(JIT::Imm32(value.payload()), m_stackIndex);
m_jit->poke(JIT::Imm32(value.tag()), m_stackIndex + 1);
m_stackIndex += stackIndexStep;
}
#else
void addArgument(JIT::TrustedImm64 argument)
{
m_jit->poke(argument, m_stackIndex);
m_stackIndex += stackIndexStep;
}
void addArgument(JIT::Imm64 argument)
{
m_jit->poke(argument, m_stackIndex);
m_stackIndex += stackIndexStep;
}
#endif
void addArgument(JIT::RegisterID tag, JIT::RegisterID payload)
{
m_jit->poke(payload, m_stackIndex);
m_jit->poke(tag, m_stackIndex + 1);
m_stackIndex += stackIndexStep;
}
#if USE(JSVALUE32_64)
void addArgument(unsigned srcVirtualRegister)
{
if (m_jit->m_codeBlock->isConstantRegisterIndex(srcVirtualRegister)) {
addArgument(m_jit->getConstantOperand(srcVirtualRegister));
return;
}
m_jit->emitLoad(srcVirtualRegister, JIT::regT1, JIT::regT0);
addArgument(JIT::regT1, JIT::regT0);
}
void getArgument(size_t argumentNumber, JIT::RegisterID tag, JIT::RegisterID payload)
{
size_t stackIndex = JITSTACKFRAME_ARGS_INDEX + (argumentNumber * stackIndexStep);
m_jit->peek(payload, stackIndex);
m_jit->peek(tag, stackIndex + 1);
}
#else
void addArgument(unsigned src, JIT::RegisterID scratchRegister) // src is a virtual register.
{
if (m_jit->m_codeBlock->isConstantRegisterIndex(src))
addArgument(JIT::Imm64(JSValue::encode(m_jit->m_codeBlock->getConstant(src))));
else {
m_jit->load64(JIT::Address(JIT::callFrameRegister, src * sizeof(Register)), scratchRegister);
addArgument(scratchRegister);
}
m_jit->killLastResultRegister();
}
#endif
JIT::Call call()
{
#if ENABLE(OPCODE_SAMPLING)
if (m_jit->m_bytecodeOffset != (unsigned)-1)
m_jit->sampleInstruction(m_jit->m_codeBlock->instructions().begin() + m_jit->m_bytecodeOffset, true);
#endif
m_jit->restoreArgumentReference();
m_jit->updateTopCallFrame();
JIT::Call call = m_jit->call();
m_jit->m_calls.append(CallRecord(call, m_jit->m_bytecodeOffset, m_stub.value()));
#if ENABLE(OPCODE_SAMPLING)
if (m_jit->m_bytecodeOffset != (unsigned)-1)
m_jit->sampleInstruction(m_jit->m_codeBlock->instructions().begin() + m_jit->m_bytecodeOffset, false);
#endif
#if USE(JSVALUE32_64)
m_jit->unmap();
#else
m_jit->killLastResultRegister();
#endif
return call;
}
#if USE(JSVALUE32_64)
JIT::Call call(unsigned dst) // dst is a virtual register.
{
ASSERT(m_returnType == Value || m_returnType == Cell);
JIT::Call call = this->call();
if (m_returnType == Value)
m_jit->emitStore(dst, JIT::regT1, JIT::regT0);
else
m_jit->emitStoreCell(dst, JIT::returnValueRegister);
return call;
}
JIT::Call callWithValueProfiling(unsigned dst)
{
ASSERT(m_returnType == Value || m_returnType == Cell);
JIT::Call call = this->call();
ASSERT(JIT::returnValueRegister == JIT::regT0);
if (m_returnType == Cell)
m_jit->move(JIT::TrustedImm32(JSValue::CellTag), JIT::regT1);
m_jit->emitValueProfilingSite();
if (m_returnType == Value)
m_jit->emitStore(dst, JIT::regT1, JIT::regT0);
else
m_jit->emitStoreCell(dst, JIT::returnValueRegister);
return call;
}
#else
JIT::Call call(unsigned dst) // dst is a virtual register.
{
ASSERT(m_returnType == Value || m_returnType == Cell);
JIT::Call call = this->call();
m_jit->emitPutVirtualRegister(dst);
return call;
}
JIT::Call callWithValueProfiling(unsigned dst)
{
ASSERT(m_returnType == Value || m_returnType == Cell);
JIT::Call call = this->call();
ASSERT(JIT::returnValueRegister == JIT::regT0);
m_jit->emitValueProfilingSite();
m_jit->emitPutVirtualRegister(dst);
return call;
}
#endif
JIT::Call call(JIT::RegisterID dst) // dst is a machine register.
{
#if USE(JSVALUE32_64) || !ASSERT_DISABLED
ASSERT(m_returnType == Value || m_returnType == VoidPtr || m_returnType == Int || m_returnType == Cell);
#endif
JIT::Call call = this->call();
if (dst != JIT::returnValueRegister)
m_jit->move(JIT::returnValueRegister, dst);
return call;
}
private:
static const size_t stackIndexStep = sizeof(EncodedJSValue) == 2 * sizeof(void*) ? 2 : 1;
JIT* m_jit;
FunctionPtr m_stub;
#if USE(JSVALUE32_64) || !ASSERT_DISABLED
enum { Void, VoidPtr, Int, Value, Cell } m_returnType;
#endif
size_t m_stackIndex;
};
}
#endif // ENABLE(JIT)
#endif // JITStubCall_h
|