diff options
| author | 2017-03-30 02:56:32 +0000 | |
|---|---|---|
| committer | 2017-03-30 02:56:32 +0000 | |
| commit | cd59eb493ecb84f4ae32ca67c202a52378f6afd4 (patch) | |
| tree | 3b093786852fb1b8231db281c646b39a55517ca1 | |
| parent | b48064e8e4c3271bab104f7155ce2ecd52a30177 (diff) | |
| parent | b68e12c7d9e06e3b7f627bff097dba93d7b60bb4 (diff) | |
Merge "Do more GCs for test 141"
am: b68e12c7d9
Change-Id: I9767192431c17959104722ef7cfe6485902b4244
| -rw-r--r-- | test/141-class-unload/src/Main.java | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/test/141-class-unload/src/Main.java b/test/141-class-unload/src/Main.java index 595c70d0f6..7e8431fb52 100644 --- a/test/141-class-unload/src/Main.java +++ b/test/141-class-unload/src/Main.java @@ -59,7 +59,7 @@ public class Main { // Stop the JIT to ensure its threads and work queue are not keeping classes // artifically alive. stopJit(); - Runtime.getRuntime().gc(); + doUnloading(); System.runFinalization(); BufferedReader reader = new BufferedReader(new FileReader ("/proc/" + pid + "/maps")); String line; @@ -83,12 +83,20 @@ public class Main { } } + private static void doUnloading() { + // Do multiple GCs to prevent rare flakiness if some other thread is keeping the + // classloader live. + for (int i = 0; i < 5; ++i) { + Runtime.getRuntime().gc(); + } + } + private static void testUnloadClass(Constructor<?> constructor) throws Exception { WeakReference<Class> klass = setUpUnloadClassWeak(constructor); // No strong references to class loader, should get unloaded. - Runtime.getRuntime().gc(); + doUnloading(); WeakReference<Class> klass2 = setUpUnloadClassWeak(constructor); - Runtime.getRuntime().gc(); + doUnloading(); // If the weak reference is cleared, then it was unloaded. System.out.println(klass.get()); System.out.println(klass2.get()); @@ -98,7 +106,7 @@ public class Main { throws Exception { WeakReference<ClassLoader> loader = setUpUnloadLoader(constructor, true); // No strong references to class loader, should get unloaded. - Runtime.getRuntime().gc(); + doUnloading(); // If the weak reference is cleared, then it was unloaded. System.out.println(loader.get()); } @@ -110,7 +118,7 @@ public class Main { Throwable throwable = (Throwable) stackTraceMethod.invoke(klass); stackTraceMethod = null; klass = null; - Runtime.getRuntime().gc(); + doUnloading(); boolean isNull = weak_klass.get() == null; System.out.println("class null " + isNull + " " + throwable.getMessage()); } @@ -118,7 +126,7 @@ public class Main { private static void testLoadAndUnloadLibrary(Constructor<?> constructor) throws Exception { WeakReference<ClassLoader> loader = setUpLoadLibrary(constructor); // No strong references to class loader, should get unloaded. - Runtime.getRuntime().gc(); + doUnloading(); // If the weak reference is cleared, then it was unloaded. System.out.println(loader.get()); } @@ -147,7 +155,7 @@ public class Main { private static void testNoUnloadInstance(Constructor<?> constructor) throws Exception { Pair p = testNoUnloadInstanceHelper(constructor); - Runtime.getRuntime().gc(); + 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); |