summaryrefslogtreecommitdiff
path: root/benchmarks
diff options
context:
space:
mode:
authorRichard Uhler <ruhler@google.com>2017-11-22 16:12:44 +0000
committerRichard Uhler <ruhler@google.com>2017-11-29 15:21:14 +0000
commit2953435e0c8bdfd26603ecfffdfd9c88ea0a5717 (patch)
tree377e309bde35643c588b69352333470a49e57c8f /benchmarks
parent1d1bd2ab71c847609e97016000ccafa3043f7b98 (diff)
Add VMDebug.getInstancesOfClasses API.
The API can be used to iterate over instances of a given type on the heap. The GetInstancesOfClassesBenchmark run on bullhead shows the run time of the API grows linearly in the number of classes, C, to get instances of and the number of total instances, N, allocated on the heap. C N=~2^18 N=~2^19 1 13ms 21ms 2 26ms 43ms 4 53ms 87ms Bug: 69729799 Test: art/test/testrunner/testrunner.py -t 099-vmdebug -b --host Change-Id: Iebc34e1b079e719a66bb93963c5315a0d24834b1
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/src/benchmarks/GetInstancesOfClassesBenchmark.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/benchmarks/src/benchmarks/GetInstancesOfClassesBenchmark.java b/benchmarks/src/benchmarks/GetInstancesOfClassesBenchmark.java
new file mode 100644
index 0000000000..2e85fae040
--- /dev/null
+++ b/benchmarks/src/benchmarks/GetInstancesOfClassesBenchmark.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package benchmarks;
+
+import dalvik.system.VMDebug;
+
+public class GetInstancesOfClassesBenchmark {
+ private static class ObjectTree {
+ ObjectTree left;
+ ObjectTree right;
+
+ public ObjectTree(int depth) {
+ if (depth > 1) {
+ left = new ObjectTree(depth - 1);
+ right = new ObjectTree(depth - 1);
+ }
+ }
+ }
+
+ // 2^19 = 524288
+ private static ObjectTree tree = new ObjectTree(19);
+
+ public void timeGetInstancesOf1Class(int reps) {
+ Class[] classes = new Class[]{
+ Integer.class
+ };
+ for (int rep = 0; rep < reps; ++rep) {
+ VMDebug.getInstancesOfClasses(classes, true);
+ }
+ }
+
+ public void timeGetInstancesOf2Classes(int reps) {
+ Class[] classes = new Class[]{
+ Integer.class,
+ Long.class
+ };
+ for (int rep = 0; rep < reps; ++rep) {
+ VMDebug.getInstancesOfClasses(classes, true);
+ }
+ }
+
+ public void timeGetInstancesOf4Classes(int reps) {
+ Class[] classes = new Class[]{
+ Integer.class,
+ Long.class,
+ Float.class,
+ Double.class
+ };
+ for (int rep = 0; rep < reps; ++rep) {
+ VMDebug.getInstancesOfClasses(classes, true);
+ }
+ }
+}