Commit bf08ea99 authored by svenpanne's avatar svenpanne Committed by Commit bot

Add %_IncrementStatsCounter intrinsic.

Review URL: https://codereview.chromium.org/1031383002

Cr-Commit-Position: refs/heads/master@{#27497}
parent e7c2bd1a
...@@ -82,6 +82,12 @@ FieldAccess AccessBuilder::ForContextSlot(size_t index) { ...@@ -82,6 +82,12 @@ FieldAccess AccessBuilder::ForContextSlot(size_t index) {
} }
// static
FieldAccess AccessBuilder::ForStatsCounter() {
return {kUntaggedBase, 0, MaybeHandle<Name>(), Type::Signed32(), kMachInt32};
}
// static // static
ElementAccess AccessBuilder::ForFixedArrayElement() { ElementAccess AccessBuilder::ForFixedArrayElement() {
return {kTaggedBase, FixedArray::kHeaderSize, Type::Any(), kMachAnyTagged}; return {kTaggedBase, FixedArray::kHeaderSize, Type::Any(), kMachAnyTagged};
......
...@@ -46,6 +46,9 @@ class AccessBuilder FINAL : public AllStatic { ...@@ -46,6 +46,9 @@ class AccessBuilder FINAL : public AllStatic {
// Provides access Context slots. // Provides access Context slots.
static FieldAccess ForContextSlot(size_t index); static FieldAccess ForContextSlot(size_t index);
// Provides access to the backing store of a StatsCounter.
static FieldAccess ForStatsCounter();
// Provides access to FixedArray elements. // Provides access to FixedArray elements.
static ElementAccess ForFixedArrayElement(); static ElementAccess ForFixedArrayElement();
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "src/compiler/access-builder.h" #include "src/compiler/access-builder.h"
#include "src/compiler/js-graph.h" #include "src/compiler/js-graph.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties.h" #include "src/compiler/node-properties.h"
namespace v8 { namespace v8 {
...@@ -33,6 +34,8 @@ Reduction JSIntrinsicLowering::Reduce(Node* node) { ...@@ -33,6 +34,8 @@ Reduction JSIntrinsicLowering::Reduce(Node* node) {
return ReduceDoubleLo(node); return ReduceDoubleLo(node);
case Runtime::kInlineHeapObjectGetMap: case Runtime::kInlineHeapObjectGetMap:
return ReduceHeapObjectGetMap(node); return ReduceHeapObjectGetMap(node);
case Runtime::kInlineIncrementStatsCounter:
return ReduceIncrementStatsCounter(node);
case Runtime::kInlineIsArray: case Runtime::kInlineIsArray:
return ReduceIsInstanceType(node, JS_ARRAY_TYPE); return ReduceIsInstanceType(node, JS_ARRAY_TYPE);
case Runtime::kInlineIsFunction: case Runtime::kInlineIsFunction:
...@@ -136,6 +139,30 @@ Reduction JSIntrinsicLowering::ReduceHeapObjectGetMap(Node* node) { ...@@ -136,6 +139,30 @@ Reduction JSIntrinsicLowering::ReduceHeapObjectGetMap(Node* node) {
} }
Reduction JSIntrinsicLowering::ReduceIncrementStatsCounter(Node* node) {
if (!FLAG_native_code_counters) return ChangeToUndefined(node);
HeapObjectMatcher<String> m(NodeProperties::GetValueInput(node, 0));
if (!m.HasValue() || !m.Value().handle()->IsString()) {
return ChangeToUndefined(node);
}
SmartArrayPointer<char> name = m.Value().handle()->ToCString();
StatsCounter counter(jsgraph()->isolate(), name.get());
if (!counter.Enabled()) return ChangeToUndefined(node);
Node* effect = NodeProperties::GetEffectInput(node);
Node* control = NodeProperties::GetControlInput(node);
FieldAccess access = AccessBuilder::ForStatsCounter();
Node* cnt = jsgraph()->ExternalConstant(ExternalReference(&counter));
Node* load =
graph()->NewNode(simplified()->LoadField(access), cnt, effect, control);
Node* inc =
graph()->NewNode(machine()->Int32Add(), load, jsgraph()->OneConstant());
Node* store = graph()->NewNode(simplified()->StoreField(access), cnt, inc,
load, control);
return ChangeToUndefined(node, store);
}
Reduction JSIntrinsicLowering::ReduceIsInstanceType( Reduction JSIntrinsicLowering::ReduceIsInstanceType(
Node* node, InstanceType instance_type) { Node* node, InstanceType instance_type) {
// if (%_IsSmi(value)) { // if (%_IsSmi(value)) {
...@@ -352,6 +379,13 @@ Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a, ...@@ -352,6 +379,13 @@ Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a,
} }
Reduction JSIntrinsicLowering::ChangeToUndefined(Node* node, Node* effect) {
NodeProperties::ReplaceWithValue(node, jsgraph()->UndefinedConstant(),
effect);
return Changed(node);
}
Graph* JSIntrinsicLowering::graph() const { return jsgraph()->graph(); } Graph* JSIntrinsicLowering::graph() const { return jsgraph()->graph(); }
......
...@@ -32,6 +32,7 @@ class JSIntrinsicLowering FINAL : public Reducer { ...@@ -32,6 +32,7 @@ class JSIntrinsicLowering FINAL : public Reducer {
Reduction ReduceDoubleHi(Node* node); Reduction ReduceDoubleHi(Node* node);
Reduction ReduceDoubleLo(Node* node); Reduction ReduceDoubleLo(Node* node);
Reduction ReduceHeapObjectGetMap(Node* node); Reduction ReduceHeapObjectGetMap(Node* node);
Reduction ReduceIncrementStatsCounter(Node* node);
Reduction ReduceIsInstanceType(Node* node, InstanceType instance_type); Reduction ReduceIsInstanceType(Node* node, InstanceType instance_type);
Reduction ReduceIsNonNegativeSmi(Node* node); Reduction ReduceIsNonNegativeSmi(Node* node);
Reduction ReduceIsSmi(Node* node); Reduction ReduceIsSmi(Node* node);
...@@ -47,6 +48,7 @@ class JSIntrinsicLowering FINAL : public Reducer { ...@@ -47,6 +48,7 @@ class JSIntrinsicLowering FINAL : public Reducer {
Reduction Change(Node* node, const Operator* op); Reduction Change(Node* node, const Operator* op);
Reduction Change(Node* node, const Operator* op, Node* a, Node* b, Node* c); Reduction Change(Node* node, const Operator* op, Node* a, Node* b, Node* c);
Reduction ChangeToUndefined(Node* node, Node* effect = nullptr);
Graph* graph() const; Graph* graph() const;
JSGraph* jsgraph() const { return jsgraph_; } JSGraph* jsgraph() const { return jsgraph_; }
......
...@@ -318,5 +318,17 @@ RUNTIME_FUNCTION(Runtime_GetFromCache) { ...@@ -318,5 +318,17 @@ RUNTIME_FUNCTION(Runtime_GetFromCache) {
args[0] = isolate->native_context()->jsfunction_result_caches()->get(id); args[0] = isolate->native_context()->jsfunction_result_caches()->get(id);
return __RT_impl_Runtime_GetFromCacheRT(args, isolate); return __RT_impl_Runtime_GetFromCacheRT(args, isolate);
} }
RUNTIME_FUNCTION(Runtime_IncrementStatsCounter) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_CHECKED(String, name, 0);
if (FLAG_native_code_counters) {
StatsCounter(isolate, name->ToCString().get()).Increment();
}
return isolate->heap()->undefined_value();
}
} }
} // namespace v8::internal } // namespace v8::internal
...@@ -87,6 +87,7 @@ namespace internal { ...@@ -87,6 +87,7 @@ namespace internal {
F(TryMigrateInstance, 1, 1) \ F(TryMigrateInstance, 1, 1) \
F(NotifyContextDisposed, 0, 1) \ F(NotifyContextDisposed, 0, 1) \
F(ThrowIteratorResultNotAnObject, 1, 1) \ F(ThrowIteratorResultNotAnObject, 1, 1) \
F(IncrementStatsCounter, 1, 1) \
\ \
/* Array join support */ \ /* Array join support */ \
F(PushIfAbsent, 2, 1) \ F(PushIfAbsent, 2, 1) \
......
...@@ -49,6 +49,32 @@ TEST(HeapObjectGetMap) { ...@@ -49,6 +49,32 @@ TEST(HeapObjectGetMap) {
} }
#define COUNTER_NAME "hurz"
static int* LookupCounter(const char* name) {
static int counter = 1234;
return strcmp(name, COUNTER_NAME) == 0 ? &counter : nullptr;
}
TEST(IncrementStatsCounter) {
FLAG_turbo_deoptimization = true;
FLAG_native_code_counters = true;
reinterpret_cast<v8::Isolate*>(CcTest::InitIsolateOnce())
->SetCounterFunction(LookupCounter);
FunctionTester T(
"(function() { %_IncrementStatsCounter(\"" COUNTER_NAME "\"); })", flags);
StatsCounter counter(T.main_isolate(), COUNTER_NAME);
if (!counter.Enabled()) return;
int old_value = *counter.GetInternalPointer();
T.CheckCall(T.undefined());
CHECK_EQ(old_value + 1, *counter.GetInternalPointer());
}
#undef COUNTER_NAME
TEST(IsArray) { TEST(IsArray) {
FLAG_turbo_deoptimization = true; FLAG_turbo_deoptimization = true;
FunctionTester T("(function(a) { return %_IsArray(a); })", flags); FunctionTester T("(function(a) { return %_IsArray(a); })", flags);
......
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