source: webkit/trunk/JavaScriptCore/kjs/interpreter.cpp@ 34372

Last change on this file since 34372 was 34036, checked in by [email protected], 17 years ago

2008-05-22 Kevin McCullough <[email protected]>

Reviewed by Sam.

<rdar://problem/5951561> Turn on JavaScript Profiler
Get basic JS profiling working.
Even with this patch the profiler will not be compiled in because we do
not know the extend, if any, of the performance regression it would cause
when it is not in use. However with these changes, if the profiler were
on, it would not crash and show good profiling data.

  • VM/Machine.cpp: Instrument the calls sites that are needed for profiling. (KJS::callEval): (KJS::Machine::unwindCallFrame): (KJS::Machine::execute): (KJS::Machine::privateExecute):
  • kjs/function.cpp: Ditto. (KJS::globalFuncEval):
  • kjs/interpreter.cpp: Ditto. (KJS::Interpreter::evaluate):
  • profiler/Profile.cpp: (KJS::Profile::willExecute): (KJS::Profile::didExecute): Because we do not get a good context when startProfiling is called it is possible that m_currentNode will be at the top of the known stack when a didExecute() is called. What we then do is create a new node that represents the function being exited and insert it between the head and the currently known children, since they should be children of this new node.
  • profiler/ProfileNode.cpp: (KJS::ProfileNode::ProfileNode): (KJS::ProfileNode::willExecute): Rename the add function for consistency. (KJS::ProfileNode::addChild): Appends the child to this node but also sets the parent pointer of the children to this node. (KJS::ProfileNode::insertNode): Insert a node between this node and its children. Also set the time for the new node since it is now exiting and we don't really know when it started. (KJS::ProfileNode::stopProfiling): (KJS::ProfileNode::startTimer):
  • profiler/ProfileNode.h: (KJS::CallIdentifier::toString): Added for debugging. (KJS::ProfileNode::setParent): (KJS::ProfileNode::setSelfTime): Fixed an old bug where we set the visibleTotalTime not the visibleSelfTime. (KJS::ProfileNode::children): (KJS::ProfileNode::toString): Added for debugging.
  • profiler/Profiler.cpp: remove unecessary calls. (KJS::Profiler::startProfiling):
  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2007 Apple Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#include "config.h"
24#include "interpreter.h"
25
26#include "ExecState.h"
27#include "JSGlobalObject.h"
28#include "Machine.h"
29#include "Parser.h"
30#include "debugger.h"
31#include <profiler/Profiler.h>
32#include <stdio.h>
33
34#if !PLATFORM(WIN_OS)
35#include <unistd.h>
36#endif
37
38namespace KJS {
39
40Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UString& code)
41{
42 return checkSyntax(exec, sourceURL, startingLineNumber, UStringSourceProvider::create(code));
43}
44
45Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source)
46{
47 JSLock lock;
48
49 int errLine;
50 UString errMsg;
51
52 RefPtr<ProgramNode> progNode = parser().parse<ProgramNode>(exec, sourceURL, startingLineNumber, source, 0, &errLine, &errMsg);
53 if (!progNode)
54 return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, 0, sourceURL));
55 return Completion(Normal);
56}
57
58Completion Interpreter::evaluate(ExecState* exec, ScopeChain& scopeChain, const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV)
59{
60 return evaluate(exec, scopeChain, sourceURL, startingLineNumber, UStringSourceProvider::create(code), thisV);
61}
62
63Completion Interpreter::evaluate(ExecState* exec, ScopeChain& scopeChain, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source, JSValue* thisValue)
64{
65 JSLock lock;
66
67 // parse the source code
68 int sourceId;
69 int errLine;
70 UString errMsg;
71
72 RefPtr<ProgramNode> programNode = parser().parse<ProgramNode>(exec, sourceURL, startingLineNumber, source, &sourceId, &errLine, &errMsg);
73
74 // no program node means a syntax error occurred
75 if (!programNode)
76 return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, sourceId, sourceURL));
77
78 JSObject* thisObj = (!thisValue || thisValue->isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue->toObject(exec);
79
80 JSValue* exception = 0;
81 JSValue* result = machine().execute(programNode.get(), exec, scopeChain.node(), thisObj, &exec->dynamicGlobalObject()->registerFileStack(), &exception);
82
83 return exception ? Completion(Throw, exception) : Completion(Normal, result);
84}
85
86static bool printExceptions = false;
87
88bool Interpreter::shouldPrintExceptions()
89{
90 return printExceptions;
91}
92
93void Interpreter::setShouldPrintExceptions(bool print)
94{
95 printExceptions = print;
96}
97
98} // namespace KJS
Note: See TracBrowser for help on using the repository browser.