diff --git a/test/hotspot/jtreg/compiler/codecache/CodeCacheFullCountTest.java b/test/hotspot/jtreg/compiler/codecache/CodeCacheFullCountTest.java
index 652d0b0b52695c0b61e30887686f72010f0e4c45..ff28c588b4c2b67eac35e9cb22967366334513a2 100644
--- a/test/hotspot/jtreg/compiler/codecache/CodeCacheFullCountTest.java
+++ b/test/hotspot/jtreg/compiler/codecache/CodeCacheFullCountTest.java
@@ -45,12 +45,20 @@ public class CodeCacheFullCountTest {
         }
     }
 
-    public static void wasteCodeCache()  throws Exception {
+    public static void wasteCodeCache() throws Throwable {
         URL url = CodeCacheFullCountTest.class.getProtectionDomain().getCodeSource().getLocation();
 
-        for (int i = 0; i < 500; i++) {
-            ClassLoader cl = new MyClassLoader(url);
-            refClass(cl.loadClass("SomeClass"));
+        try {
+            for (int i = 0; i < 500; i++) {
+                ClassLoader cl = new MyClassLoader(url);
+                refClass(cl.loadClass("SomeClass"));
+            }
+        } catch (Throwable t) {
+            // Expose the root cause of the Throwable instance.
+            while (t.getCause() != null) {
+                t = t.getCause();
+            }
+            throw t;
         }
     }
 
@@ -59,7 +67,7 @@ public class CodeCacheFullCountTest {
           "-XX:ReservedCodeCacheSize=2496k", "-XX:-UseCodeCacheFlushing", "CodeCacheFullCountTest", "WasteCodeCache");
         OutputAnalyzer oa = ProcessTools.executeProcess(pb);
         // Ignore adapter creation failures
-        if (oa.getExitValue() != 0 && !oa.getStderr().contains("Out of space in CodeCache for adapters")) {
+        if (oa.getExitValue() != 0 && !oa.getOutput().contains("Out of space in CodeCache for adapters")) {
             oa.reportDiagnosticSummary();
             throw new RuntimeException("VM finished with exit code " + oa.getExitValue());
         }