summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-prod (mdb) <android-build-team-robot@google.com>2020-01-16 18:42:03 +0000
committerandroid-build-prod (mdb) <android-build-team-robot@google.com>2020-01-16 18:42:03 +0000
commit39f6f72c471078320f12691f84e7ec0310e35af9 (patch)
treeaf65e0ff8698d66fbc494ade39e5db62827c01fa
parent8950c5f7af0df31caa754a4300f8b0eedfb04b37 (diff)
parent8ecb1371ffbfa14da182d0e6957e93a57a6f28d3 (diff)
downloadart-pie-cts-release.tar.gz
Change-Id: I0e51c1359c20c08d46677699fe4a6f008255ea26
-rw-r--r--test/906-iterate-heap/src/art/Test906.java73
1 files changed, 46 insertions, 27 deletions
diff --git a/test/906-iterate-heap/src/art/Test906.java b/test/906-iterate-heap/src/art/Test906.java
index 65c2c8c560..be9663a6d4 100644
--- a/test/906-iterate-heap/src/art/Test906.java
+++ b/test/906-iterate-heap/src/art/Test906.java
@@ -24,6 +24,51 @@ public class Test906 {
doTest();
}
+ // Number of times we will try to count the heap in various ways. If we are unlucky and end up in
+ // the middle of a GC we could incorrectly fail. This is expected to be incredibly rare so 10
+ // retries should be more than sufficient.
+ private static final int ITERATE_RETRIES = 10;
+ private static void testHeapCount() throws Exception {
+ IllegalStateException lastThrow = new IllegalStateException(
+ "Failed to get consistent counts after " + ITERATE_RETRIES + " retries");
+ for (int i = 0; i < ITERATE_RETRIES; i++) {
+ try {
+ int all = iterateThroughHeapCount(0, null, Integer.MAX_VALUE);
+ int tagged = iterateThroughHeapCount(HEAP_FILTER_OUT_UNTAGGED, null, Integer.MAX_VALUE);
+ int untagged = iterateThroughHeapCount(HEAP_FILTER_OUT_TAGGED, null, Integer.MAX_VALUE);
+ int taggedClass = iterateThroughHeapCount(HEAP_FILTER_OUT_CLASS_UNTAGGED, null,
+ Integer.MAX_VALUE);
+ int untaggedClass = iterateThroughHeapCount(HEAP_FILTER_OUT_CLASS_TAGGED, null,
+ Integer.MAX_VALUE);
+
+ if (all != tagged + untagged) {
+ throw new IllegalStateException("Instances: " + all + " != " + tagged + " + " + untagged);
+ }
+ if (all != taggedClass + untaggedClass) {
+ throw new IllegalStateException("By class: " + all + " != " + taggedClass + " + " +
+ untaggedClass);
+ }
+ if (tagged != 6) {
+ throw new IllegalStateException(tagged + " tagged objects");
+ }
+ if (taggedClass != 2) {
+ throw new IllegalStateException(tagged + " objects with tagged class");
+ }
+ if (all == tagged) {
+ throw new IllegalStateException("All objects tagged");
+ }
+ if (all == taggedClass) {
+ throw new IllegalStateException("All objects have tagged class");
+ }
+ // Everything worked!
+ return;
+ } catch (IllegalStateException e) {
+ lastThrow.addSuppressed(e);
+ }
+ }
+ throw lastThrow;
+ }
+
public static void doTest() throws Exception {
A a = new A();
B b = new B();
@@ -39,33 +84,7 @@ public class Test906 {
setTag(s, 5);
setTag(B.class, 100);
- int all = iterateThroughHeapCount(0, null, Integer.MAX_VALUE);
- int tagged = iterateThroughHeapCount(HEAP_FILTER_OUT_UNTAGGED, null, Integer.MAX_VALUE);
- int untagged = iterateThroughHeapCount(HEAP_FILTER_OUT_TAGGED, null, Integer.MAX_VALUE);
- int taggedClass = iterateThroughHeapCount(HEAP_FILTER_OUT_CLASS_UNTAGGED, null,
- Integer.MAX_VALUE);
- int untaggedClass = iterateThroughHeapCount(HEAP_FILTER_OUT_CLASS_TAGGED, null,
- Integer.MAX_VALUE);
-
- if (all != tagged + untagged) {
- throw new IllegalStateException("Instances: " + all + " != " + tagged + " + " + untagged);
- }
- if (all != taggedClass + untaggedClass) {
- throw new IllegalStateException("By class: " + all + " != " + taggedClass + " + " +
- untaggedClass);
- }
- if (tagged != 6) {
- throw new IllegalStateException(tagged + " tagged objects");
- }
- if (taggedClass != 2) {
- throw new IllegalStateException(tagged + " objects with tagged class");
- }
- if (all == tagged) {
- throw new IllegalStateException("All objects tagged");
- }
- if (all == taggedClass) {
- throw new IllegalStateException("All objects have tagged class");
- }
+ testHeapCount();
long classTags[] = new long[100];
long sizes[] = new long[100];