diff options
author | 2019-07-23 13:10:20 -0700 | |
---|---|---|
committer | 2019-08-13 17:54:27 +0000 | |
commit | 72d7e94d70923c5ff4cbe947117801583eae4672 (patch) | |
tree | cde1932ed801dc7f388b56282d3e2bca000e428a /test/1974-resize-array/src | |
parent | f1bb75abb38609d72648e03eefac7320b5e804b4 (diff) |
Add obsolete object event
Add an extension event to notify agents that an object is becoming
obsolete. This is meant to be used by agents performing allocation
tracking using the VMObjectAlloc event to let them know that an object
replacement is occurring. This event is only triggered by calls to
JVMTI functions that create obsolete objects. Normal GC actions
(including a moving compaction) will not cause this event to trigger.
Test: ./test.py --host
Bug: 134162467
Change-Id: If48b880814a751ba6c24c18d0ad116db4f8fdf64
Diffstat (limited to 'test/1974-resize-array/src')
-rw-r--r-- | test/1974-resize-array/src/art/Test1974.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/1974-resize-array/src/art/Test1974.java b/test/1974-resize-array/src/art/Test1974.java index 8460e827eb..c4427c7b62 100644 --- a/test/1974-resize-array/src/art/Test1974.java +++ b/test/1974-resize-array/src/art/Test1974.java @@ -422,6 +422,56 @@ public class Test1974 { System.out.println("Same value? " + (after_tagged_obj[0] == arr)); } + public static void runWithJvmtiTagsObsolete() throws Exception { + Object[] arr = new Object[] {"4", "44", "444"}; + long globalID = 444_444_444l; + System.out.println("Test jvmti-tags with obsolete"); + Main.setTag(arr, globalID); + StartCollectFrees(); + StartAssignObsoleteIncrementedId(); + DbgPrintln("Pre hash: " + arr.hashCode()); + System.out.println( + "val is: " + Arrays.deepToString(GetObjectsWithTag(globalID)) + " resize +5"); + ResizeArray(() -> arr, arr.length + 5); + Object[] after_tagged_obj = GetObjectsWithTag(globalID); + Object[] obsolete_tagged_obj = GetObjectsWithTag(globalID + 1); + System.out.println("val is: " + Arrays.deepToString(GetObjectsWithTag(globalID))); + EndAssignObsoleteIncrementedId(); + long[] obsoletes_freed = CollectFreedTags(); + DbgPrintln("Post hash: " + after_tagged_obj[0].hashCode()); + System.out.println("Same value? " + (after_tagged_obj[0] == arr)); + if (obsolete_tagged_obj.length >= 1) { + DbgPrintln("Found objects with obsolete tag: " + Arrays.deepToString(obsolete_tagged_obj)); + boolean bad = false; + if (obsolete_tagged_obj.length != 1) { + System.out.println( + "Found obsolete tag'd objects: " + + Arrays.deepHashCode(obsolete_tagged_obj) + + " but only expected one!"); + bad = true; + } + if (!Arrays.deepEquals( + Arrays.copyOf(arr, ((Object[]) obsolete_tagged_obj[0]).length), + (Object[]) obsolete_tagged_obj[0])) { + System.out.println("Obsolete array was unexpectedly different than non-obsolete one!"); + bad = true; + } + if (!Arrays.stream(obsoletes_freed).anyMatch((l) -> l == globalID + 1)) { + DbgPrintln("Didn't see a free of the obsolete id"); + } + if (!bad) { + System.out.println("Everything looks good WRT obsolete object"); + } + } else { + if (!Arrays.stream(obsoletes_freed).anyMatch((l) -> l == globalID + 1)) { + System.out.println("Didn't see a free of the obsolete id"); + } else { + DbgPrintln("Saw a free of obsolete id!"); + System.out.println("Everything looks good WRT obsolete object!"); + } + } + } + public static void run() throws Exception { // Simple runAsThread(Test1974::runInstance); @@ -457,6 +507,9 @@ public class Test1974 { // Basic jvmti tags runAsThread(Test1974::runWithJvmtiTags); + + // Grab obsolete reference using tags/detect free + runAsThread(Test1974::runWithJvmtiTagsObsolete); } // Use a supplier so that we don't have to have a local ref to the resized @@ -470,4 +523,12 @@ public class Test1974 { public static native <T> T ReadJniRef(long t); public static native Object[] GetObjectsWithTag(long tag); + + public static native void StartCollectFrees(); + + public static native void StartAssignObsoleteIncrementedId(); + + public static native void EndAssignObsoleteIncrementedId(); + + public static native long[] CollectFreedTags(); } |