2008-05-30 18:58:43 -07:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2008-06-03 14:48:47 -07:00
|
|
|
* vim: set ts=8 sw=4 et tw=79 ft=cpp:
|
2008-05-30 18:58:43 -07:00
|
|
|
*
|
|
|
|
* ***** 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
|
2008-06-28 09:58:15 -07:00
|
|
|
* Brendan Eich <brendan@mozilla.org>
|
2008-05-30 18:58:43 -07:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
2008-06-28 09:58:15 -07:00
|
|
|
* Andreas Gal <gal@mozilla.com>
|
2008-05-30 18:58:43 -07:00
|
|
|
*
|
|
|
|
* 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 ***** */
|
|
|
|
|
2008-05-31 15:29:54 -07:00
|
|
|
#ifndef jstracer_h___
|
|
|
|
#define jstracer_h___
|
2008-05-30 18:58:43 -07:00
|
|
|
|
|
|
|
#include "jsstddef.h"
|
|
|
|
#include "jslock.h"
|
|
|
|
|
2008-06-26 22:58:57 -07:00
|
|
|
#include "nanojit/nanojit.h"
|
2008-06-21 14:55:32 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Tracker is used to keep track of values being manipulated by the
|
|
|
|
* interpreter during trace recording.
|
|
|
|
*/
|
|
|
|
class Tracker
|
|
|
|
{
|
|
|
|
struct Page {
|
|
|
|
struct Page* next;
|
|
|
|
long base;
|
2008-06-26 20:44:23 -07:00
|
|
|
nanojit::LIns* map[0];
|
2008-06-21 14:55:32 -07:00
|
|
|
};
|
|
|
|
struct Page* pagelist;
|
|
|
|
|
2008-06-26 20:46:51 -07:00
|
|
|
long getPageBase(const void* v) const;
|
|
|
|
struct Page* findPage(const void* v) const;
|
|
|
|
struct Page* addPage(const void* v);
|
2008-06-21 14:55:32 -07:00
|
|
|
public:
|
|
|
|
Tracker();
|
|
|
|
~Tracker();
|
|
|
|
|
2008-06-26 20:44:23 -07:00
|
|
|
nanojit::LIns* get(const void* v) const;
|
|
|
|
void set(const void* v, nanojit::LIns* ins);
|
|
|
|
void clear();
|
2008-06-21 14:55:32 -07:00
|
|
|
};
|
|
|
|
|
2008-06-26 22:19:11 -07:00
|
|
|
/*
|
|
|
|
* FrameStack keeps track of stack frames during recording as we enter and
|
|
|
|
* leave methods.
|
|
|
|
*/
|
|
|
|
class FrameStack
|
|
|
|
{
|
|
|
|
JSStackFrame* stack[16];
|
|
|
|
uint32 depth;
|
|
|
|
public:
|
|
|
|
FrameStack(JSStackFrame& entryFrame);
|
|
|
|
~FrameStack();
|
|
|
|
|
|
|
|
bool enter(JSStackFrame& frame);
|
|
|
|
void leave();
|
|
|
|
|
|
|
|
JSStackFrame* findFrame(void* p) const;
|
|
|
|
bool contains(void* p) const;
|
2008-06-27 16:24:17 -07:00
|
|
|
uint32_t nativeFrameOffset(void* p) const;
|
|
|
|
uint32_t nativeFrameSize() const;
|
2008-06-28 11:00:18 -07:00
|
|
|
|
|
|
|
uint32 calldepth() const { return depth; }
|
2008-06-26 22:19:11 -07:00
|
|
|
};
|
|
|
|
|
2008-06-26 20:49:04 -07:00
|
|
|
class TraceRecorder {
|
2008-06-26 22:41:10 -07:00
|
|
|
Tracker tracker;
|
2008-06-26 22:19:11 -07:00
|
|
|
FrameStack frameStack;
|
2008-06-26 20:37:28 -07:00
|
|
|
struct JSFrameRegs entryState;
|
|
|
|
nanojit::Fragment* fragment;
|
2008-06-27 18:06:50 -07:00
|
|
|
nanojit::LirBuffer* lirbuf;
|
2008-06-26 20:37:28 -07:00
|
|
|
nanojit::LirWriter* lir;
|
|
|
|
|
2008-06-27 18:06:50 -07:00
|
|
|
nanojit::SideExit* snapshot(nanojit::SideExit& exit, JSFrameRegs& regs);
|
|
|
|
public:
|
|
|
|
TraceRecorder(JSContext* cx, JSFrameRegs& regs, nanojit::Fragmento*);
|
|
|
|
~TraceRecorder();
|
|
|
|
|
2008-06-28 09:58:15 -07:00
|
|
|
inline jsbytecode* entryPC() const
|
2008-06-27 18:06:50 -07:00
|
|
|
{
|
|
|
|
return entryState.pc;
|
|
|
|
}
|
2008-06-26 22:33:33 -07:00
|
|
|
|
2008-06-26 22:41:10 -07:00
|
|
|
void init(void* p, nanojit::LIns* l);
|
|
|
|
void set(void* p, nanojit::LIns* l);
|
|
|
|
nanojit::LIns* get(void* p);
|
|
|
|
|
2008-06-27 20:58:06 -07:00
|
|
|
void readstack(void*);
|
2008-06-26 22:58:57 -07:00
|
|
|
|
|
|
|
void copy(void* a, void* v);
|
2008-06-27 00:22:16 -07:00
|
|
|
void imm(jsint i, void* v);
|
|
|
|
void imm(jsdouble d, void* v);
|
2008-06-26 22:58:57 -07:00
|
|
|
void unary(nanojit::LOpcode op, void* a, void* v);
|
|
|
|
void binary(nanojit::LOpcode op, void* a, void* b, void* v);
|
2008-06-27 06:53:10 -07:00
|
|
|
void binary0(nanojit::LOpcode op, void* a, void* v);
|
2008-06-26 22:58:57 -07:00
|
|
|
void call(int id, void* a, void* v);
|
|
|
|
void call(int id, void* a, void* b, void* v);
|
|
|
|
void call(int id, void* a, void* b, void* c, void* v);
|
|
|
|
|
2008-06-27 00:22:16 -07:00
|
|
|
void iinc(void* a, int32_t incr, void* v, JSFrameRegs& regs);
|
|
|
|
|
2008-06-27 07:28:10 -07:00
|
|
|
void guard_0(bool expected, void* a, JSFrameRegs& regs);
|
|
|
|
void guard_h(bool expected, void* a, JSFrameRegs& regs);
|
|
|
|
void guard_ov(bool expected, void* a, JSFrameRegs& regs);
|
2008-06-27 20:58:06 -07:00
|
|
|
void guard_eq(bool expected, void* a, void* b, JSFrameRegs& regs);
|
|
|
|
void guard_eqi(bool expected, void* a, int i, JSFrameRegs& regs);
|
2008-06-27 18:06:50 -07:00
|
|
|
|
|
|
|
void closeLoop(nanojit::Fragmento* fragmento);
|
2008-06-27 20:58:06 -07:00
|
|
|
|
|
|
|
void load(void* a, int32_t i, void* v);
|
2008-06-22 09:30:04 -07:00
|
|
|
};
|
|
|
|
|
2008-06-11 13:07:24 -07:00
|
|
|
/*
|
2008-06-03 23:52:28 -07:00
|
|
|
* Trace monitor. Every runtime is associated with a trace monitor that keeps
|
|
|
|
* track of loop frequencies for all JavaScript code loaded into that runtime.
|
|
|
|
* For this we use a loop table. Adjacent slots in the loop table, one for each
|
|
|
|
* loop header in a given script, are requested using lock-free synchronization
|
|
|
|
* from the runtime-wide loop table slot space, when the script is compiled.
|
2008-06-11 13:07:24 -07:00
|
|
|
*
|
2008-06-03 23:52:28 -07:00
|
|
|
* The loop table also doubles as trace tree pointer table once a loop achieves
|
|
|
|
* a certain number of iterations and we recorded a tree for that loop.
|
2008-05-30 18:58:43 -07:00
|
|
|
*/
|
|
|
|
struct JSTraceMonitor {
|
2008-06-26 18:13:54 -07:00
|
|
|
int freq;
|
|
|
|
nanojit::Fragmento* fragmento;
|
2008-06-26 20:49:04 -07:00
|
|
|
TraceRecorder* recorder;
|
2008-05-30 18:58:43 -07:00
|
|
|
};
|
|
|
|
|
2008-06-27 08:41:59 -07:00
|
|
|
#define TRACING_ENABLED(cx) JS_HAS_OPTION(cx, JSOPTION_JIT)
|
2008-06-10 16:49:05 -07:00
|
|
|
#define TRACE_TRIGGER_MASK 0x3f
|
2008-05-30 18:58:43 -07:00
|
|
|
|
2008-06-26 20:37:28 -07:00
|
|
|
extern bool
|
2008-06-22 09:30:04 -07:00
|
|
|
js_StartRecording(JSContext* cx, JSFrameRegs& regs);
|
2008-06-11 17:21:15 -07:00
|
|
|
|
2008-06-21 14:55:32 -07:00
|
|
|
extern void
|
2008-06-22 09:30:04 -07:00
|
|
|
js_EndRecording(JSContext* cx, JSFrameRegs& regs);
|
2008-06-11 17:59:28 -07:00
|
|
|
|
2008-05-31 15:29:54 -07:00
|
|
|
#endif /* jstracer_h___ */
|