[runtime] Add function for printing type profile.

Separate the function that prints type profile with
--type-profile from the one that collects type profile.

The name needs to be stored in the feedback vector as well. I'll make a
follow up CL that stores the relevant information, so it can
be printed later.

BUG=v8:5935
R=yangguo@chromium.org

Review-Url: https://codereview.chromium.org/2757993002
Cr-Commit-Position: refs/heads/master@{#43929}
This commit is contained in:
franzih 2017-03-20 05:10:14 -07:00 committed by Commit bot
parent ab97fd76ef
commit 3e0aabb62f
5 changed files with 40 additions and 114 deletions

View File

@ -710,10 +710,6 @@ RUNTIME_FUNCTION(Runtime_CollectTypeProfile) {
CollectTypeProfileNexus nexus(vector, vector->ToSlot(index));
nexus.Collect(type);
PrintF("%s\n", name->ToCString().get());
nexus.Print();
PrintF("\n");
return *name;
}

View File

@ -156,6 +156,35 @@ RUNTIME_FUNCTION(Runtime_IsConcurrentRecompilationSupported) {
isolate->concurrent_recompilation_enabled());
}
RUNTIME_FUNCTION(Runtime_PrintTypeProfile) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
if (!FLAG_type_profile) {
return isolate->heap()->undefined_value();
}
CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
if (function->has_feedback_vector()) {
FeedbackVector* vector = function->feedback_vector();
Object* function_name = vector->shared_function_info()->name();
PrintF("Function: %s\n", String::cast(function_name)->ToCString().get());
FeedbackMetadataIterator iter(vector->metadata());
while (iter.HasNext()) {
FeedbackSlot slot = iter.Next();
FeedbackSlotKind kind = iter.kind();
if (kind == FeedbackSlotKind::kTypeProfile) {
CollectTypeProfileNexus nexus(vector, slot);
nexus.Print();
PrintF("\n");
return isolate->heap()->undefined_value();
}
}
}
return isolate->heap()->undefined_value();
}
RUNTIME_FUNCTION(Runtime_OptimizeFunctionOnNextCall) {
HandleScope scope(isolate);

View File

@ -551,6 +551,7 @@ namespace internal {
F(RunningInSimulator, 0, 1) \
F(IsConcurrentRecompilationSupported, 0, 1) \
F(OptimizeFunctionOnNextCall, -1, 1) \
F(PrintTypeProfile, 1, 1) \
F(InterpretFunctionOnNextCall, 1, 1) \
F(BaselineFunctionOnNextCall, 1, 1) \
F(OptimizeOsr, -1, 1) \

View File

@ -2,22 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --type-profile --turbo
// Flags: --type-profile --turbo --allow-natives-syntax
function test(param) {
var my_var1 = param;
var my_var2 = 17;
}
%PrintTypeProfile(test);
test({});
test(123);
test('hello');
test(123);
%PrintTypeProfile(test);
test(undefined);
test('hello');
test({x: 12});
test({x: 12});
%PrintTypeProfile(test);
class MyClass {
constructor() {}
}

View File

@ -1,88 +1,10 @@
my_var1
Object
my_var2
number
my_var1
Object
number
my_var2
number
number
my_var1
Object
number
string
my_var2
number
number
number
my_var1
Function: test
Object
number
string
number
my_var2
number
number
number
number
my_var1
Object
number
string
number
undefined
my_var2
number
number
number
number
number
my_var1
Object
number
string
number
undefined
string
my_var2
number
number
number
number
number
number
my_var1
Object
number
string
number
undefined
string
Object
my_var2
number
number
number
number
number
number
number
my_var1
Function: test
Object
number
string
@ -92,34 +14,6 @@ string
Object
Object
my_var2
number
number
number
number
number
number
number
number
Function
MyClass
Function
my_var
MyClass
my_var
MyClass
Object
my_var
MyClass
Object
number
*%(basename)s:34: throw otherwise test fails with --stress-opt
*%(basename)s:40: throw otherwise test fails with --stress-opt
throw "throw otherwise test fails with --stress-opt";
^