Reviewers: Michael Starzinger,
Description:
Add %_IncrementStatsCounter intrinsic.
Please review this at https://codereview.chromium.org/1031383002/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+84, -0 lines):
M src/compiler/access-builder.h
M src/compiler/access-builder.cc
M src/compiler/js-intrinsic-lowering.h
M src/compiler/js-intrinsic-lowering.cc
M src/runtime/runtime.h
M src/runtime/runtime-internal.cc
M test/cctest/compiler/test-run-intrinsics.cc
Index: src/compiler/access-builder.cc
diff --git a/src/compiler/access-builder.cc b/src/compiler/access-builder.cc
index
8a04603e5a1f0cf95cad3536775e3e9c4555b075..c69f22cb870fb7361774aa4322867555c3b61f08
100644
--- a/src/compiler/access-builder.cc
+++ b/src/compiler/access-builder.cc
@@ -83,6 +83,12 @@ FieldAccess AccessBuilder::ForContextSlot(size_t index) {
// static
+FieldAccess AccessBuilder::ForStatsCounter() {
+ return {kUntaggedBase, 0, MaybeHandle<Name>(), Type::Signed32(),
kMachInt32};
+}
+
+
+// static
ElementAccess AccessBuilder::ForFixedArrayElement() {
return {kTaggedBase, FixedArray::kHeaderSize, Type::Any(),
kMachAnyTagged};
}
Index: src/compiler/access-builder.h
diff --git a/src/compiler/access-builder.h b/src/compiler/access-builder.h
index
e46a0503aae2076273fbef231e5be1472c99007e..ddbad8c64e7f2b717f1756945f9d2a725a264420
100644
--- a/src/compiler/access-builder.h
+++ b/src/compiler/access-builder.h
@@ -46,6 +46,9 @@ class AccessBuilder FINAL : public AllStatic {
// Provides access Context slots.
static FieldAccess ForContextSlot(size_t index);
+ // Provides access to the backing store of a StatsCounter.
+ static FieldAccess ForStatsCounter();
+
// Provides access to FixedArray elements.
static ElementAccess ForFixedArrayElement();
Index: src/compiler/js-intrinsic-lowering.cc
diff --git a/src/compiler/js-intrinsic-lowering.cc
b/src/compiler/js-intrinsic-lowering.cc
index
6fcd00f2f5bc079900902bbc39631519deb68902..7253aab787780acfd51268090ec36b81ce558165
100644
--- a/src/compiler/js-intrinsic-lowering.cc
+++ b/src/compiler/js-intrinsic-lowering.cc
@@ -7,6 +7,7 @@
#include "src/compiler/access-builder.h"
#include "src/compiler/js-graph.h"
+#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties.h"
namespace v8 {
@@ -33,6 +34,8 @@ Reduction JSIntrinsicLowering::Reduce(Node* node) {
return ReduceDoubleLo(node);
case Runtime::kInlineHeapObjectGetMap:
return ReduceHeapObjectGetMap(node);
+ case Runtime::kInlineIncrementStatsCounter:
+ return ReduceIncrementStatsCounter(node);
case Runtime::kInlineIsArray:
return ReduceIsInstanceType(node, JS_ARRAY_TYPE);
case Runtime::kInlineIsFunction:
@@ -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(
Node* node, InstanceType instance_type) {
// if (%_IsSmi(value)) {
@@ -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(); }
Index: src/compiler/js-intrinsic-lowering.h
diff --git a/src/compiler/js-intrinsic-lowering.h
b/src/compiler/js-intrinsic-lowering.h
index
d4d1e477e3b2643bf5ef679e16f7eb0368dff6dd..35fb66147b1262a9883ce8eb162673d02c5d6a62
100644
--- a/src/compiler/js-intrinsic-lowering.h
+++ b/src/compiler/js-intrinsic-lowering.h
@@ -32,6 +32,7 @@ class JSIntrinsicLowering FINAL : public Reducer {
Reduction ReduceDoubleHi(Node* node);
Reduction ReduceDoubleLo(Node* node);
Reduction ReduceHeapObjectGetMap(Node* node);
+ Reduction ReduceIncrementStatsCounter(Node* node);
Reduction ReduceIsInstanceType(Node* node, InstanceType instance_type);
Reduction ReduceIsNonNegativeSmi(Node* node);
Reduction ReduceIsSmi(Node* node);
@@ -47,6 +48,7 @@ class JSIntrinsicLowering FINAL : public Reducer {
Reduction Change(Node* node, const Operator* op);
Reduction Change(Node* node, const Operator* op, Node* a, Node* b, Node*
c);
+ Reduction ChangeToUndefined(Node* node, Node* effect = nullptr);
Graph* graph() const;
JSGraph* jsgraph() const { return jsgraph_; }
Index: src/runtime/runtime-internal.cc
diff --git a/src/runtime/runtime-internal.cc
b/src/runtime/runtime-internal.cc
index
0f807be5b8008214a84354592f99128d4fb01ed7..973c204435f7ca24fa17541c1ab6e8219f6eaacb
100644
--- a/src/runtime/runtime-internal.cc
+++ b/src/runtime/runtime-internal.cc
@@ -318,5 +318,17 @@ RUNTIME_FUNCTION(Runtime_GetFromCache) {
args[0] = isolate->native_context()->jsfunction_result_caches()->get(id);
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
Index: src/runtime/runtime.h
diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h
index
903ea66984b4da1f4e736772f0dfb18a96425d70..c8f6e19df1061322e286933484eb259f30e331f0
100644
--- a/src/runtime/runtime.h
+++ b/src/runtime/runtime.h
@@ -87,6 +87,7 @@ namespace internal {
F(TryMigrateInstance, 1, 1) \
F(NotifyContextDisposed, 0, 1) \
F(ThrowIteratorResultNotAnObject, 1, 1) \
+ F(IncrementStatsCounter, 1, 1) \
\
/* Array join support */ \
F(PushIfAbsent, 2, 1) \
Index: test/cctest/compiler/test-run-intrinsics.cc
diff --git a/test/cctest/compiler/test-run-intrinsics.cc
b/test/cctest/compiler/test-run-intrinsics.cc
index
65a180c11a054c90df8faf6cda636f55a9359202..411d63da2de6d8cac14b0eb947889b8fbe11c4e8
100644
--- a/test/cctest/compiler/test-run-intrinsics.cc
+++ b/test/cctest/compiler/test-run-intrinsics.cc
@@ -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) {
FLAG_turbo_deoptimization = true;
FunctionTester T("(function(a) { return %_IsArray(a); })", flags);
--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.