8204308: SA: serviceability/sa/TestInstanceKlassSize*.java fails when running in CDS mode
authorjgeorge
Mon, 27 Aug 2018 10:25:13 +0530
changeset 51531 948c62200f8c
parent 51530 1f0b605bdc28
child 51532 5f40be158613
child 56868 67c7659ecda5
8204308: SA: serviceability/sa/TestInstanceKlassSize*.java fails when running in CDS mode Summary: Use longs instead of ints while computing the identity hash of klass symbols Reviewed-by: coleenp, lfoltan
src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Symbol.java
src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/Hashtable.java
test/hotspot/jtreg/ProblemList-cds-mode.txt
test/hotspot/jtreg/ProblemList.txt
test/hotspot/jtreg/serviceability/sa/CDSJMapClstats.java
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Symbol.java	Sat Aug 25 11:10:21 2018 -0400
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/Symbol.java	Mon Aug 27 10:25:13 2018 +0530
@@ -80,15 +80,16 @@
   // _identity_hash is a short
   private static CIntegerField idHash;
 
-  public int identityHash() {
+  public long identityHash() {
     long addr_value = getAddress().asLongValue();
-    int  addr_bits = (int)(addr_value >> (VM.getVM().getLogMinObjAlignmentInBytes() + 3));
+    long addr_bits =
+      (addr_value >> (VM.getVM().getLogMinObjAlignmentInBytes() + 3)) & 0xffffffffL;
     int  length = (int)getLength();
     int  byte0 = getByteAt(0);
     int  byte1 = getByteAt(1);
-    int  id_hash = (int)(0xffff & idHash.getValue(this.addr));
-    return id_hash |
-           ((addr_bits ^ (length << 8) ^ ((byte0 << 8) | byte1)) << 16);
+    long id_hash = 0xffffL & (long)idHash.getValue(this.addr);
+    return (id_hash |
+      ((addr_bits ^ (length << 8) ^ ((byte0 << 8) | byte1)) << 16)) & 0xffffffffL;
   }
 
   public boolean equals(byte[] modUTF8Chars) {
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/Hashtable.java	Sat Aug 25 11:10:21 2018 -0400
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/Hashtable.java	Mon Aug 27 10:25:13 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -49,8 +49,8 @@
     return HashtableEntry.class;
   }
 
-  public int computeHash(Symbol name) {
-    return (int) name.identityHash();
+  public long computeHash(Symbol name) {
+    return name.identityHash();
   }
 
   public int hashToIndex(long fullHash) {
--- a/test/hotspot/jtreg/ProblemList-cds-mode.txt	Sat Aug 25 11:10:21 2018 -0400
+++ b/test/hotspot/jtreg/ProblemList-cds-mode.txt	Mon Aug 27 10:25:13 2018 +0530
@@ -27,5 +27,3 @@
 #
 #############################################################################
 
-serviceability/sa/TestInstanceKlassSize.java                    8204308   generic-all
-serviceability/sa/TestInstanceKlassSizeForInterface.java        8204308   generic-all
--- a/test/hotspot/jtreg/ProblemList.txt	Sat Aug 25 11:10:21 2018 -0400
+++ b/test/hotspot/jtreg/ProblemList.txt	Mon Aug 27 10:25:13 2018 +0530
@@ -92,6 +92,7 @@
 serviceability/sa/ClhsdbAttach.java 8193639 solaris-all
 serviceability/sa/ClhsdbCDSCore.java 8193639 solaris-all
 serviceability/sa/ClhsdbCDSJstackPrintAll.java 8193639 solaris-all
+serviceability/sa/CDSJMapClstats.java 8193639 solaris-all
 serviceability/sa/ClhsdbField.java 8193639 solaris-all
 serviceability/sa/ClhsdbFindPC.java 8193639 solaris-all
 serviceability/sa/ClhsdbFlags.java 8193639 solaris-all
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/serviceability/sa/CDSJMapClstats.java	Mon Aug 27 10:25:13 2018 +0530
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8204308
+ * @summary Test the jhsdb jmap -clstats command with CDS enabled
+ * @requires vm.hasSAandCanAttach & vm.cds
+ * @library /test/lib
+ * @run main/othervm/timeout=2400 CDSJMapClstats
+ */
+
+import java.util.List;
+import java.util.Arrays;
+import java.util.stream.Collectors;
+import jdk.test.lib.cds.CDSTestUtils;
+import jdk.test.lib.cds.CDSOptions;
+import jdk.test.lib.apps.LingeredApp;
+import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.JDKToolLauncher;
+
+public class CDSJMapClstats {
+
+    private static void runClstats(long lingeredAppPid) throws Exception {
+
+        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+        launcher.addToolArg("jmap");
+        launcher.addToolArg("--clstats");
+        launcher.addToolArg("--pid");
+        launcher.addToolArg(Long.toString(lingeredAppPid));
+
+        ProcessBuilder processBuilder = new ProcessBuilder();
+        processBuilder.command(launcher.getCommand());
+        System.out.println(
+            processBuilder.command().stream().collect(Collectors.joining(" ")));
+
+        OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder);
+        System.out.println(SAOutput.getOutput());
+        SAOutput.shouldHaveExitValue(0);
+        SAOutput.shouldContain("BootClassLoader");
+    }
+
+
+    public static void main(String[] args) throws Exception {
+        System.out.println("Starting CDSJMapClstats test");
+        String sharedArchiveName = "ArchiveForCDSJMapClstats.jsa";
+        LingeredApp theApp = null;
+
+        try {
+            CDSOptions opts = (new CDSOptions()).setArchiveName(sharedArchiveName);
+            CDSTestUtils.createArchiveAndCheck(opts);
+
+            List<String> vmArgs = Arrays.asList(
+                "-XX:+UnlockDiagnosticVMOptions",
+                "-XX:SharedArchiveFile=" + sharedArchiveName,
+                "-Xshare:auto");
+            theApp = LingeredApp.startApp(vmArgs);
+            System.out.println("Started LingeredApp with pid " + theApp.getPid());
+            runClstats(theApp.getPid());
+        } catch (Exception ex) {
+            throw new RuntimeException("Test ERROR " + ex, ex);
+        } finally {
+            LingeredApp.stopApp(theApp);
+        }
+        System.out.println("Test PASSED");
+    }
+}