[JAEGER] Enabled method JIT backend.

This commit is contained in:
David Anderson
2010-05-22 17:41:21 -07:00
parent 27fbe16186
commit 0d01073487
5 changed files with 352 additions and 10 deletions

View File

@@ -0,0 +1,211 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=4 sw=4 et tw=99:
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released
* May 28, 2008.
*
* The Initial Developer of the Original Code is
* Brendan Eich <brendan@mozilla.org>
*
* Contributor(s):
* David Anderson <danderson@mozilla.com>
* David Mandelin <dmandelin@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "MethodJIT.h"
#include "Compiler.h"
using namespace js;
using namespace js::mjit;
#if defined(JS_METHODJIT_SPEW)
static const char *OpcodeNames[] = {
# define OPDEF(op,val,name,token,length,nuses,ndefs,prec,format) #name,
# include "jsopcode.tbl"
# undef OPDEF
};
#endif
mjit::Compiler::Compiler(JSContext *cx, JSScript *script, JSObject *scopeChain)
: cx(cx), script(script), scopeChain(scopeChain), globalObj(scopeChain->getGlobal()),
analysis(cx, script), jumpMap(NULL)
{
}
#define CHECK_STATUS(expr) \
JS_BEGIN_MACRO \
CompileStatus status_ = (expr); \
if (status_ != Compile_Okay) \
return status_; \
JS_END_MACRO
CompileStatus
mjit::Compiler::Compile()
{
JS_ASSERT(!script->ncode);
JaegerSpew(JSpew_Scripts, "compiling script (file \"%s\") (line \"%d\") (length \"%d\")\n",
script->filename, script->lineno, script->length);
/* Perform bytecode analysis. */
if (!analysis.analyze()) {
if (analysis.OOM())
return Compile_Error;
JaegerSpew(JSpew_Abort, "couldn't analyze bytecode; probably switchX or OOM\n");
return Compile_Abort;
}
jumpMap = (Label *)cx->malloc(sizeof(Label) * script->length);
if (!jumpMap)
return Compile_Error;
#ifdef DEBUG
for (uint32 i = 0; i < script->length; i++)
jumpMap[i] = Label();
#endif
#ifdef JS_TRACER
if (script->tracePoints) {
script->trees = (TraceTreeCache*)cx->malloc(script->tracePoints * sizeof(TraceTreeCache));
if (!script->trees)
return Compile_Abort;
memset(script->trees, 0, script->tracePoints * sizeof(TraceTreeCache));
}
#endif
Profiler prof;
prof.start();
CHECK_STATUS(generatePrologue());
CHECK_STATUS(generateMethod());
CHECK_STATUS(generateEpilogue());
CHECK_STATUS(finishThisUp());
#ifdef JS_METHODJIT_SPEW
prof.stop();
JaegerSpew(JSpew_Prof, "compilation took %d us\n", prof.time_us());
#endif
JaegerSpew(JSpew_Scripts, "successfully compiled (code \"%p\") (size \"%ld\")\n",
(void*)script->ncode, 0); //cr.m_size);
return Compile_Abort;
}
#undef CHECK_STATUS
mjit::Compiler::~Compiler()
{
cx->free(jumpMap);
}
CompileStatus
mjit::Compiler::generatePrologue()
{
#ifdef JS_CPU_ARM
/*
* Unlike x86/x64, the return address is not pushed on the stack. To
* compensate, we store the LR back into the stack on entry. This means
* it's really done twice when called via the trampoline, but it's only
* one instruction so probably not a big deal.
*
* The trampoline version goes through a veneer to make sure we can enter
* scripts at any arbitrary point - i.e. we can't rely on this being here,
* except for inline calls.
*/
masm.storePtr(ARMRegisters::lr, FrameAddress(offsetof(VMFrame, scriptedReturn)));
#endif
return Compile_Okay;
}
CompileStatus
mjit::Compiler::generateMethod()
{
PC = script->code;
for (;;) {
JSOp op = JSOp(*PC);
OpcodeStatus &opinfo = analysis[PC];
if (opinfo.nincoming) {
opinfo.safePoint = true;
}
if (!opinfo.visited) {
if (op == JSOP_STOP)
break;
if (js_CodeSpec[op].length != -1)
PC += js_CodeSpec[op].length;
else
PC += js_GetVariableBytecodeLength(PC);
continue;
}
#ifdef DEBUG
if (IsJaegerSpewChannelActive(JSpew_JSOps)) {
JaegerSpew(JSpew_JSOps, " %2d ", 0); //cg.getStackDepth());
js_Disassemble1(cx, script, PC, PC - script->code,
JS_TRUE, stdout);
}
#endif
switch (op) {
default:
/* Sorry, this opcode isn't implemented yet. */
#ifdef JS_METHODJIT_SPEW
JaegerSpew(JSpew_Abort, "opcode %s not handled yet\n", OpcodeNames[op]);
#endif
return Compile_Abort;
}
}
return Compile_Okay;
}
CompileStatus
mjit::Compiler::generateEpilogue()
{
return Compile_Okay;
}
CompileStatus
mjit::Compiler::finishThisUp()
{
return Compile_Okay;
}
CompileStatus
mjit::TryCompile(JSContext *cx, JSScript *script, JSObject *scopeChain)
{
Compiler cc(cx, script, scopeChain);
JS_ASSERT(!script->ncode);
return cc.Compile();
}