summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2023-01-03 10:55:36 +0000
committer Nicolas Geoffray <ngeoffray@google.com> 2023-01-04 13:11:22 +0000
commit1a214cea72b9ea4a3125f0e920dbcc904dbd6dfa (patch)
treed2122203cbab675193c9286b558dd0da89d645a6
parent8b09deb0c9355ee650d9e2cdf729839e36de0bb9 (diff)
Deflake 141-class-unload.
With compiler optimizations, the object intended to stay alive can actually be reclaimed. Move the object to a static to avoid this behavior. Test: 141-class-unload --no-image Change-Id: I10fdb62094af80d1e8ccc6850fe91422b87236e7
-rw-r--r--test/141-class-unload/src/Main.java7
1 files changed, 4 insertions, 3 deletions
diff --git a/test/141-class-unload/src/Main.java b/test/141-class-unload/src/Main.java
index 3cfe0064fc..8031dbada8 100644
--- a/test/141-class-unload/src/Main.java
+++ b/test/141-class-unload/src/Main.java
@@ -147,7 +147,9 @@ public class Main {
public WeakReference<ClassLoader> classLoader;
}
- private static Pair testNoUnloadInstanceHelper(Constructor<?> constructor) throws Exception {
+ // Make the method not inline-able to prevent the compiler optimizing away the allocation.
+ private static Pair $noinline$testNoUnloadInstanceHelper(Constructor<?> constructor)
+ throws Exception {
ClassLoader loader = (ClassLoader) constructor.newInstance(
DEX_FILE, LIBRARY_SEARCH_PATH, ClassLoader.getSystemClassLoader());
Object o = testNoUnloadHelper(loader);
@@ -155,9 +157,8 @@ public class Main {
}
private static void testNoUnloadInstance(Constructor<?> constructor) throws Exception {
- Pair p = testNoUnloadInstanceHelper(constructor);
+ Pair p = $noinline$testNoUnloadInstanceHelper(constructor);
doUnloading();
- // If the class loader was unloded too early due to races, just pass the test.
boolean isNull = p.classLoader.get() == null;
System.out.println("loader null " + isNull);
}