2007-10-19 15:24:32 -07:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sw=4 et tw=80:
|
|
|
|
*
|
|
|
|
* ***** 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.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brendan Eich <brendan@mozilla.org>
|
|
|
|
*
|
|
|
|
* 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 ***** */
|
|
|
|
|
2010-04-30 17:04:31 -07:00
|
|
|
#ifdef INCLUDE_MOZILLA_DTRACE
|
2007-10-19 15:24:32 -07:00
|
|
|
#include "javascript-trace.h"
|
2010-04-30 17:04:31 -07:00
|
|
|
#endif
|
2007-10-19 15:24:32 -07:00
|
|
|
#include "jspubtd.h"
|
|
|
|
#include "jsprvtd.h"
|
|
|
|
|
|
|
|
#ifndef _JSDTRACEF_H
|
|
|
|
#define _JSDTRACEF_H
|
|
|
|
|
2010-04-30 17:04:31 -07:00
|
|
|
namespace js {
|
|
|
|
|
|
|
|
class DTrace {
|
2010-05-05 15:32:47 -07:00
|
|
|
static void enterJSFunImpl(JSContext *cx, JSStackFrame *fp, const JSFunction *fun);
|
|
|
|
static void handleFunctionInfo(JSContext *cx, JSStackFrame *fp, JSStackFrame *dfp,
|
|
|
|
JSFunction *fun);
|
|
|
|
static void handleFunctionArgs(JSContext *cx, JSStackFrame *fp, const JSFunction *fun,
|
|
|
|
jsuint argc, jsval *argv);
|
|
|
|
static void handleFunctionRval(JSContext *cx, JSStackFrame *fp, JSFunction *fun, jsval rval);
|
|
|
|
static void handleFunctionReturn(JSContext *cx, JSStackFrame *fp, JSFunction *fun);
|
|
|
|
static void finalizeObjectImpl(JSObject *obj);
|
2010-04-30 17:04:31 -07:00
|
|
|
public:
|
|
|
|
/*
|
|
|
|
* If |lval| is provided to the enter/exit methods, it is tested to see if
|
|
|
|
* it is a function as a predicate to the dtrace event emission.
|
|
|
|
*/
|
2010-05-05 15:32:47 -07:00
|
|
|
static void enterJSFun(JSContext *cx, JSStackFrame *fp, JSFunction *fun,
|
2010-05-02 17:14:44 -07:00
|
|
|
JSStackFrame *dfp, jsuint argc, jsval *argv, jsval *lval = NULL);
|
2010-05-05 15:32:47 -07:00
|
|
|
static void exitJSFun(JSContext *cx, JSStackFrame *fp, JSFunction *fun, jsval rval,
|
|
|
|
jsval *lval = NULL);
|
2010-04-30 17:04:31 -07:00
|
|
|
|
2010-05-05 15:32:47 -07:00
|
|
|
static void finalizeObject(JSObject *obj);
|
2010-04-30 17:04:31 -07:00
|
|
|
|
|
|
|
class ExecutionScope {
|
|
|
|
const JSScript *script;
|
|
|
|
void startExecution();
|
|
|
|
void endExecution();
|
|
|
|
public:
|
2010-05-05 15:32:47 -07:00
|
|
|
explicit ExecutionScope(JSScript *script);
|
|
|
|
~ExecutionScope();
|
|
|
|
};
|
|
|
|
|
|
|
|
class ObjectCreationScope {
|
|
|
|
JSContext * const cx;
|
|
|
|
JSStackFrame * const fp;
|
|
|
|
JSClass * const clasp;
|
|
|
|
void handleCreationStart();
|
|
|
|
void handleCreationImpl(JSObject *obj);
|
|
|
|
void handleCreationEnd();
|
|
|
|
public:
|
|
|
|
ObjectCreationScope(JSContext *cx, JSStackFrame *fp, JSClass *clasp);
|
|
|
|
void handleCreation(JSObject *obj);
|
|
|
|
~ObjectCreationScope();
|
2010-04-30 17:04:31 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
inline void
|
2010-05-05 15:32:47 -07:00
|
|
|
DTrace::enterJSFun(JSContext *cx, JSStackFrame *fp, JSFunction *fun, JSStackFrame *dfp,
|
|
|
|
jsuint argc, jsval *argv, jsval *lval)
|
2010-04-30 17:04:31 -07:00
|
|
|
{
|
|
|
|
#ifdef INCLUDE_MOZILLA_DTRACE
|
2010-05-02 17:14:44 -07:00
|
|
|
if (!lval || VALUE_IS_FUNCTION(cx, *lval)) {
|
2010-04-30 17:04:31 -07:00
|
|
|
if (JAVASCRIPT_FUNCTION_ENTRY_ENABLED())
|
2010-05-05 15:32:47 -07:00
|
|
|
enterJSFunImpl(cx, fp, fun);
|
2010-04-30 17:04:31 -07:00
|
|
|
if (JAVASCRIPT_FUNCTION_INFO_ENABLED())
|
2010-05-05 15:32:47 -07:00
|
|
|
handleFunctionInfo(cx, fp, dfp, fun);
|
2010-04-30 17:04:31 -07:00
|
|
|
if (JAVASCRIPT_FUNCTION_ARGS_ENABLED())
|
2010-05-05 15:32:47 -07:00
|
|
|
handleFunctionArgs(cx, fp, fun, argc, argv);
|
2010-04-30 17:04:31 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2010-05-05 15:32:47 -07:00
|
|
|
DTrace::exitJSFun(JSContext *cx, JSStackFrame *fp, JSFunction *fun, jsval rval, jsval *lval)
|
2010-04-30 17:04:31 -07:00
|
|
|
{
|
|
|
|
#ifdef INCLUDE_MOZILLA_DTRACE
|
2010-05-02 17:14:44 -07:00
|
|
|
if (!lval || VALUE_IS_FUNCTION(cx, *lval)) {
|
2010-04-30 17:04:31 -07:00
|
|
|
if (JAVASCRIPT_FUNCTION_RVAL_ENABLED())
|
2010-05-05 15:32:47 -07:00
|
|
|
handleFunctionRval(cx, fp, fun, rval);
|
2010-04-30 17:04:31 -07:00
|
|
|
if (JAVASCRIPT_FUNCTION_RETURN_ENABLED())
|
2010-05-05 15:32:47 -07:00
|
|
|
handleFunctionReturn(cx, fp, fun);
|
2010-04-30 17:04:31 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2010-05-05 15:32:47 -07:00
|
|
|
DTrace::finalizeObject(JSObject *obj)
|
2010-04-30 17:04:31 -07:00
|
|
|
{
|
|
|
|
#ifdef INCLUDE_MOZILLA_DTRACE
|
|
|
|
if (JAVASCRIPT_OBJECT_FINALIZE_ENABLED())
|
2010-05-05 15:32:47 -07:00
|
|
|
finalizeObjectImpl(obj);
|
2010-04-30 17:04:31 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-05-05 15:32:47 -07:00
|
|
|
/* Execution scope. */
|
|
|
|
|
|
|
|
inline
|
|
|
|
DTrace::ExecutionScope::ExecutionScope(JSScript *script)
|
|
|
|
: script(script)
|
2010-04-30 17:04:31 -07:00
|
|
|
{
|
|
|
|
#ifdef INCLUDE_MOZILLA_DTRACE
|
|
|
|
if (JAVASCRIPT_EXECUTE_START_ENABLED())
|
2010-05-05 15:32:47 -07:00
|
|
|
startExecution();
|
2010-04-30 17:04:31 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-05-05 15:32:47 -07:00
|
|
|
inline
|
|
|
|
DTrace::ExecutionScope::~ExecutionScope()
|
2010-04-30 17:04:31 -07:00
|
|
|
{
|
|
|
|
#ifdef INCLUDE_MOZILLA_DTRACE
|
2010-05-02 17:14:44 -07:00
|
|
|
if (JAVASCRIPT_EXECUTE_DONE_ENABLED())
|
2010-05-05 15:32:47 -07:00
|
|
|
endExecution();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Object creation scope. */
|
|
|
|
|
|
|
|
inline
|
|
|
|
DTrace::ObjectCreationScope::ObjectCreationScope(JSContext *cx, JSStackFrame *fp, JSClass *clasp)
|
|
|
|
: cx(cx), fp(fp), clasp(clasp)
|
|
|
|
{
|
|
|
|
#ifdef INCLUDE_MOZILLA_DTRACE
|
|
|
|
if (JAVASCRIPT_OBJECT_CREATE_START_ENABLED())
|
|
|
|
handleCreationStart();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
DTrace::ObjectCreationScope::handleCreation(JSObject *obj)
|
|
|
|
{
|
|
|
|
#ifdef INCLUDE_MOZILLA_DTRACE
|
|
|
|
if (JAVASCRIPT_OBJECT_CREATE_ENABLED())
|
|
|
|
handleCreationImpl(obj);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
DTrace::ObjectCreationScope::~ObjectCreationScope()
|
|
|
|
{
|
|
|
|
#ifdef INCLUDE_MOZILLA_DTRACE
|
|
|
|
if (JAVASCRIPT_OBJECT_CREATE_DONE_ENABLED())
|
|
|
|
handleCreationEnd();
|
2010-04-30 17:04:31 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace js */
|
|
|
|
|
2007-10-19 15:24:32 -07:00
|
|
|
#endif /* _JSDTRACE_H */
|