Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (196146 => 196147)
--- trunk/Source/_javascript_Core/ChangeLog 2016-02-04 21:51:26 UTC (rev 196146)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-02-04 21:51:40 UTC (rev 196147)
@@ -1,3 +1,59 @@
+2016-02-04 Saam barati <sbar...@apple.com>
+
+ JSC Sampling Profiler: (host) is confusing in cases where I would expect to see JS name
+ https://bugs.webkit.org/show_bug.cgi?id=153663
+ <rdar://problem/24415092>
+
+ Reviewed by Geoffrey Garen.
+
+ We now collect the Callee in the processed StackFrame
+ when the Callee is a valid GC object. We later ask
+ the Callee for it's .displayName or .name property.
+ When we don't have a valid callee, we will still
+ use the Executable for this information.
+
+ This helps us come up with good names for frames where
+ the Callee object is a bound function or an InternalFunction.
+
+ * inspector/agents/InspectorScriptProfilerAgent.cpp:
+ (Inspector::InspectorScriptProfilerAgent::addEvent):
+ (Inspector::buildSamples):
+ (Inspector::InspectorScriptProfilerAgent::trackingComplete):
+ * runtime/SamplingProfiler.cpp:
+ (JSC::reportStats):
+ (JSC::FrameWalker::walk):
+ (JSC::SamplingProfiler::processUnverifiedStackTraces):
+ (JSC::SamplingProfiler::visit):
+ (JSC::SamplingProfiler::shutdown):
+ (JSC::SamplingProfiler::clearData):
+ (JSC::SamplingProfiler::StackFrame::nameFromCallee):
+ (JSC::SamplingProfiler::StackFrame::displayName):
+ (JSC::SamplingProfiler::StackFrame::displayNameForJSONTests):
+ (JSC::SamplingProfiler::stackTracesAsJSON):
+ * runtime/SamplingProfiler.h:
+ (JSC::SamplingProfiler::UnprocessedStackFrame::UnprocessedStackFrame):
+ (JSC::SamplingProfiler::StackFrame::StackFrame):
+ * tests/stress/sampling-profiler-basic.js:
+ (platformSupportsSamplingProfiler.nothing):
+ (platformSupportsSamplingProfiler.top):
+ * tests/stress/sampling-profiler-bound-function-name.js: Added.
+ (platformSupportsSamplingProfiler.foo):
+ (platformSupportsSamplingProfiler.bar):
+ (platformSupportsSamplingProfiler.let.baz):
+ (platformSupportsSamplingProfiler):
+ * tests/stress/sampling-profiler-display-name.js: Added.
+ (platformSupportsSamplingProfiler.foo):
+ (platformSupportsSamplingProfiler.baz):
+ (platformSupportsSamplingProfiler.):
+ (platformSupportsSamplingProfiler.bar):
+ (platformSupportsSamplingProfiler.jaz):
+ (platformSupportsSamplingProfiler.makeFunction.let.result):
+ (platformSupportsSamplingProfiler.makeFunction):
+ * tests/stress/sampling-profiler-internal-function-name.js: Added.
+ (platformSupportsSamplingProfiler.foo):
+ (platformSupportsSamplingProfiler.bar):
+ (platformSupportsSamplingProfiler):
+
2016-02-04 Chris Dumez <cdu...@apple.com>
Object.getOwnPropertyDescriptor() returns incomplete descriptor for instance properties
Modified: trunk/Source/_javascript_Core/inspector/agents/InspectorScriptProfilerAgent.cpp (196146 => 196147)
--- trunk/Source/_javascript_Core/inspector/agents/InspectorScriptProfilerAgent.cpp 2016-02-04 21:51:26 UTC (rev 196146)
+++ trunk/Source/_javascript_Core/inspector/agents/InspectorScriptProfilerAgent.cpp 2016-02-04 21:51:40 UTC (rev 196147)
@@ -157,7 +157,7 @@
}
#if ENABLE(SAMPLING_PROFILER)
-static Ref<Protocol::ScriptProfiler::Samples> buildSamples(Vector<SamplingProfiler::StackTrace>&& samplingProfilerStackTraces, double totalTime)
+static Ref<Protocol::ScriptProfiler::Samples> buildSamples(VM& vm, Vector<SamplingProfiler::StackTrace>&& samplingProfilerStackTraces, double totalTime)
{
Ref<Protocol::Array<Protocol::ScriptProfiler::StackTrace>> stackTraces = Protocol::Array<Protocol::ScriptProfiler::StackTrace>::create();
for (SamplingProfiler::StackTrace& stackTrace : samplingProfilerStackTraces) {
@@ -165,7 +165,7 @@
for (SamplingProfiler::StackFrame& stackFrame : stackTrace.frames) {
Ref<Protocol::ScriptProfiler::StackFrame> frame = Protocol::ScriptProfiler::StackFrame::create()
.setSourceID(String::number(stackFrame.sourceID()))
- .setName(stackFrame.displayName())
+ .setName(stackFrame.displayName(vm))
.setLine(stackFrame.functionStartLine())
.setColumn(stackFrame.functionStartColumn())
.setUrl(stackFrame.url())
@@ -195,7 +195,7 @@
LockHolder locker(samplingProfiler->getLock());
samplingProfiler->stop(locker);
Vector<SamplingProfiler::StackTrace> stackTraces = samplingProfiler->releaseStackTraces(locker);
- Ref<Protocol::ScriptProfiler::Samples> samples = buildSamples(WTFMove(stackTraces), samplingProfiler->totalTime(locker));
+ Ref<Protocol::ScriptProfiler::Samples> samples = buildSamples(m_environment.scriptDebugServer().vm(), WTFMove(stackTraces), samplingProfiler->totalTime(locker));
locker.unlockEarly();
Modified: trunk/Source/_javascript_Core/runtime/SamplingProfiler.cpp (196146 => 196147)
--- trunk/Source/_javascript_Core/runtime/SamplingProfiler.cpp 2016-02-04 21:51:26 UTC (rev 196146)
+++ trunk/Source/_javascript_Core/runtime/SamplingProfiler.cpp 2016-02-04 21:51:40 UTC (rev 196147)
@@ -44,6 +44,7 @@
#include "PCToCodeOriginMap.h"
#include "SlotVisitor.h"
#include "SlotVisitorInlines.h"
+#include "StructureInlines.h"
#include "VM.h"
#include "VMEntryScope.h"
@@ -58,7 +59,6 @@
static const bool sReportStats = false;
using FrameType = SamplingProfiler::FrameType;
-using UnprocessedFrameType = SamplingProfiler::UnprocessedFrameType;
using UnprocessedStackFrame = SamplingProfiler::UnprocessedStackFrame;
ALWAYS_INLINE static void reportStats()
@@ -89,14 +89,14 @@
resetAtMachineFrame();
size_t maxStackTraceSize = stackTrace.size();
while (!isAtTop() && !m_bailingOut && m_depth < maxStackTraceSize) {
- if (CodeBlock* codeBlock = m_callFrame->codeBlock()) {
+ CallSiteIndex callSiteIndex;
+ JSValue unsafeCallee = m_callFrame->unsafeCallee();
+ CodeBlock* codeBlock = m_callFrame->codeBlock();
+ if (codeBlock) {
ASSERT(isValidCodeBlock(codeBlock));
- stackTrace[m_depth] = UnprocessedStackFrame(codeBlock, m_callFrame->callSiteIndex());
- } else {
- RELEASE_ASSERT(codeBlock == nullptr);
- JSValue unsafeCallee = m_callFrame->unsafeCallee();
- stackTrace[m_depth] = UnprocessedStackFrame(JSValue::encode(unsafeCallee));
+ callSiteIndex = m_callFrame->callSiteIndex();
}
+ stackTrace[m_depth] = UnprocessedStackFrame(codeBlock, JSValue::encode(unsafeCallee), callSiteIndex);
m_depth++;
advanceToParentFrame();
resetAtMachineFrame();
@@ -330,7 +330,7 @@
auto appendCodeBlock = [&] (CodeBlock* codeBlock, unsigned bytecodeIndex) {
stackTrace.frames.append(StackFrame(codeBlock->ownerExecutable()));
- m_seenExecutables.add(codeBlock->ownerExecutable());
+ m_liveCellPointers.add(codeBlock->ownerExecutable());
if (bytecodeIndex < codeBlock->instructionCount()) {
int divot;
@@ -341,16 +341,24 @@
}
};
- auto appendUnverifiedCallee = [&] (JSValue callee) {
+ auto appendEmptyFrame = [&] {
stackTrace.frames.append(StackFrame());
+ };
+
+ auto storeCalleeIntoTopFrame = [&] (EncodedJSValue encodedCallee) {
+ // Set the callee if it's a valid GC object.
+ JSValue callee = JSValue::decode(encodedCallee);
StackFrame& stackFrame = stackTrace.frames.last();
+ bool alreadyHasExecutable = !!stackFrame.executable;
if (!Heap::isValueGCObject(filter, markedBlockSet, callee)) {
- stackFrame.frameType = FrameType::Unknown;
+ if (!alreadyHasExecutable)
+ stackFrame.frameType = FrameType::Unknown;
return;
}
JSCell* calleeCell = callee.asCell();
- auto frameTypeFromCallData = [&] () -> FrameType {
+ auto setFallbackFrameType = [&] {
+ ASSERT(!alreadyHasExecutable);
FrameType result = FrameType::Unknown;
CallData callData;
CallType callType;
@@ -358,30 +366,47 @@
if (callType == CallTypeHost)
result = FrameType::Host;
- return result;
+ stackFrame.frameType = result;
};
+ auto addCallee = [&] (JSObject* callee) {
+ stackFrame.callee = callee;
+ m_liveCellPointers.add(callee);
+ };
+
if (calleeCell->type() != JSFunctionType) {
- stackFrame.frameType = frameTypeFromCallData();
+ if (JSObject* object = jsDynamicCast<JSObject*>(calleeCell))
+ addCallee(object);
+
+ if (!alreadyHasExecutable)
+ setFallbackFrameType();
+
return;
}
- ExecutableBase* executable = static_cast<JSFunction*>(calleeCell)->executable();
+
+ addCallee(jsCast<JSFunction*>(calleeCell));
+
+ if (alreadyHasExecutable)
+ return;
+
+ ExecutableBase* executable = jsCast<JSFunction*>(calleeCell)->executable();
if (!executable) {
- stackFrame.frameType = frameTypeFromCallData();
+ setFallbackFrameType();
return;
}
RELEASE_ASSERT(Heap::isPointerGCObject(filter, markedBlockSet, executable));
stackFrame.frameType = FrameType::Executable;
stackFrame.executable = executable;
- m_seenExecutables.add(executable);
+ m_liveCellPointers.add(executable);
};
+
// Prepend the top-most inlined frame if needed and gather
// location information about where the top frame is executing.
size_t startIndex = 0;
- if (unprocessedStackTrace.frames.size() && unprocessedStackTrace.frames[0].frameType == UnprocessedFrameType::VerifiedCodeBlock) {
- CodeBlock* topCodeBlock = unprocessedStackTrace.frames[0].u.verifiedCodeBlock;
+ if (unprocessedStackTrace.frames.size() && !!unprocessedStackTrace.frames[0].verifiedCodeBlock) {
+ CodeBlock* topCodeBlock = unprocessedStackTrace.frames[0].verifiedCodeBlock;
if (unprocessedStackTrace.topFrameIsLLInt) {
// We reuse LLInt CodeBlocks for the baseline JIT, so we need to check for both jit types.
// This might also be false for various reasons (known and unknown), even though
@@ -403,20 +428,21 @@
UNUSED_PARAM(isValidPC); // FIXME: do something with this info for the web inspector: https://bugs.webkit.org/show_bug.cgi?id=153455
appendCodeBlock(topCodeBlock, bytecodeIndex);
+ storeCalleeIntoTopFrame(unprocessedStackTrace.frames[0].unverifiedCallee);
startIndex = 1;
}
} else if (Optional<CodeOrigin> codeOrigin = topCodeBlock->findPC(unprocessedStackTrace.topPC)) {
codeOrigin->walkUpInlineStack([&] (const CodeOrigin& codeOrigin) {
appendCodeBlock(codeOrigin.inlineCallFrame ? codeOrigin.inlineCallFrame->baselineCodeBlock.get() : topCodeBlock, codeOrigin.bytecodeIndex);
});
+ storeCalleeIntoTopFrame(unprocessedStackTrace.frames[0].unverifiedCallee);
startIndex = 1;
}
}
for (size_t i = startIndex; i < unprocessedStackTrace.frames.size(); i++) {
UnprocessedStackFrame& unprocessedStackFrame = unprocessedStackTrace.frames[i];
- if (unprocessedStackFrame.frameType == UnprocessedFrameType::VerifiedCodeBlock) {
- CodeBlock* codeBlock = unprocessedStackFrame.u.verifiedCodeBlock;
+ if (CodeBlock* codeBlock = unprocessedStackFrame.verifiedCodeBlock) {
CallSiteIndex callSiteIndex = unprocessedStackFrame.callSiteIndex;
auto appendCodeBlockNoInlining = [&] {
@@ -437,10 +463,12 @@
#else
appendCodeBlockNoInlining();
#endif
- } else {
- ASSERT(unprocessedStackFrame.frameType == UnprocessedFrameType::UnverifiedCallee);
- appendUnverifiedCallee(JSValue::decode(unprocessedStackFrame.u.unverifiedCallee));
- }
+ } else
+ appendEmptyFrame();
+
+ // Note that this is okay to do if we walked the inline stack because
+ // the machine frame will be at the top of the processed stack trace.
+ storeCalleeIntoTopFrame(unprocessedStackFrame.unverifiedCallee);
}
}
@@ -450,8 +478,8 @@
void SamplingProfiler::visit(SlotVisitor& slotVisitor)
{
RELEASE_ASSERT(m_lock.isLocked());
- for (ExecutableBase* executable : m_seenExecutables)
- slotVisitor.appendUnbarrieredReadOnlyPointer(executable);
+ for (JSCell* cell : m_liveCellPointers)
+ slotVisitor.appendUnbarrieredReadOnlyPointer(cell);
}
void SamplingProfiler::shutdown()
@@ -539,12 +567,44 @@
{
ASSERT(m_lock.isLocked());
m_stackTraces.clear();
- m_seenExecutables.clear();
+ m_liveCellPointers.clear();
m_unprocessedStackTraces.clear();
}
-String SamplingProfiler::StackFrame::displayName()
+String SamplingProfiler::StackFrame::nameFromCallee(VM& vm)
{
+ if (!callee)
+ return String();
+
+ ExecState* exec = callee->globalObject()->globalExec();
+ auto getPropertyIfPureOperation = [&] (const Identifier& ident) -> String {
+ PropertySlot slot(callee);
+ PropertyName propertyName(ident);
+ if (callee->getPropertySlot(exec, propertyName, slot)) {
+ if (slot.isValue()) {
+ JSValue nameValue = slot.getValue(exec, propertyName);
+ if (isJSString(nameValue))
+ return asString(nameValue)->tryGetValue();
+ }
+ }
+ return String();
+ };
+
+ String name = getPropertyIfPureOperation(vm.propertyNames->displayName);
+ if (!name.isEmpty())
+ return name;
+
+ return getPropertyIfPureOperation(vm.propertyNames->name);
+}
+
+String SamplingProfiler::StackFrame::displayName(VM& vm)
+{
+ {
+ String name = nameFromCallee(vm);
+ if (!name.isEmpty())
+ return name;
+ }
+
if (frameType == FrameType::Unknown)
return ASCIILiteral("(unknown)");
if (frameType == FrameType::Host)
@@ -564,8 +624,14 @@
return String();
}
-String SamplingProfiler::StackFrame::displayNameForJSONTests()
+String SamplingProfiler::StackFrame::displayNameForJSONTests(VM& vm)
{
+ {
+ String name = nameFromCallee(vm);
+ if (!name.isEmpty())
+ return name;
+ }
+
if (frameType == FrameType::Unknown)
return ASCIILiteral("(unknown)");
if (frameType == FrameType::Host)
@@ -674,7 +740,7 @@
for (StackFrame& stackFrame : stackTrace.frames) {
comma();
json.appendLiteral("\"");
- json.append(stackFrame.displayNameForJSONTests());
+ json.append(stackFrame.displayNameForJSONTests(m_vm));
json.appendLiteral("\"");
loopedOnce = true;
}
Modified: trunk/Source/_javascript_Core/runtime/SamplingProfiler.h (196146 => 196147)
--- trunk/Source/_javascript_Core/runtime/SamplingProfiler.h 2016-02-04 21:51:26 UTC (rev 196146)
+++ trunk/Source/_javascript_Core/runtime/SamplingProfiler.h 2016-02-04 21:51:40 UTC (rev 196147)
@@ -45,35 +45,20 @@
WTF_MAKE_FAST_ALLOCATED;
public:
- enum class UnprocessedFrameType {
- UnverifiedCallee,
- VerifiedCodeBlock
- };
-
struct UnprocessedStackFrame {
- UnprocessedStackFrame(EncodedJSValue callee)
- : frameType(UnprocessedFrameType::UnverifiedCallee)
- {
- u.unverifiedCallee = callee;
- }
- UnprocessedStackFrame(CodeBlock* codeBlock, CallSiteIndex callSiteIndex)
- : frameType(UnprocessedFrameType::VerifiedCodeBlock)
+ UnprocessedStackFrame(CodeBlock* codeBlock, EncodedJSValue callee, CallSiteIndex callSiteIndex)
+ : unverifiedCallee(callee)
+ , verifiedCodeBlock(codeBlock)
, callSiteIndex(callSiteIndex)
- {
- u.unverifiedCallee = JSValue::encode(JSValue());
- u.verifiedCodeBlock = codeBlock;
- }
+ { }
UnprocessedStackFrame()
- : frameType(UnprocessedFrameType::UnverifiedCallee)
{
- u.unverifiedCallee = JSValue::encode(JSValue());
+ unverifiedCallee = JSValue::encode(JSValue());
+ verifiedCodeBlock = nullptr;
}
- UnprocessedFrameType frameType;
- union {
- EncodedJSValue unverifiedCallee;
- CodeBlock* verifiedCodeBlock;
- } u;
+ EncodedJSValue unverifiedCallee;
+ CodeBlock* verifiedCodeBlock;
CallSiteIndex callSiteIndex;
};
@@ -88,21 +73,21 @@
: frameType(FrameType::Executable)
, executable(executable)
{ }
+
StackFrame()
- : frameType(FrameType::Unknown)
- , executable(nullptr)
{ }
- FrameType frameType;
- ExecutableBase* executable;
-
+ FrameType frameType { FrameType::Unknown };
+ ExecutableBase* executable { nullptr };
+ JSObject* callee { nullptr };
// These attempt to be _expression_-level line and column number.
unsigned lineNumber { std::numeric_limits<unsigned>::max() };
unsigned columnNumber { std::numeric_limits<unsigned>::max() };
// These are function-level data.
- String displayName();
- String displayNameForJSONTests(); // Used for JSC stress tests because they want the "(anonymous function)" string for anonymous functions and they want "(eval)" for eval'd code.
+ String nameFromCallee(VM&);
+ String displayName(VM&);
+ String displayNameForJSONTests(VM&); // Used for JSC stress tests because they want the "(anonymous function)" string for anonymous functions and they want "(eval)" for eval'd code.
int functionStartLine();
unsigned functionStartColumn();
intptr_t sourceID();
@@ -168,7 +153,7 @@
bool m_isActive;
bool m_isPaused;
bool m_hasDispatchedFunction;
- HashSet<ExecutableBase*> m_seenExecutables;
+ HashSet<JSCell*> m_liveCellPointers;
Vector<UnprocessedStackFrame> m_currentFrames;
};
Modified: trunk/Source/_javascript_Core/tests/stress/sampling-profiler-basic.js (196146 => 196147)
--- trunk/Source/_javascript_Core/tests/stress/sampling-profiler-basic.js 2016-02-04 21:51:26 UTC (rev 196146)
+++ trunk/Source/_javascript_Core/tests/stress/sampling-profiler-basic.js 2016-02-04 21:51:40 UTC (rev 196147)
@@ -17,7 +17,7 @@
function nothing(x) { return x; }
noInline(nothing);
- runTest(foo, ["(host)", "bar", "foo"]);
+ runTest(foo, ["Error", "bar", "foo"]);
function top() {
let x = 0;
Added: trunk/Source/_javascript_Core/tests/stress/sampling-profiler-bound-function-name.js (0 => 196147)
--- trunk/Source/_javascript_Core/tests/stress/sampling-profiler-bound-function-name.js (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/sampling-profiler-bound-function-name.js 2016-02-04 21:51:40 UTC (rev 196147)
@@ -0,0 +1,28 @@
+if (platformSupportsSamplingProfiler()) {
+ load("./sampling-profiler/samplingProfiler.js");
+
+ function foo() {
+ let o = {};
+ for (let i = 0; i < 100; i++) {
+ o[i + "p"] = i;
+ }
+ }
+
+ function bar() {
+ let o = {};
+ for (let i = 0; i < 100; i++) {
+ o[i + "p"] = i;
+ }
+ }
+
+ let boundFoo = foo.bind(null);
+ let boundBar = bar.bind(null);
+
+ let baz = function() {
+ boundFoo();
+ boundBar();
+ }
+
+ runTest(baz, ["foo", "bound foo", "baz"]);
+ runTest(baz, ["bar", "bound bar", "baz"]);
+}
Added: trunk/Source/_javascript_Core/tests/stress/sampling-profiler-display-name.js (0 => 196147)
--- trunk/Source/_javascript_Core/tests/stress/sampling-profiler-display-name.js (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/sampling-profiler-display-name.js 2016-02-04 21:51:40 UTC (rev 196147)
@@ -0,0 +1,49 @@
+if (platformSupportsSamplingProfiler()) {
+ load("./sampling-profiler/samplingProfiler.js");
+
+ function foo() {
+ let o = {};
+ for (let i = 0; i < 500; i++)
+ o[i + "p"] = i;
+ }
+ foo.displayName = "display foo";
+ runTest(foo, ["display foo"]);
+
+
+ function baz() {
+ let o = {};
+ for (let i = 0; i < 500; i++)
+ o[i + "p"] = i;
+ }
+ Object.defineProperty(baz, 'displayName', { get: function() { throw new Error("shouldnt be called"); } }); // We should ignore this because it's a getter.
+ runTest(baz, ["baz"]);
+
+
+ function bar() {
+ let o = {};
+ for (let i = 0; i < 500; i++)
+ o[i + "p"] = i;
+ }
+ bar.displayName = 20; // We should ignore this because it's not a string.
+ runTest(bar, ["bar"]);
+
+ function jaz() {
+ let o = {};
+ for (let i = 0; i < 500; i++)
+ o[i + "p"] = i;
+ }
+ jaz.displayName = ""; // We should ignore this because it's the empty string.
+ runTest(jaz, ["jaz"]);
+
+ function makeFunction(displayName) {
+ let result = function() {
+ let o = {};
+ for (let i = 0; i < 500; i++)
+ o[i + "p"] = i;
+ };
+ result.displayName = displayName;
+ return result;
+ }
+
+ runTest(makeFunction("hello world"), ["hello world"])
+}
Added: trunk/Source/_javascript_Core/tests/stress/sampling-profiler-internal-function-name.js (0 => 196147)
--- trunk/Source/_javascript_Core/tests/stress/sampling-profiler-internal-function-name.js (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/sampling-profiler-internal-function-name.js 2016-02-04 21:51:40 UTC (rev 196147)
@@ -0,0 +1,17 @@
+if (platformSupportsSamplingProfiler()) {
+ load("./sampling-profiler/samplingProfiler.js");
+
+ function foo() {
+ let x;
+ for (let i = 0; i < 1000; i++)
+ x = new Error();
+ }
+ runTest(foo, ["Error", "foo"]);
+
+ function bar() {
+ let x;
+ for (let i = 0; i < 1000; i++)
+ x = new Function();
+ }
+ runTest(bar, ["Function", "bar"]);
+}