2008-05-30 18:58:43 -07:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2008-07-07 02:55:03 -07:00
|
|
|
* vim: set ts=8 sw=4 et tw=99 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-07-15 15:05:16 -07:00
|
|
|
* Mike Shaver <shaver@mozilla.org>
|
|
|
|
* David Anderson <danderson@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
|
|
|
|
2008-09-11 15:53:00 -07:00
|
|
|
#ifdef JS_TRACER
|
2008-08-12 08:36:29 -07:00
|
|
|
|
2008-11-07 15:23:43 -08:00
|
|
|
#include "jscntxt.h"
|
2008-05-30 18:58:43 -07:00
|
|
|
#include "jsstddef.h"
|
2008-07-23 02:57:56 -07:00
|
|
|
#include "jstypes.h"
|
2008-05-30 18:58:43 -07:00
|
|
|
#include "jslock.h"
|
2008-07-02 14:38:12 -07:00
|
|
|
#include "jsnum.h"
|
2008-07-03 22:08:13 -07:00
|
|
|
#include "jsinterp.h"
|
2008-10-08 15:08:33 -07:00
|
|
|
#include "jsbuiltins.h"
|
2008-07-05 16:28:03 -07:00
|
|
|
|
2008-10-29 21:56:35 -07:00
|
|
|
#if defined(DEBUG) && !defined(JS_JIT_SPEW)
|
|
|
|
#define JS_JIT_SPEW
|
|
|
|
#endif
|
|
|
|
|
2008-07-29 23:48:39 -07:00
|
|
|
template <typename T>
|
2008-09-23 18:12:53 -07:00
|
|
|
class Queue : public GCObject {
|
2008-07-29 23:48:39 -07:00
|
|
|
T* _data;
|
|
|
|
unsigned _len;
|
|
|
|
unsigned _max;
|
2008-07-30 04:17:22 -07:00
|
|
|
|
|
|
|
void ensure(unsigned size) {
|
|
|
|
while (_max < size)
|
|
|
|
_max <<= 1;
|
|
|
|
_data = (T*)realloc(_data, _max * sizeof(T));
|
|
|
|
}
|
2008-07-29 23:48:39 -07:00
|
|
|
public:
|
|
|
|
Queue(unsigned max = 16) {
|
|
|
|
this->_max = max;
|
|
|
|
this->_len = 0;
|
|
|
|
this->_data = (T*)malloc(max * sizeof(T));
|
|
|
|
}
|
|
|
|
|
|
|
|
~Queue() {
|
|
|
|
free(_data);
|
|
|
|
}
|
|
|
|
|
2008-08-06 19:06:37 -07:00
|
|
|
bool contains(T a) {
|
|
|
|
for (unsigned n = 0; n < _len; ++n)
|
|
|
|
if (_data[n] == a)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-07-29 23:48:39 -07:00
|
|
|
void add(T a) {
|
2008-07-30 04:17:22 -07:00
|
|
|
ensure(_len + 1);
|
2008-08-26 01:00:53 -07:00
|
|
|
JS_ASSERT(_len <= _max);
|
2008-07-29 23:48:39 -07:00
|
|
|
_data[_len++] = a;
|
|
|
|
}
|
|
|
|
|
2008-08-26 01:00:53 -07:00
|
|
|
void add(T* chunk, unsigned size) {
|
|
|
|
ensure(_len + size);
|
|
|
|
JS_ASSERT(_len <= _max);
|
|
|
|
memcpy(&_data[_len], chunk, size * sizeof(T));
|
|
|
|
_len += size;
|
|
|
|
}
|
|
|
|
|
2008-08-11 15:16:34 -07:00
|
|
|
void addUnique(T a) {
|
|
|
|
if (!contains(a))
|
|
|
|
add(a);
|
|
|
|
}
|
|
|
|
|
2008-07-30 04:17:22 -07:00
|
|
|
void setLength(unsigned len) {
|
|
|
|
ensure(len + 1);
|
|
|
|
_len = len;
|
|
|
|
}
|
|
|
|
|
2008-07-29 23:48:39 -07:00
|
|
|
void clear() {
|
|
|
|
_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned length() const {
|
|
|
|
return _len;
|
|
|
|
}
|
|
|
|
|
|
|
|
T* data() const {
|
|
|
|
return _data;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-06-21 14:55:32 -07:00
|
|
|
/*
|
2008-07-07 02:55:03 -07:00
|
|
|
* Tracker is used to keep track of values being manipulated by the interpreter
|
|
|
|
* during trace recording.
|
2008-06-21 14:55:32 -07:00
|
|
|
*/
|
2008-07-07 02:55:03 -07:00
|
|
|
class Tracker {
|
2008-06-21 14:55:32 -07:00
|
|
|
struct Page {
|
2008-07-05 11:18:26 -07:00
|
|
|
struct Page* next;
|
|
|
|
jsuword base;
|
2008-07-10 18:42:04 -07:00
|
|
|
nanojit::LIns* map[1];
|
2008-06-21 14:55:32 -07:00
|
|
|
};
|
|
|
|
struct Page* pagelist;
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-07-05 11:18:26 -07:00
|
|
|
jsuword getPageBase(const void* v) const;
|
2008-06-26 20:46:51 -07:00
|
|
|
struct Page* findPage(const void* v) const;
|
|
|
|
struct Page* addPage(const void* v);
|
2008-07-07 02:21:04 -07:00
|
|
|
public:
|
2008-06-21 14:55:32 -07:00
|
|
|
Tracker();
|
|
|
|
~Tracker();
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-07-20 14:23:39 -07:00
|
|
|
bool has(const void* v) const;
|
2008-07-10 18:42:04 -07:00
|
|
|
nanojit::LIns* get(const void* v) const;
|
|
|
|
void set(const void* v, nanojit::LIns* ins);
|
2008-06-26 20:44:23 -07:00
|
|
|
void clear();
|
2008-06-21 14:55:32 -07:00
|
|
|
};
|
|
|
|
|
2008-08-07 15:28:43 -07:00
|
|
|
/*
|
|
|
|
* The oracle keeps track of slots that should not be demoted to int because we know them
|
|
|
|
* to overflow or they result in type-unstable traces. We are using a simple hash table.
|
|
|
|
* Collisions lead to loss of optimization (demotable slots are not demoted) but have no
|
|
|
|
* correctness implications.
|
|
|
|
*/
|
|
|
|
#define ORACLE_SIZE 4096
|
|
|
|
|
|
|
|
class Oracle {
|
|
|
|
avmplus::BitSet _dontDemote;
|
|
|
|
public:
|
2008-08-07 17:43:13 -07:00
|
|
|
void markGlobalSlotUndemotable(JSScript* script, unsigned slot);
|
|
|
|
bool isGlobalSlotUndemotable(JSScript* script, unsigned slot) const;
|
2008-08-07 15:28:43 -07:00
|
|
|
void markStackSlotUndemotable(JSScript* script, jsbytecode* ip, unsigned slot);
|
|
|
|
bool isStackSlotUndemotable(JSScript* script, jsbytecode* ip, unsigned slot) const;
|
2008-08-20 15:18:43 -07:00
|
|
|
void clear();
|
2008-08-07 15:28:43 -07:00
|
|
|
};
|
|
|
|
|
2008-08-07 17:22:21 -07:00
|
|
|
typedef Queue<uint16> SlotList;
|
|
|
|
|
2008-08-07 15:28:43 -07:00
|
|
|
class TypeMap : public Queue<uint8> {
|
|
|
|
public:
|
2008-08-07 17:22:21 -07:00
|
|
|
void captureGlobalTypes(JSContext* cx, SlotList& slots);
|
2008-08-07 16:23:50 -07:00
|
|
|
void captureStackTypes(JSContext* cx, unsigned callDepth);
|
2008-08-19 11:32:36 -07:00
|
|
|
bool matches(TypeMap& other) const;
|
2008-08-07 15:28:43 -07:00
|
|
|
};
|
|
|
|
|
2008-11-07 15:23:43 -08:00
|
|
|
enum ExitType {
|
|
|
|
BRANCH_EXIT,
|
|
|
|
LOOP_EXIT,
|
|
|
|
NESTED_EXIT,
|
|
|
|
MISMATCH_EXIT,
|
|
|
|
OOM_EXIT,
|
|
|
|
OVERFLOW_EXIT,
|
|
|
|
UNSTABLE_LOOP_EXIT,
|
|
|
|
TIMEOUT_EXIT
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VMSideExit : public nanojit::SideExit
|
|
|
|
{
|
|
|
|
intptr_t ip_adj;
|
|
|
|
intptr_t sp_adj;
|
|
|
|
intptr_t rp_adj;
|
|
|
|
int32_t calldepth;
|
|
|
|
uint32 numGlobalSlots;
|
|
|
|
uint32 numStackSlots;
|
|
|
|
uint32 numStackSlotsBelowCurrentFrame;
|
|
|
|
ExitType exitType;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline uint8* getTypeMap(nanojit::SideExit* exit)
|
|
|
|
{
|
|
|
|
return (uint8*)(((VMSideExit*)exit) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct InterpState
|
|
|
|
{
|
|
|
|
void* sp; /* native stack pointer, stack[0] is spbase[0] */
|
|
|
|
void* rp; /* call stack pointer */
|
|
|
|
void* gp; /* global frame pointer */
|
|
|
|
JSContext *cx; /* current VM context handle */
|
|
|
|
void* eos; /* first unusable word after the native stack */
|
|
|
|
void* eor; /* first unusable word after the call stack */
|
|
|
|
VMSideExit* lastTreeExitGuard; /* guard we exited on during a tree call */
|
|
|
|
VMSideExit* lastTreeCallGuard; /* guard we want to grow from if the tree
|
|
|
|
call exit guard mismatched */
|
|
|
|
void* rpAtLastTreeCall; /* value of rp at innermost tree call guard */
|
|
|
|
};
|
|
|
|
|
2008-10-27 20:42:49 -07:00
|
|
|
struct UnstableExit
|
|
|
|
{
|
|
|
|
nanojit::Fragment* fragment;
|
2008-11-07 15:23:43 -08:00
|
|
|
VMSideExit* exit;
|
2008-10-27 20:42:49 -07:00
|
|
|
UnstableExit* next;
|
|
|
|
};
|
|
|
|
|
2008-08-11 16:01:21 -07:00
|
|
|
class TreeInfo MMGC_SUBCLASS_DECL {
|
2008-08-06 19:25:24 -07:00
|
|
|
nanojit::Fragment* fragment;
|
2008-07-16 21:41:03 -07:00
|
|
|
public:
|
2008-08-22 17:31:23 -07:00
|
|
|
JSScript* script;
|
2008-07-23 23:18:02 -07:00
|
|
|
unsigned maxNativeStackSlots;
|
2008-07-23 02:57:56 -07:00
|
|
|
ptrdiff_t nativeStackBase;
|
2008-07-14 19:12:50 -07:00
|
|
|
unsigned maxCallDepth;
|
2008-08-07 15:28:43 -07:00
|
|
|
TypeMap stackTypeMap;
|
2008-08-27 17:25:56 -07:00
|
|
|
Queue<nanojit::Fragment*> dependentTrees;
|
2008-09-02 23:52:11 -07:00
|
|
|
unsigned branchCount;
|
2008-11-07 15:23:43 -08:00
|
|
|
Queue<VMSideExit*> sideExits;
|
2008-10-27 20:42:49 -07:00
|
|
|
UnstableExit* unstableExits;
|
2008-08-27 17:25:56 -07:00
|
|
|
|
2008-10-27 20:42:49 -07:00
|
|
|
TreeInfo(nanojit::Fragment* _fragment) : unstableExits(NULL) {
|
2008-08-27 17:25:56 -07:00
|
|
|
fragment = _fragment;
|
2008-08-16 23:43:49 -07:00
|
|
|
}
|
2008-10-27 20:42:49 -07:00
|
|
|
~TreeInfo();
|
2008-07-04 13:23:42 -07:00
|
|
|
};
|
2008-10-12 15:39:32 -07:00
|
|
|
|
|
|
|
struct FrameInfo {
|
|
|
|
JSObject* callee; // callee function object
|
|
|
|
jsbytecode* callpc; // pc of JSOP_CALL in caller script
|
|
|
|
uint8* typemap; // typemap for the stack frame
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
uint16 spdist; // distance from fp->slots to fp->regs->sp at JSOP_CALL
|
|
|
|
uint16 argc; // actual argument count, may be < fun->nargs
|
|
|
|
} s;
|
|
|
|
uint32 word; // for spdist/argc LIR store in record_JSOP_CALL
|
|
|
|
};
|
|
|
|
};
|
2008-10-07 11:00:16 -07:00
|
|
|
|
2008-09-23 18:12:53 -07:00
|
|
|
class TraceRecorder : public GCObject {
|
2008-06-28 18:47:12 -07:00
|
|
|
JSContext* cx;
|
2008-08-19 11:32:36 -07:00
|
|
|
JSTraceMonitor* traceMonitor;
|
2008-07-14 16:40:38 -07:00
|
|
|
JSObject* globalObj;
|
2008-07-10 18:42:04 -07:00
|
|
|
Tracker tracker;
|
2008-07-23 23:18:02 -07:00
|
|
|
Tracker nativeFrameTracker;
|
2008-07-02 14:38:12 -07:00
|
|
|
char* entryTypeMap;
|
2008-07-21 13:18:08 -07:00
|
|
|
unsigned callDepth;
|
2008-07-10 21:55:09 -07:00
|
|
|
JSAtom** atoms;
|
2008-11-07 15:23:43 -08:00
|
|
|
VMSideExit* anchor;
|
2008-06-26 20:37:28 -07:00
|
|
|
nanojit::Fragment* fragment;
|
2008-07-21 12:41:43 -07:00
|
|
|
TreeInfo* treeInfo;
|
2008-06-27 18:06:50 -07:00
|
|
|
nanojit::LirBuffer* lirbuf;
|
2008-06-26 20:37:28 -07:00
|
|
|
nanojit::LirWriter* lir;
|
2008-07-01 19:43:10 -07:00
|
|
|
nanojit::LirBufWriter* lir_buf_writer;
|
2008-06-30 18:08:32 -07:00
|
|
|
nanojit::LirWriter* verbose_filter;
|
|
|
|
nanojit::LirWriter* cse_filter;
|
|
|
|
nanojit::LirWriter* expr_filter;
|
2008-07-05 23:21:53 -07:00
|
|
|
nanojit::LirWriter* func_filter;
|
2008-09-02 22:29:23 -07:00
|
|
|
#ifdef NJ_SOFTFLOAT
|
2008-09-02 22:29:23 -07:00
|
|
|
nanojit::LirWriter* float_filter;
|
|
|
|
#endif
|
2008-07-02 14:38:12 -07:00
|
|
|
nanojit::LIns* cx_ins;
|
2008-07-23 23:18:02 -07:00
|
|
|
nanojit::LIns* gp_ins;
|
2008-08-12 21:39:44 -07:00
|
|
|
nanojit::LIns* eos_ins;
|
2008-08-13 13:51:59 -07:00
|
|
|
nanojit::LIns* eor_ins;
|
2008-07-24 10:35:10 -07:00
|
|
|
nanojit::LIns* rval_ins;
|
2008-08-19 13:11:18 -07:00
|
|
|
nanojit::LIns* inner_sp_ins;
|
2008-08-29 18:59:21 -07:00
|
|
|
bool deepAborted;
|
2008-09-05 18:29:08 -07:00
|
|
|
bool applyingArguments;
|
|
|
|
bool trashTree;
|
2008-08-28 14:24:58 -07:00
|
|
|
nanojit::Fragment* whichTreeToTrash;
|
2008-08-29 15:12:17 -07:00
|
|
|
Queue<jsbytecode*> cfgMerges;
|
2008-09-23 13:29:41 -07:00
|
|
|
jsval* global_dslots;
|
2008-10-07 11:00:16 -07:00
|
|
|
JSTraceableNative* pendingTraceableNative;
|
2008-10-08 21:02:04 -07:00
|
|
|
bool terminate;
|
2008-10-27 20:42:49 -07:00
|
|
|
intptr_t terminate_ip_adj;
|
|
|
|
nanojit::Fragment* outerToBlacklist;
|
|
|
|
nanojit::Fragment* promotedPeer;
|
2008-08-29 18:59:21 -07:00
|
|
|
|
2008-07-23 23:18:02 -07:00
|
|
|
bool isGlobal(jsval* p) const;
|
|
|
|
ptrdiff_t nativeGlobalOffset(jsval* p) const;
|
2008-08-15 10:09:36 -07:00
|
|
|
ptrdiff_t nativeStackOffset(jsval* p) const;
|
2008-07-23 23:18:02 -07:00
|
|
|
void import(nanojit::LIns* base, ptrdiff_t offset, jsval* p, uint8& t,
|
2008-08-11 12:47:18 -07:00
|
|
|
const char *prefix, uintN index, JSStackFrame *fp);
|
2008-08-13 16:29:59 -07:00
|
|
|
void import(TreeInfo* treeInfo, nanojit::LIns* sp, unsigned ngslots, unsigned callDepth,
|
2008-08-13 15:50:11 -07:00
|
|
|
uint8* globalTypeMap, uint8* stackTypeMap);
|
2008-07-23 23:18:02 -07:00
|
|
|
void trackNativeStackUse(unsigned slots);
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-07-30 04:20:48 -07:00
|
|
|
bool lazilyImportGlobalSlot(unsigned slot);
|
2008-08-29 18:59:21 -07:00
|
|
|
|
2008-11-07 15:23:43 -08:00
|
|
|
nanojit::LIns* guard(bool expected, nanojit::LIns* cond, ExitType exitType);
|
2008-10-28 22:40:10 -07:00
|
|
|
nanojit::LIns* guard(bool expected, nanojit::LIns* cond, nanojit::LIns* exit);
|
2008-07-17 02:00:23 -07:00
|
|
|
nanojit::LIns* addName(nanojit::LIns* ins, const char* name);
|
2008-06-30 17:12:52 -07:00
|
|
|
|
2008-09-09 06:06:23 -07:00
|
|
|
nanojit::LIns* get(jsval* p) const;
|
2008-08-15 14:47:49 -07:00
|
|
|
nanojit::LIns* writeBack(nanojit::LIns* i, nanojit::LIns* base, ptrdiff_t offset);
|
2008-07-21 12:57:02 -07:00
|
|
|
void set(jsval* p, nanojit::LIns* l, bool initializing = false);
|
2008-07-06 11:48:41 -07:00
|
|
|
|
2008-10-27 20:42:49 -07:00
|
|
|
bool checkType(jsval& v, uint8 t, jsval*& stage_val, nanojit::LIns*& stage_ins,
|
|
|
|
unsigned& stage_count);
|
|
|
|
bool deduceTypeStability(nanojit::Fragment* root_peer, nanojit::Fragment** stable_peer,
|
|
|
|
unsigned* demotes);
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-07-04 03:06:18 -07:00
|
|
|
jsval& argval(unsigned n) const;
|
|
|
|
jsval& varval(unsigned n) const;
|
|
|
|
jsval& stackval(int n) const;
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-08-20 22:40:39 -07:00
|
|
|
nanojit::LIns* scopeChain() const;
|
|
|
|
bool activeCallOrGlobalSlot(JSObject* obj, jsval*& vp);
|
|
|
|
|
2008-07-04 03:06:18 -07:00
|
|
|
nanojit::LIns* arg(unsigned n);
|
2008-07-04 15:21:56 -07:00
|
|
|
void arg(unsigned n, nanojit::LIns* i);
|
2008-07-04 03:06:18 -07:00
|
|
|
nanojit::LIns* var(unsigned n);
|
2008-07-04 15:21:56 -07:00
|
|
|
void var(unsigned n, nanojit::LIns* i);
|
2008-07-04 03:06:18 -07:00
|
|
|
nanojit::LIns* stack(int n);
|
|
|
|
void stack(int n, nanojit::LIns* i);
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-07-06 15:55:04 -07:00
|
|
|
nanojit::LIns* f2i(nanojit::LIns* f);
|
2008-09-25 11:31:40 -07:00
|
|
|
nanojit::LIns* makeNumberInt32(nanojit::LIns* f);
|
2008-10-29 00:14:30 -07:00
|
|
|
nanojit::LIns* stringify(jsval& v, nanojit::LIns* v_ins);
|
2008-09-25 11:31:40 -07:00
|
|
|
|
2008-10-08 21:02:04 -07:00
|
|
|
bool ifop();
|
2008-08-28 23:50:48 -07:00
|
|
|
bool switchop();
|
2008-07-09 15:15:32 -07:00
|
|
|
bool inc(jsval& v, jsint incr, bool pre = true);
|
2008-07-19 10:24:10 -07:00
|
|
|
bool inc(jsval& v, nanojit::LIns*& v_ins, jsint incr, bool pre = true);
|
2008-07-19 00:15:22 -07:00
|
|
|
bool incProp(jsint incr, bool pre = true);
|
|
|
|
bool incElem(jsint incr, bool pre = true);
|
2008-08-12 08:33:40 -07:00
|
|
|
bool incName(jsint incr, bool pre = true);
|
2008-08-28 23:50:48 -07:00
|
|
|
|
2008-09-15 15:30:06 -07:00
|
|
|
enum { CMP_NEGATE = 1, CMP_TRY_BRANCH_AFTER_COND = 2, CMP_CASE = 4, CMP_STRICT = 8 };
|
2008-08-28 23:50:48 -07:00
|
|
|
bool cmp(nanojit::LOpcode op, int flags = 0);
|
2008-07-06 13:16:34 -07:00
|
|
|
|
|
|
|
bool unary(nanojit::LOpcode op);
|
|
|
|
bool binary(nanojit::LOpcode op);
|
2008-07-07 02:21:04 -07:00
|
|
|
|
|
|
|
bool ibinary(nanojit::LOpcode op);
|
2008-07-05 22:04:58 -07:00
|
|
|
bool iunary(nanojit::LOpcode op);
|
2008-07-07 02:21:04 -07:00
|
|
|
bool bbinary(nanojit::LOpcode op);
|
2008-07-05 23:21:53 -07:00
|
|
|
void demote(jsval& v, jsdouble result);
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-08-10 11:54:27 -07:00
|
|
|
bool map_is_native(JSObjectMap* map, nanojit::LIns* map_ins, nanojit::LIns*& ops_ins,
|
|
|
|
size_t op_offset = 0);
|
2008-07-30 16:32:33 -07:00
|
|
|
bool test_property_cache(JSObject* obj, nanojit::LIns* obj_ins, JSObject*& obj2,
|
|
|
|
jsuword& pcval);
|
2008-07-09 11:42:31 -07:00
|
|
|
bool test_property_cache_direct_slot(JSObject* obj, nanojit::LIns* obj_ins, uint32& slot);
|
2008-07-07 02:21:04 -07:00
|
|
|
void stobj_set_slot(nanojit::LIns* obj_ins, unsigned slot,
|
2008-07-07 02:55:03 -07:00
|
|
|
nanojit::LIns*& dslots_ins, nanojit::LIns* v_ins);
|
2008-07-30 16:32:33 -07:00
|
|
|
nanojit::LIns* stobj_get_fslot(nanojit::LIns* obj_ins, unsigned slot);
|
2008-07-07 02:21:04 -07:00
|
|
|
nanojit::LIns* stobj_get_slot(nanojit::LIns* obj_ins, unsigned slot,
|
2008-07-07 02:55:03 -07:00
|
|
|
nanojit::LIns*& dslots_ins);
|
2008-07-07 02:21:04 -07:00
|
|
|
bool native_set(nanojit::LIns* obj_ins, JSScopeProperty* sprop,
|
2008-07-07 02:55:03 -07:00
|
|
|
nanojit::LIns*& dslots_ins, nanojit::LIns* v_ins);
|
2008-07-07 02:21:04 -07:00
|
|
|
bool native_get(nanojit::LIns* obj_ins, nanojit::LIns* pobj_ins, JSScopeProperty* sprop,
|
2008-07-07 02:55:03 -07:00
|
|
|
nanojit::LIns*& dslots_ins, nanojit::LIns*& v_ins);
|
2008-07-25 16:51:42 -07:00
|
|
|
|
2008-08-12 09:42:29 -07:00
|
|
|
bool name(jsval*& vp);
|
2008-07-19 10:24:28 -07:00
|
|
|
bool prop(JSObject* obj, nanojit::LIns* obj_ins, uint32& slot, nanojit::LIns*& v_ins);
|
2008-09-25 15:04:48 -07:00
|
|
|
bool elem(jsval& oval, jsval& idx, jsval*& vp, nanojit::LIns*& v_ins, nanojit::LIns*& addr_ins);
|
2008-07-06 10:38:55 -07:00
|
|
|
|
2008-07-16 14:36:50 -07:00
|
|
|
bool getProp(JSObject* obj, nanojit::LIns* obj_ins);
|
|
|
|
bool getProp(jsval& v);
|
|
|
|
bool getThis(nanojit::LIns*& this_ins);
|
2008-10-13 09:04:26 -07:00
|
|
|
|
2008-07-06 13:59:59 -07:00
|
|
|
bool box_jsval(jsval v, nanojit::LIns*& v_ins);
|
2008-07-06 10:38:55 -07:00
|
|
|
bool unbox_jsval(jsval v, nanojit::LIns*& v_ins);
|
2008-07-30 16:32:33 -07:00
|
|
|
bool guardClass(JSObject* obj, nanojit::LIns* obj_ins, JSClass* clasp);
|
|
|
|
bool guardDenseArray(JSObject* obj, nanojit::LIns* obj_ins);
|
|
|
|
bool guardDenseArrayIndex(JSObject* obj, jsint idx, nanojit::LIns* obj_ins,
|
2008-10-24 21:51:04 -07:00
|
|
|
nanojit::LIns* dslots_ins, nanojit::LIns* idx_ins,
|
2008-11-07 15:23:43 -08:00
|
|
|
ExitType exitType);
|
2008-09-25 15:04:48 -07:00
|
|
|
bool guardElemOp(JSObject* obj, nanojit::LIns* obj_ins, jsid id, size_t op_offset, jsval* vp);
|
2008-07-24 10:35:10 -07:00
|
|
|
void clearFrameSlotsFromCache();
|
2008-08-08 16:37:01 -07:00
|
|
|
bool guardShapelessCallee(jsval& callee);
|
2008-09-18 14:13:37 -07:00
|
|
|
bool interpretedFunctionCall(jsval& fval, JSFunction* fun, uintN argc, bool constructing);
|
2008-10-13 09:04:26 -07:00
|
|
|
bool functionCall(bool constructing);
|
2008-08-13 14:02:35 -07:00
|
|
|
bool forInLoop(jsval* vp);
|
2008-07-31 16:30:00 -07:00
|
|
|
|
2008-08-29 15:12:17 -07:00
|
|
|
void trackCfgMerges(jsbytecode* pc);
|
2008-10-08 21:02:04 -07:00
|
|
|
void flipIf(jsbytecode* pc, bool& cond);
|
2008-08-29 15:12:17 -07:00
|
|
|
void fuseIf(jsbytecode* pc, bool cond, nanojit::LIns* x);
|
2008-09-05 18:29:08 -07:00
|
|
|
|
2008-07-03 23:57:57 -07:00
|
|
|
public:
|
2008-09-09 22:22:52 -07:00
|
|
|
friend bool js_MonitorRecording(TraceRecorder* tr);
|
2008-09-05 18:29:08 -07:00
|
|
|
|
2008-11-07 15:23:43 -08:00
|
|
|
TraceRecorder(JSContext* cx, VMSideExit*, nanojit::Fragment*, TreeInfo*,
|
2008-08-20 22:37:00 -07:00
|
|
|
unsigned ngslots, uint8* globalTypeMap, uint8* stackTypeMap,
|
2008-11-07 15:23:43 -08:00
|
|
|
VMSideExit* expectedInnerExit, nanojit::Fragment* outerToBlacklist);
|
2008-07-03 23:57:57 -07:00
|
|
|
~TraceRecorder();
|
|
|
|
|
2008-09-09 13:20:44 -07:00
|
|
|
uint8 determineSlotType(jsval* vp) const;
|
2008-11-07 15:23:43 -08:00
|
|
|
nanojit::LIns* snapshot(ExitType exitType);
|
2008-07-17 01:29:41 -07:00
|
|
|
nanojit::Fragment* getFragment() const { return fragment; }
|
2008-07-27 14:28:56 -07:00
|
|
|
bool isLoopHeader(JSContext* cx) const;
|
2008-08-25 15:17:46 -07:00
|
|
|
void compile(nanojit::Fragmento* fragmento);
|
2008-10-27 20:42:49 -07:00
|
|
|
bool closeLoop(nanojit::Fragmento* fragmento, bool& demote, unsigned *demotes);
|
2008-08-25 15:17:46 -07:00
|
|
|
void endLoop(nanojit::Fragmento* fragmento);
|
2008-10-27 20:42:49 -07:00
|
|
|
void joinEdgesToEntry(nanojit::Fragmento* fragmento, nanojit::Fragment* peer_root);
|
2008-08-06 22:26:20 -07:00
|
|
|
void blacklist() { fragment->blacklist(); }
|
2008-10-27 20:42:49 -07:00
|
|
|
bool adjustCallerTypes(nanojit::Fragment* f, unsigned* demote_slots, bool& trash);
|
|
|
|
nanojit::Fragment* findNestedCompatiblePeer(nanojit::Fragment* f, nanojit::Fragment** empty);
|
2008-08-20 00:51:56 -07:00
|
|
|
void prepareTreeCall(nanojit::Fragment* inner);
|
2008-11-07 15:23:43 -08:00
|
|
|
void emitTreeCall(nanojit::Fragment* inner, VMSideExit* exit);
|
2008-08-07 16:41:20 -07:00
|
|
|
unsigned getCallDepth() const;
|
2008-07-17 01:29:41 -07:00
|
|
|
|
2008-07-16 23:00:59 -07:00
|
|
|
bool record_EnterFrame();
|
2008-07-24 10:35:10 -07:00
|
|
|
bool record_LeaveFrame();
|
2008-09-11 15:53:00 -07:00
|
|
|
bool record_SetPropHit(JSPropCacheEntry* entry, JSScopeProperty* sprop);
|
2008-09-09 22:22:52 -07:00
|
|
|
bool record_SetPropMiss(JSPropCacheEntry* entry);
|
2008-09-24 19:31:51 -07:00
|
|
|
bool record_DefLocalFunSetSlot(uint32 slot, JSObject* obj);
|
2008-10-07 11:00:16 -07:00
|
|
|
bool record_FastNativeCallComplete();
|
2008-10-28 14:04:29 -07:00
|
|
|
bool record_IteratorNextComplete();
|
2008-09-24 19:31:51 -07:00
|
|
|
|
2008-10-27 20:42:49 -07:00
|
|
|
nanojit::Fragment* getOuterToBlacklist() { return outerToBlacklist; }
|
2008-08-29 18:59:21 -07:00
|
|
|
void deepAbort() { deepAborted = true; }
|
|
|
|
bool wasDeepAborted() { return deepAborted; }
|
2008-10-08 21:02:04 -07:00
|
|
|
bool walkedOutOfLoop() { return terminate; }
|
2008-10-27 20:42:49 -07:00
|
|
|
void setPromotedPeer(nanojit::Fragment* peer) { promotedPeer = peer; }
|
|
|
|
TreeInfo* getTreeInfo() { return treeInfo; }
|
2008-10-08 21:02:04 -07:00
|
|
|
|
2008-07-07 02:21:04 -07:00
|
|
|
#define OPDEF(op,val,name,token,length,nuses,ndefs,prec,format) \
|
2008-07-10 21:55:09 -07:00
|
|
|
bool record_##op();
|
2008-07-07 02:21:04 -07:00
|
|
|
# include "jsopcode.tbl"
|
|
|
|
#undef OPDEF
|
2008-06-22 09:30:04 -07:00
|
|
|
};
|
|
|
|
|
2008-06-27 08:41:59 -07:00
|
|
|
#define TRACING_ENABLED(cx) JS_HAS_OPTION(cx, JSOPTION_JIT)
|
2008-09-09 22:22:52 -07:00
|
|
|
#define TRACE_RECORDER(cx) (JS_TRACE_MONITOR(cx).recorder)
|
|
|
|
#define SET_TRACE_RECORDER(cx,tr) (JS_TRACE_MONITOR(cx).recorder = (tr))
|
2008-05-30 18:58:43 -07:00
|
|
|
|
2008-09-09 22:22:52 -07:00
|
|
|
// See jsinterp.cpp for the ENABLE_TRACER definition.
|
|
|
|
#define RECORD_ARGS(x,args) \
|
2008-07-16 22:58:06 -07:00
|
|
|
JS_BEGIN_MACRO \
|
2008-11-03 20:57:50 -08:00
|
|
|
if (!js_MonitorRecording(TRACE_RECORDER(cx))) \
|
2008-08-29 15:12:17 -07:00
|
|
|
ENABLE_TRACER(0); \
|
2008-09-09 22:22:52 -07:00
|
|
|
else \
|
2008-11-03 20:57:50 -08:00
|
|
|
TRACE_ARGS_(TRACE_RECORDER(cx),x,args); \
|
2008-09-09 22:22:52 -07:00
|
|
|
JS_END_MACRO
|
|
|
|
|
|
|
|
#define TRACE_ARGS_(tr,x,args) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
if (!tr->record_##x args) { \
|
2008-10-09 16:17:13 -07:00
|
|
|
js_AbortRecording(cx, #x); \
|
2008-07-16 22:58:06 -07:00
|
|
|
ENABLE_TRACER(0); \
|
|
|
|
} \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
2008-09-09 22:22:52 -07:00
|
|
|
#define TRACE_ARGS(x,args) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
TraceRecorder* tr_ = TRACE_RECORDER(cx); \
|
|
|
|
if (tr_) \
|
|
|
|
TRACE_ARGS_(tr_, x, args); \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
|
|
|
#define RECORD(x) RECORD_ARGS(x, ())
|
2008-09-18 16:53:09 -07:00
|
|
|
#define TRACE_0(x) TRACE_ARGS(x, ())
|
2008-09-09 22:22:52 -07:00
|
|
|
#define TRACE_1(x,a) TRACE_ARGS(x, (a))
|
|
|
|
#define TRACE_2(x,a,b) TRACE_ARGS(x, (a, b))
|
|
|
|
|
2008-07-04 01:10:57 -07:00
|
|
|
extern bool
|
2008-10-09 16:17:13 -07:00
|
|
|
js_MonitorLoopEdge(JSContext* cx, uintN& inlineCallCount);
|
2008-08-28 22:33:22 -07:00
|
|
|
|
|
|
|
extern bool
|
2008-09-09 22:22:52 -07:00
|
|
|
js_MonitorRecording(TraceRecorder *tr);
|
2008-06-11 17:21:15 -07:00
|
|
|
|
2008-06-28 18:19:21 -07:00
|
|
|
extern void
|
2008-10-09 16:17:13 -07:00
|
|
|
js_AbortRecording(JSContext* cx, const char* reason);
|
2008-06-28 18:19:21 -07:00
|
|
|
|
2008-07-05 19:15:00 -07:00
|
|
|
extern void
|
2008-08-11 18:47:22 -07:00
|
|
|
js_InitJIT(JSTraceMonitor *tm);
|
2008-07-05 19:15:00 -07:00
|
|
|
|
2008-07-17 10:22:40 -07:00
|
|
|
extern void
|
2008-08-11 19:17:30 -07:00
|
|
|
js_FinishJIT(JSTraceMonitor *tm);
|
2008-07-17 10:22:40 -07:00
|
|
|
|
2008-08-06 21:56:25 -07:00
|
|
|
extern void
|
|
|
|
js_FlushJITCache(JSContext* cx);
|
|
|
|
|
2008-08-20 16:01:56 -07:00
|
|
|
extern void
|
|
|
|
js_FlushJITOracle(JSContext* cx);
|
|
|
|
|
2008-09-11 15:53:00 -07:00
|
|
|
#else /* !JS_TRACER */
|
|
|
|
|
|
|
|
#define RECORD(x) ((void)0)
|
2008-09-22 13:04:47 -07:00
|
|
|
#define TRACE_0(x) ((void)0)
|
2008-09-11 15:53:00 -07:00
|
|
|
#define TRACE_1(x,a) ((void)0)
|
|
|
|
#define TRACE_2(x,a,b) ((void)0)
|
|
|
|
|
|
|
|
#endif /* !JS_TRACER */
|
2008-08-12 08:36:29 -07:00
|
|
|
|
2008-05-31 15:29:54 -07:00
|
|
|
#endif /* jstracer_h___ */
|