Commit eb51bd9b authored by barraclough@apple.com's avatar barraclough@apple.com

2008-07-30 Gavin Barraclough <barraclough@apple.com>

        Reviewed by Geoff Garen.

        Fixes for Windows and non-AllInOne file build with SamplingTool, plus review fixes.

        * GNUmakefile.am:              Adding SamplingTool.cpp to build.
        * JavaScriptCore.exp:          Export hooks to init & control SamplingTool.
        * JavaScriptCore.pri:          Adding SamplingTool.cpp to build.
        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj: Adding SamplingTool.cpp to build.
        * JavaScriptCore.xcodeproj/project.pbxproj: Adding SamplingTool.cpp to build.
        * JavaScriptCoreSources.bkl:   Adding SamplingTool.cpp to build.
        * VM/Machine.cpp:              MACHINE_SAMPLING_callingNativeFunction renamed MACHINE_SAMPLING_callingHostFunction
        * VM/Machine.h:
        * VM/Opcode.cpp:               SamplingTool moved to SamplingTool.cpp/.h, opcodeNames generated from FOR_EACH_OPCODE_ID.
        * VM/Opcode.h:
        * VM/SamplingTool.cpp:         Added .cpp/.h for SamplingTool.
        * VM/SamplingTool.h:
        * kjs/Shell.cpp:               Switched SAMPLING_TOOL_ENABLED to ENABLE_SAMPLING_TOOL.
        * wtf/Platform.h:              Added ENABLE_SAMPLING_TOOL config option.
        * kjs/nodes.cpp:               Header include to fix non-AllInOne builds.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@35454 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 328e98d3
2008-07-30 Gavin Barraclough <barraclough@apple.com>
Reviewed by Geoff Garen.
Fixes for Windows and non-AllInOne file build with SamplingTool, plus review fixes.
* GNUmakefile.am: Adding SamplingTool.cpp to build.
* JavaScriptCore.exp: Export hooks to init & control SamplingTool.
* JavaScriptCore.pri: Adding SamplingTool.cpp to build.
* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj: Adding SamplingTool.cpp to build.
* JavaScriptCore.xcodeproj/project.pbxproj: Adding SamplingTool.cpp to build.
* JavaScriptCoreSources.bkl: Adding SamplingTool.cpp to build.
* VM/Machine.cpp: MACHINE_SAMPLING_callingNativeFunction renamed MACHINE_SAMPLING_callingHostFunction
* VM/Machine.h:
* VM/Opcode.cpp: SamplingTool moved to SamplingTool.cpp/.h, opcodeNames generated from FOR_EACH_OPCODE_ID.
* VM/Opcode.h:
* VM/SamplingTool.cpp: Added .cpp/.h for SamplingTool.
* VM/SamplingTool.h:
* kjs/Shell.cpp: Switched SAMPLING_TOOL_ENABLED to ENABLE_SAMPLING_TOOL.
* wtf/Platform.h: Added ENABLE_SAMPLING_TOOL config option.
* kjs/nodes.cpp: Header include to fix non-AllInOne builds.
2008-07-30 Ariya Hidayat <ariya.hidayat@trolltech.com>
Reviewed by Alexey Proskuryakov.
......@@ -50,6 +50,7 @@ javascriptcore_sources += \
JavaScriptCore/VM/JSPropertyNameIterator.cpp \
JavaScriptCore/VM/Machine.cpp \
JavaScriptCore/VM/Opcode.cpp \
JavaScriptCore/VM/SamplingTool.cpp \
JavaScriptCore/pcre/pcre_compile.cpp \
JavaScriptCore/pcre/pcre_exec.cpp \
JavaScriptCore/pcre/pcre_tables.cpp \
......
......@@ -101,6 +101,9 @@ __ZN3KJS12DateInstance4infoE
__ZN3KJS12JSGlobalData6createEv
__ZN3KJS12JSGlobalDataD1Ev
__ZN3KJS12PropertySlot15undefinedGetterEPNS_9ExecStateERKNS_10IdentifierERKS0_
__ZN3KJS12SamplingTool4dumpEPNS_9ExecStateE
__ZN3KJS12SamplingTool4stopEv
__ZN3KJS12SamplingTool5startEj
__ZN3KJS12StringObject14deletePropertyEPNS_9ExecStateERKNS_10IdentifierE
__ZN3KJS12StringObject14toThisJSStringEPNS_9ExecStateE
__ZN3KJS12StringObject16getPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayE
......
......@@ -58,6 +58,7 @@ SOURCES += \
VM/JSPropertyNameIterator.cpp \
VM/Machine.cpp \
VM/Opcode.cpp \
VM/SamplingTool.cpp \
VM/RegisterFile.cpp
# AllInOneFile.cpp helps gcc analize and optimize code
......
......@@ -1273,6 +1273,14 @@
RelativePath="..\..\VM\Opcode.h"
>
</File>
<File
RelativePath="..\..\VM\SamplingTool.cpp"
>
</File>
<File
RelativePath="..\..\VM\SamplingTool.h"
>
</File>
<File
RelativePath="..\..\VM\Register.h"
>
......
......@@ -74,6 +74,8 @@
659126BD0BDD1728001921FB /* AllInOneFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 659126BC0BDD1728001921FB /* AllInOneFile.cpp */; };
65DFC93308EA173A00F7300B /* HashTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65DFC92D08EA173A00F7300B /* HashTable.cpp */; };
65FDE49C0BDD1D4A00E80111 /* Assertions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65E217B808E7EECC0023E5F6 /* Assertions.cpp */; };
8613F45A0E3A433E00C948FD /* SamplingTool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8613F4580E3A433E00C948FD /* SamplingTool.cpp */; };
8613F45B0E3A433E00C948FD /* SamplingTool.h in Headers */ = {isa = PBXBuildFile; fileRef = 8613F4590E3A433E00C948FD /* SamplingTool.h */; };
905B02AE0E28640F006DF882 /* RefCountedLeakCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 905B02AD0E28640F006DF882 /* RefCountedLeakCounter.cpp */; };
90D3469C0E285280009492EE /* RefCountedLeakCounter.h in Headers */ = {isa = PBXBuildFile; fileRef = 90D3469B0E285280009492EE /* RefCountedLeakCounter.h */; settings = {ATTRIBUTES = (Private, ); }; };
930754C108B0F68000AB3056 /* pcre_compile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 930754BF08B0F68000AB3056 /* pcre_compile.cpp */; };
......@@ -555,6 +557,8 @@
65FB3F4809D11B2400F49DEB /* grammar.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = grammar.cpp; sourceTree = "<group>"; };
704FD35305697E6D003DBED9 /* BooleanObject.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = BooleanObject.h; sourceTree = "<group>"; tabWidth = 8; };
7E2C6C980D31C6B6002D44E2 /* ScopeChainMark.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScopeChainMark.h; sourceTree = "<group>"; };
8613F4580E3A433E00C948FD /* SamplingTool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SamplingTool.cpp; path = VM/SamplingTool.cpp; sourceTree = "<group>"; };
8613F4590E3A433E00C948FD /* SamplingTool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SamplingTool.h; path = VM/SamplingTool.h; sourceTree = "<group>"; };
905B02AD0E28640F006DF882 /* RefCountedLeakCounter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefCountedLeakCounter.cpp; sourceTree = "<group>"; };
90D3469B0E285280009492EE /* RefCountedLeakCounter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RefCountedLeakCounter.h; sourceTree = "<group>"; };
9303F567099118FA00AD71B8 /* OwnPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OwnPtr.h; sourceTree = "<group>"; };
......@@ -961,6 +965,8 @@
149B15E00D81F88D009CB8C7 /* vm */ = {
isa = PBXGroup;
children = (
8613F4580E3A433E00C948FD /* SamplingTool.cpp */,
8613F4590E3A433E00C948FD /* SamplingTool.h */,
149B1A9E0D86ED73009CB8C7 /* CodeBlock.cpp */,
149B1A9D0D86ED73009CB8C7 /* CodeBlock.h */,
A72701B40DADE94900E548D7 /* ExceptionHelpers.cpp */,
......@@ -1508,6 +1514,7 @@
BC756FC90E2031B200DE7D12 /* JSGlobalObjectFunctions.h in Headers */,
BCF605140E203EF800B9A64D /* ArgList.h in Headers */,
95FDFA160E2299980006FB00 /* HeavyProfile.h in Headers */,
8613F45B0E3A433E00C948FD /* SamplingTool.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -1811,6 +1818,7 @@
95CD45760E1C4FDD0085358E /* ProfileGenerator.cpp in Sources */,
95FDFA140E22998F0006FB00 /* HeavyProfile.cpp in Sources */,
905B02AE0E28640F006DF882 /* RefCountedLeakCounter.cpp in Sources */,
8613F45A0E3A433E00C948FD /* SamplingTool.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -144,6 +144,7 @@ Source files for JSCore.
VM/JSPropertyNameIterator.cpp
VM/Machine.cpp
VM/Opcode.cpp
VM/SamplingTool.cpp
VM/RegisterFile.cpp
</set>
<set append="1" var="JSCORE_WTF_SOURCES">
......
......@@ -50,6 +50,7 @@
#include "collector.h"
#include "debugger.h"
#include "operations.h"
#include "SamplingTool.h"
#include <stdio.h>
#if HAVE(SYS_TIME_H)
......@@ -475,12 +476,8 @@ NEVER_INLINE JSValue* Machine::callEval(ExecState* exec, JSObject* thisObj, Scop
}
Machine::Machine()
:
#if SAMPLING_TOOL_ENABLED
m_sampler(0),
#else
m_reentryDepth(0)
#endif
: m_sampler(0)
, m_reentryDepth(0)
, m_timeoutTime(0)
, m_timeAtLastCheckTimeout(0)
, m_timeExecuting(0)
......@@ -2374,7 +2371,7 @@ JSValue* Machine::privateExecute(ExecutionFlag flag, ExecState* exec, RegisterFi
JSValue* thisValue = thisVal == missingThisObjectMarker() ? exec->globalThisValue() : r[thisVal].jsValue(exec);
ArgList args(r + firstArg + 1, argCount - 1);
MACHINE_SAMPLING_callingNativeFunction();
MACHINE_SAMPLING_callingHostFunction();
JSValue* returnValue = callData.native.function(exec, static_cast<JSObject*>(v), thisValue, args);
VM_CHECK_EXCEPTION();
......@@ -2501,6 +2498,9 @@ JSValue* Machine::privateExecute(ExecutionFlag flag, ExecState* exec, RegisterFi
(*enabledProfilerReference)->willExecute(exec, constructor);
ArgList args(r + firstArg + 1, argCount - 1);
MACHINE_SAMPLING_callingHostFunction();
JSValue* returnValue = constructData.native.function(exec, constructor, args);
VM_CHECK_EXCEPTION();
......
......@@ -48,6 +48,7 @@ namespace KJS {
class ProgramNode;
class Register;
class ScopeChainNode;
class SamplingTool;
enum DebugHookID {
WillExecuteProgram,
......@@ -119,10 +120,8 @@ namespace KJS {
m_timeoutTime = 0;
m_timeoutCheckCount = 0;
}
#if SAMPLING_TOOL_ENABLED
SamplingTool* m_sampler;
#endif
private:
enum ExecutionFlag { Normal, InitializeAndReturn };
......
This diff is collapsed.
......@@ -30,12 +30,13 @@
#ifndef Opcodes_h
#define Opcodes_h
#include <algorithm>
#include <string.h>
#include <wtf/Assertions.h>
#include <wtf/HashMap.h>
namespace KJS {
#define SAMPLING_TOOL_ENABLED 0
#define DUMP_OPCODE_STATS 0
#define FOR_EACH_OPCODE_ID(macro) \
......@@ -148,118 +149,25 @@ namespace KJS {
typedef OpcodeID Opcode;
#endif
class ExecState;
class ScopeNode;
class CodeBlock;
struct Instruction;
#if SAMPLING_TOOL_ENABLED
#if ENABLE(SAMPLING_TOOL) || DUMP_OPCODE_STATS
struct ScopeSampleRecord
{
RefPtr<ScopeNode> m_scope;
CodeBlock* m_codeBlock;
int m_totalCount;
int* m_vpcCounts;
unsigned m_size;
ScopeSampleRecord(ScopeNode* scope)
: m_scope(scope)
, m_codeBlock(0)
, m_totalCount(0)
, m_vpcCounts(0)
, m_size(0)
{
}
~ScopeSampleRecord()
{
if (m_vpcCounts)
free(m_vpcCounts);
}
void sample(CodeBlock* codeBlock, Instruction* vPC);
};
#define PADDING_STRING " "
#define PADDING_STRING_LENGTH static_cast<unsigned>(strlen(PADDING_STRING))
typedef WTF::HashMap<ScopeNode*, ScopeSampleRecord*> ScopeSampleRecordMap;
extern const char* const opcodeNames[];
class SamplingTool
inline const char* padOpcodeName(OpcodeID op, unsigned width)
{
public:
SamplingTool()
: m_running(false)
, m_recordedCodeBlock(0)
, m_recordedVPC(0)
, m_totalSamples(0)
, m_scopeSampleMap(new ScopeSampleRecordMap())
{
}
~SamplingTool()
{
for (ScopeSampleRecordMap::iterator iter = m_scopeSampleMap->begin(); iter != m_scopeSampleMap->end(); ++iter)
delete iter->second;
delete m_scopeSampleMap;
}
void start(unsigned hertz=1000);
void stop();
void dump(ExecState*);
void notifyOfScope(ScopeNode* scope);
void sample(CodeBlock* recordedCodeBlock, Instruction* recordedVPC)
{
m_recordedCodeBlock = recordedCodeBlock;
m_recordedVPC = recordedVPC;
}
unsigned pad = width - strlen(opcodeNames[op]);
pad = std::min(pad, PADDING_STRING_LENGTH);
return PADDING_STRING + PADDING_STRING_LENGTH - pad;
}
void privateExecuteReturned()
{
m_recordedCodeBlock = 0;
m_recordedVPC = 0;
}
void callingNativeFunction()
{
m_recordedCodeBlock = 0;
m_recordedVPC = 0;
}
private:
static void* threadStartFunc(void*);
void run();
// Sampling thread state.
bool m_running;
unsigned m_hertz;
pthread_t m_samplingThread;
// State tracked by the main thread, used by the sampling thread.
CodeBlock* m_recordedCodeBlock;
Instruction* m_recordedVPC;
// Gathered sample data.
long long m_totalSamples;
ScopeSampleRecordMap* m_scopeSampleMap;
};
#undef PADDING_STRING_LENGTH
#undef PADDING_STRING
#endif
// SCOPENODE_ / MACHINE_ macros for use from within member methods on ScopeNode / Machine respectively.
#if SAMPLING_TOOL_ENABLED
#define SCOPENODE_SAMPLING_notifyOfScope(sampler) sampler->notifyOfScope(this)
#define MACHINE_SAMPLING_sample(codeBlock, vPC) m_sampler->sample(codeBlock, vPC)
#define MACHINE_SAMPLING_privateExecuteReturned() m_sampler->privateExecuteReturned()
#define MACHINE_SAMPLING_callingNativeFunction() m_sampler->callingNativeFunction()
#else
#define SCOPENODE_SAMPLING_notifyOfScope(sampler)
#define MACHINE_SAMPLING_sample(codeBlock, vPC)
#define MACHINE_SAMPLING_privateExecuteReturned()
#define MACHINE_SAMPLING_callingNativeFunction()
#endif
#if DUMP_OPCODE_STATS
struct OpcodeStats {
......
This diff is collapsed.
/*
* Copyright (C) 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SamplingTool_h
#define SamplingTool_h
#include <wtf/Assertions.h>
#include <wtf/HashMap.h>
#include <wtf/Threading.h>
#include <nodes.h>
#include <Opcode.h>
namespace KJS {
class ExecState;
class ScopeNode;
class CodeBlock;
struct Instruction;
struct ScopeSampleRecord {
RefPtr<ScopeNode> m_scope;
CodeBlock* m_codeBlock;
int m_totalCount;
int* m_vpcCounts;
unsigned m_size;
ScopeSampleRecord(ScopeNode* scope)
: m_scope(scope)
, m_codeBlock(0)
, m_totalCount(0)
, m_vpcCounts(0)
, m_size(0)
{
}
~ScopeSampleRecord()
{
if (m_vpcCounts)
free(m_vpcCounts);
}
void sample(CodeBlock* codeBlock, Instruction* vPC);
};
typedef WTF::HashMap<ScopeNode*, ScopeSampleRecord*> ScopeSampleRecordMap;
class SamplingTool {
public:
SamplingTool()
: m_running(false)
, m_recordedCodeBlock(0)
, m_recordedVPC(0)
, m_totalSamples(0)
, m_scopeSampleMap(new ScopeSampleRecordMap())
{
}
~SamplingTool()
{
deleteAllValues(*m_scopeSampleMap);
}
void start(unsigned hertz=1000);
void stop();
void dump(ExecState*);
void notifyOfScope(ScopeNode* scope);
void sample(CodeBlock* recordedCodeBlock, Instruction* recordedVPC)
{
m_recordedCodeBlock = recordedCodeBlock;
m_recordedVPC = recordedVPC;
}
void privateExecuteReturned()
{
m_recordedCodeBlock = 0;
m_recordedVPC = 0;
}
void callingHostFunction()
{
m_recordedCodeBlock = 0;
m_recordedVPC = 0;
}
private:
static void* threadStartFunc(void*);
void run();
// Sampling thread state.
bool m_running;
unsigned m_hertz;
ThreadIdentifier m_samplingThread;
// State tracked by the main thread, used by the sampling thread.
CodeBlock* m_recordedCodeBlock;
Instruction* m_recordedVPC;
// Gathered sample data.
long long m_totalSamples;
OwnPtr<ScopeSampleRecordMap> m_scopeSampleMap;
};
// SCOPENODE_ / MACHINE_ macros for use from within member methods on ScopeNode / Machine respectively.
#if ENABLE(SAMPLING_TOOL)
#define SCOPENODE_SAMPLING_notifyOfScope(sampler) sampler->notifyOfScope(this)
#define MACHINE_SAMPLING_sample(codeBlock, vPC) m_sampler->sample(codeBlock, vPC)
#define MACHINE_SAMPLING_privateExecuteReturned() m_sampler->privateExecuteReturned()
#define MACHINE_SAMPLING_callingHostFunction() m_sampler->callingHostFunction()
#else
#define SCOPENODE_SAMPLING_notifyOfScope(sampler)
#define MACHINE_SAMPLING_sample(codeBlock, vPC)
#define MACHINE_SAMPLING_privateExecuteReturned()
#define MACHINE_SAMPLING_callingHostFunction()
#endif
} // namespace KJS
#endif // SamplingTool_h
......@@ -34,6 +34,7 @@
#include "JSObject.h"
#include "Parser.h"
#include "PrototypeFunction.h"
#include "SamplingTool.h"
#include "collector.h"
#include "completion.h"
#include "interpreter.h"
......@@ -339,7 +340,7 @@ static bool runWithScripts(GlobalObject* globalObject, const Vector<UString>& fi
if (prettyPrint)
prettyPrintScript(globalObject->globalExec(), fileName, script);
else {
#if SAMPLING_TOOL_ENABLED
#if ENABLE(SAMPLING_TOOL)
Machine* machine = globalObject->globalData()->machine;
machine->m_sampler = new SamplingTool();
machine->m_sampler->start();
......@@ -354,7 +355,7 @@ static bool runWithScripts(GlobalObject* globalObject, const Vector<UString>& fi
printf("Exception: %s\n", completion.value()->toString(globalObject->globalExec()).ascii());
}
#if SAMPLING_TOOL_ENABLED
#if ENABLE(SAMPLING_TOOL)
machine->m_sampler->stop();
machine->m_sampler->dump(globalObject->globalExec());
delete machine->m_sampler;
......
......@@ -36,6 +36,7 @@
#include "debugger.h"
#include "lexer.h"
#include "operations.h"
#include "SamplingTool.h"
#include <math.h>
#include <wtf/Assertions.h>
#include <wtf/HashCountedSet.h>
......
......@@ -324,4 +324,7 @@
#define ENABLE_DASHBOARD_SUPPORT 0
#endif
// Set to 1 to enable the sampler, SamplingTool.
#define ENABLE_SAMPLING_TOOL 0
#endif /* WTF_Platform_h */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment