Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1182428 - Refactor common trace logging code in bytecode compiler…
Browse files Browse the repository at this point in the history
… r=luke
  • Loading branch information
jonco3 committed Jul 13, 2015
1 parent 56ef49a commit bfafeb8
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions js/src/frontend/BytecodeCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ using namespace js;
using namespace js::frontend;
using mozilla::Maybe;

class MOZ_STACK_CLASS AutoCompilationTraceLogger
{
public:
AutoCompilationTraceLogger(ExclusiveContext* cx, const TraceLoggerTextId id);

private:
TraceLoggerThread* logger;
TraceLoggerEvent event;
AutoTraceLog scriptLogger;
AutoTraceLog typeLogger;
};

AutoCompilationTraceLogger::AutoCompilationTraceLogger(ExclusiveContext* cx, const TraceLoggerTextId id)
: logger(cx->isJSContext() ? TraceLoggerForMainThread(cx->asJSContext()->runtime())
: TraceLoggerForCurrentThread()),
event(logger, TraceLogger_AnnotateScripts),
scriptLogger(logger, event),
typeLogger(logger, id)
{}

static bool
CheckLength(ExclusiveContext* cx, SourceBufferHolder& srcBuf)
{
Expand Down Expand Up @@ -223,14 +243,7 @@ frontend::CompileScript(ExclusiveContext* cx, LifoAlloc* alloc, HandleObject sco

RootedString source(cx, source_);

js::TraceLoggerThread* logger = nullptr;
if (cx->isJSContext())
logger = TraceLoggerForMainThread(cx->asJSContext()->runtime());
else
logger = TraceLoggerForCurrentThread();
js::TraceLoggerEvent event(logger, TraceLogger_AnnotateScripts, options);
js::AutoTraceLog scriptLogger(logger, event);
js::AutoTraceLog typeLogger(logger, TraceLogger_ParserCompileScript);
AutoCompilationTraceLogger traceLogger(cx, TraceLogger_ParserCompileScript);

/*
* The scripted callerFrame can only be given for compile-and-go scripts
Expand Down Expand Up @@ -472,10 +485,7 @@ frontend::CompileLazyFunction(JSContext* cx, Handle<LazyScript*> lazy, const cha
.setNoScriptRval(false)
.setSelfHostingMode(false);

js::TraceLoggerThread* logger = js::TraceLoggerForMainThread(cx->runtime());
js::TraceLoggerEvent event(logger, TraceLogger_AnnotateScripts, options);
js::AutoTraceLog scriptLogger(logger, event);
js::AutoTraceLog typeLogger(logger, TraceLogger_ParserCompileLazy);
AutoCompilationTraceLogger traceLogger(cx, TraceLogger_ParserCompileLazy);

Parser<FullParseHandler> parser(cx, &cx->tempLifoAlloc(), options, chars, length,
/* foldConstants = */ true, nullptr, lazy);
Expand Down Expand Up @@ -539,10 +549,7 @@ CompileFunctionBody(JSContext* cx, MutableHandleFunction fun, const ReadOnlyComp
{
MOZ_ASSERT(!options.isRunOnce);

js::TraceLoggerThread* logger = js::TraceLoggerForMainThread(cx->runtime());
js::TraceLoggerEvent event(logger, TraceLogger_AnnotateScripts, options);
js::AutoTraceLog scriptLogger(logger, event);
js::AutoTraceLog typeLogger(logger, TraceLogger_ParserCompileFunction);
AutoCompilationTraceLogger traceLogger(cx, TraceLogger_ParserCompileFunction);

// FIXME: make Function pass in two strings and parse them as arguments and
// ProgramElements respectively.
Expand Down

0 comments on commit bfafeb8

Please sign in to comment.