changeset 52967:a2500cf11ee5

8213323: sa/TestJmapCoreMetaspace.java and sa/TestJmapCore.java fail with ZGC Summary: Avoid creating the hprof file and throw an exception in HeapHprofBinWriter for ZGC and handle this in the TestJmap* testcases Reviewed-by: gadams, jcbeyler, cjplummer
author jgeorge
date Tue, 04 Dec 2018 11:10:19 +0530
parents 7edc56620d42
children ff04b71bf6f1
files src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/JMap.java src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java test/hotspot/jtreg/serviceability/sa/TestJmapCore.java
diffstat 3 files changed, 26 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/JMap.java	Mon Dec 03 19:47:37 2018 -0800
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/JMap.java	Tue Dec 04 11:10:19 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -182,7 +182,7 @@
             hgw.write(fileName);
             System.out.println("heap written to " + fileName);
             return true;
-        } catch (IOException exp) {
+        } catch (IOException | RuntimeException exp) {
             System.err.println(exp.getMessage());
             return false;
         }
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java	Mon Dec 03 19:47:37 2018 -0800
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java	Tue Dec 04 11:10:19 2018 +0530
@@ -32,6 +32,7 @@
 import sun.jvm.hotspot.oops.*;
 import sun.jvm.hotspot.runtime.*;
 import sun.jvm.hotspot.classfile.*;
+import sun.jvm.hotspot.gc.z.ZCollectedHeap;
 
 /*
  * This class writes Java heap in hprof binary format. This format is
@@ -388,11 +389,15 @@
     }
 
     public synchronized void write(String fileName) throws IOException {
+        VM vm = VM.getVM();
+        if (vm.getUniverse().heap() instanceof ZCollectedHeap) {
+            throw new RuntimeException("This operation is not supported with ZGC.");
+        }
+
         // open file stream and create buffered data output stream
         fos = new FileOutputStream(fileName);
         out = new DataOutputStream(new BufferedOutputStream(fos));
 
-        VM vm = VM.getVM();
         dbg = vm.getDebugger();
         objectHeap = vm.getObjectHeap();
 
--- a/test/hotspot/jtreg/serviceability/sa/TestJmapCore.java	Mon Dec 03 19:47:37 2018 -0800
+++ b/test/hotspot/jtreg/serviceability/sa/TestJmapCore.java	Tue Dec 04 11:10:19 2018 +0530
@@ -37,6 +37,7 @@
 import jdk.test.lib.hprof.HprofParser;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.Utils;
 import jtreg.SkippedException;
 
 import java.io.File;
@@ -134,10 +135,24 @@
         System.out.println(out.getStdout());
         System.err.println(out.getStderr());
 
-        Asserts.assertTrue(dumpFile.exists() && dumpFile.isFile(),
-                "Could not find dump file " + dumpFile.getAbsolutePath());
+        if (dumpFile.exists() && dumpFile.isFile()) {
+            HprofParser.parse(dumpFile);
+        } else {
+            boolean ZGCUsed = false;
 
-        HprofParser.parse(dumpFile);
+            for (String opt: Utils.getFilteredTestJavaOpts()) {
+                if (opt.contains("+UseZGC")) {
+                    ZGCUsed = true;
+                    break;
+                }
+            }
+
+            if (!ZGCUsed) {
+                throw new RuntimeException(
+                    "Could not find dump file " + dumpFile.getAbsolutePath());
+            }
+        }
+
         System.out.println("PASSED");
     }
 }