diff options
author | android-build-prod (mdb) <android-build-team-robot@google.com> | 2020-01-16 18:42:03 +0000 |
---|---|---|
committer | android-build-prod (mdb) <android-build-team-robot@google.com> | 2020-01-16 18:42:03 +0000 |
commit | 39f6f72c471078320f12691f84e7ec0310e35af9 (patch) | |
tree | af65e0ff8698d66fbc494ade39e5db62827c01fa | |
parent | 8950c5f7af0df31caa754a4300f8b0eedfb04b37 (diff) | |
parent | 8ecb1371ffbfa14da182d0e6957e93a57a6f28d3 (diff) | |
download | art-39f6f72c471078320f12691f84e7ec0310e35af9.tar.gz |
Snap for 6139873 from 8ecb1371ffbfa14da182d0e6957e93a57a6f28d3 to pie-cts-releaseandroid-cts-9.0_r20android-cts-9.0_r19android-cts-9.0_r18android-cts-9.0_r17android-cts-9.0_r16android-cts-9.0_r15android-cts-9.0_r14android-cts-9.0_r13android-cts-9.0_r12android-cts-9.0_r11pie-cts-release
Change-Id: I0e51c1359c20c08d46677699fe4a6f008255ea26
-rw-r--r-- | test/906-iterate-heap/src/art/Test906.java | 73 |
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]; |