diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index e44cf822f88..416bf66acf9 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -2864,8 +2864,8 @@ void js_TraceTraceMonitor(JSTracer *trc, JSTraceMonitor *tm) { TRACE_JSVALS(trc, tm->loopTableSize, tm->loopTable, "loop table"); - if (tm->recorderScriptObject) - JS_CALL_OBJECT_TRACER(trc, tm->recorderScriptObject, "recorder script object"); + if (tm->recorder) + JS_CALL_OBJECT_TRACER(trc, tm->recorder, "recorder object"); } void diff --git a/js/src/jsinterp.cpp b/js/src/jsinterp.cpp index 12cac904921..eb5b672df22 100644 --- a/js/src/jsinterp.cpp +++ b/js/src/jsinterp.cpp @@ -2760,7 +2760,7 @@ JS_INTERPRET(JSContext *cx) JS_END_MACRO # define BEGIN_CASE(OP) L_##OP: \ - trace_stop(#OP); + trace_stop(cx, #OP); # define TRACE_CASE(OP) L_##OP: # define END_CASE(OP) DO_NEXT_OP(OP##_LENGTH); # define END_VARLEN_CASE DO_NEXT_OP(len); @@ -2780,7 +2780,7 @@ JS_INTERPRET(JSContext *cx) JS_END_MACRO # define BEGIN_CASE(OP) case OP: \ - trace_stop(#OP); + trace_stop(cx, #OP); # define TRACE_CASE(OP) case OP: # define END_CASE(OP) END_CASE_LEN(OP##_LENGTH) # define END_CASE_LEN(n) END_CASE_LENX(n) @@ -3046,6 +3046,7 @@ JS_INTERPRET(JSContext *cx) * compiled a tree for us, and in that case reuse that * tree instead of recording a new one. */ + trace_start(cx, regs.pc); obj = js_NewObject(cx, &js_ObjectClass, NULL, NULL, 0); if (!obj) goto error; @@ -6968,7 +6969,7 @@ JS_INTERPRET(JSContext *cx) #define DEFINE_HANDLER(handler) \ handler: \ - trace_stop(#handler); + trace_stop(cx, #handler); DEFINE_HANDLER(error) JS_ASSERT((size_t)(regs.pc - script->code) < script->length); diff --git a/js/src/jsinterpinlines.h b/js/src/jsinterpinlines.h index 3247e2d2c22..fa65b60a27c 100644 --- a/js/src/jsinterpinlines.h +++ b/js/src/jsinterpinlines.h @@ -21,7 +21,7 @@ * Andreas Gal * * Contributor(s): - * Brendan Eich * * 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"), @@ -454,12 +454,19 @@ PRIMITIVE(guard_both_jsvals_are_string)(jsval& a, jsval& b) return JSVAL_IS_STRING(a) && JSVAL_IS_STRING(b); } +static inline void +PRIMITIVE(trace_start)(JSContext* cx, jsbytecode* pc) +{ + jsval args[] = { native_pointer_to_jsval(pc) }; + js_CallRecorder(cx, "start", 1, args); +} + /* * Unsupported opcodes trigger a trace stop condition and cause the trace * recorder to abandon the current trace. */ static inline void -PRIMITIVE(trace_stop)(const char* op) +PRIMITIVE(trace_stop)(JSContext* cx, const char* op) { /* If we are not tracing, this is a no-op. */ } diff --git a/js/src/jstracer.cpp b/js/src/jstracer.cpp index f30161c730c..b74f0cf6db9 100644 --- a/js/src/jstracer.cpp +++ b/js/src/jstracer.cpp @@ -88,3 +88,27 @@ js_GrowLoopTable(JSContext* cx, uint32 index) } return JS_TRUE; } + +JSObject* +js_GetRecorder(JSContext* cx) +{ + JSTraceMonitor* tm = &JS_TRACE_MONITOR(cx); + if (tm->recorder) + return tm->recorder; + JSScript* script = JS_CompileFile(cx, JS_GetGlobalObject(cx), "recorder.js"); + JS_ASSERT(script != NULL); + jsval result; + JSBool ok = JS_ExecuteScript(cx, JS_GetGlobalObject(cx), script, &result); + JS_ASSERT(ok && JSVAL_IS_OBJECT(result)); + return tm->recorder = JSVAL_TO_OBJECT(result); +} + +jsval +js_CallRecorder(JSContext* cx, const char* fn, uintN argc, jsval* argv) +{ + jsval rval; + JSBool ok; + ok = JS_CallFunctionName(cx, js_GetRecorder(cx), fn, argc, argv, &rval); + JS_ASSERT(ok); + return rval; +} \ No newline at end of file diff --git a/js/src/jstracer.h b/js/src/jstracer.h index 30f0c019110..3d8cb8e71c1 100644 --- a/js/src/jstracer.h +++ b/js/src/jstracer.h @@ -57,8 +57,7 @@ struct JSTraceMonitor { jsval *loopTable; uint32 loopTableSize; - JSScript *recorderScript; - JSObject *recorderScriptObject; + JSObject *recorder; }; #define TRACE_THRESHOLD 10 @@ -66,5 +65,17 @@ struct JSTraceMonitor { uint32 js_AllocateLoopTableSlot(JSRuntime *rt); void js_FreeLoopTableSlot(JSRuntime *rt, uint32 slot); JSBool js_GrowLoopTable(JSContext *cx, uint32 index); +jsval js_CallRecorder(JSContext* cx, const char* fn, uintN argc, jsval* argv); + +/* + * The recorder needs to keep track of native machine addresses. We speculate + * that these addresses can be wrapped into a 31-bit integer, which is true + * for most 32-bit machines. + */ +static inline jsval +native_pointer_to_jsval(void* p) { + JS_ASSERT(INT_FITS_IN_JSVAL((int)p)); + return INT_TO_JSVAL((int)p); +} #endif /* jstracer_h___ */ diff --git a/js/src/jstracerinlines.h b/js/src/jstracerinlines.h index a8c859c25c6..620e4e5be11 100644 --- a/js/src/jstracerinlines.h +++ b/js/src/jstracerinlines.h @@ -414,14 +414,14 @@ guard_both_jsvals_are_string(jsval& a, jsval& b) return interp_guard_both_jsvals_are_string(a, b); } -/* - * Unsupported opcodes trigger a trace stop condition and cause the trace - * recorder to abandon the current trace. - */ -static inline void -trace_stop(const char* op) +static inline void +trace_start(JSContext* cx, jsbytecode* pc) +{ +} + +static inline void +trace_stop(JSContext* cx, const char* op) { - /* If we are not tracing, this is a no-op. */ } #endif /* jstracerinlines_h___ */ diff --git a/js/src/recorder.js b/js/src/recorder.js new file mode 100644 index 00000000000..7db690ec206 --- /dev/null +++ b/js/src/recorder.js @@ -0,0 +1,45 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sw=4 et tw=78: + * + * ***** 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 + * Andreas Gal + * + * Contributor(s): + * Brendan Eich + * + * 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 ***** */ + +eval({ + start: function(pc) { + print("Recording at @" + pc); + } +}) +