changeset 59320:a95911422005

8244536: cds/DeterministicDump.java failed: File content different Reviewed-by: ccheung, stuefe
author iklam
date Sun, 17 May 2020 15:10:06 -0700
parents d652d9aaf286
children 140c5adcabdd
files src/hotspot/share/memory/filemap.cpp src/hotspot/share/memory/heapShared.hpp test/hotspot/jtreg/ProblemList.txt test/hotspot/jtreg/runtime/cds/DeterministicDump.java
diffstat 4 files changed, 64 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/memory/filemap.cpp	Sun May 17 21:15:33 2020 +0100
+++ b/src/hotspot/share/memory/filemap.cpp	Sun May 17 15:10:06 2020 -0700
@@ -207,16 +207,16 @@
   _alignment = alignment;
   _obj_alignment = ObjectAlignmentInBytes;
   _compact_strings = CompactStrings;
-  _narrow_oop_mode = CompressedOops::mode();
-  _narrow_oop_base = CompressedOops::base();
-  _narrow_oop_shift = CompressedOops::shift();
+  if (HeapShared::is_heap_object_archiving_allowed()) {
+    _narrow_oop_mode = CompressedOops::mode();
+    _narrow_oop_base = CompressedOops::base();
+    _narrow_oop_shift = CompressedOops::shift();
+    _heap_end = CompressedOops::end();
+  }
   _compressed_oops = UseCompressedOops;
   _compressed_class_ptrs = UseCompressedClassPointers;
   _max_heap_size = MaxHeapSize;
   _narrow_klass_shift = CompressedKlassPointers::shift();
-  if (HeapShared::is_heap_object_archiving_allowed()) {
-    _heap_end = CompressedOops::end();
-  }
 
   // The following fields are for sanity checks for whether this archive
   // will function correctly with this JVM and the bootclasspath it's
--- a/src/hotspot/share/memory/heapShared.hpp	Sun May 17 21:15:33 2020 +0100
+++ b/src/hotspot/share/memory/heapShared.hpp	Sun May 17 15:10:06 2020 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, 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
@@ -141,7 +141,8 @@
   }
 
   static unsigned klass_hash(Klass* const& klass) {
-    return primitive_hash<address>((address)klass);
+    // Generate deterministic hashcode even if SharedBaseAddress is changed due to ASLR.
+    return primitive_hash<address>(address(klass) - SharedBaseAddress);
   }
 
   class DumpTimeKlassSubGraphInfoTable
--- a/test/hotspot/jtreg/ProblemList.txt	Sun May 17 21:15:33 2020 +0100
+++ b/test/hotspot/jtreg/ProblemList.txt	Sun May 17 15:10:06 2020 -0700
@@ -95,7 +95,6 @@
 
 runtime/jni/terminatedThread/TestTerminatedThread.java 8219652 aix-ppc64
 runtime/ReservedStack/ReservedStackTest.java 8231031 generic-all
-runtime/cds/DeterministicDump.java 8244536 windows-all 
 
 #############################################################################
 
--- a/test/hotspot/jtreg/runtime/cds/DeterministicDump.java	Sun May 17 21:15:33 2020 +0100
+++ b/test/hotspot/jtreg/runtime/cds/DeterministicDump.java	Sun May 17 15:10:06 2020 -0700
@@ -36,37 +36,67 @@
 import jdk.test.lib.process.OutputAnalyzer;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.util.ArrayList;
 
 public class DeterministicDump {
     public static void main(String[] args) throws Exception {
-        for (int c = 0; c < 2; c++) { //  oop/klass compression
-            String sign = (c == 0) ?  "+" : "-";
-            String coop = "-XX:" + sign + "UseCompressedOops";
-            String ckls = "-XX:" + sign + "UseCompressedClassPointers";
+        doTest(false);
 
-            if (!Platform.is64bit()) {
-                coop = "-showversion"; // no-op
-                ckls = "-showversion"; // no-op
-            }
+        if (Platform.is64bit()) {
+            // There's no oop/klass compression on 32-bit.
+            doTest(true);
+        }
+    }
 
-            for (int gc = 0; gc < 2; gc++) { // should we trigger GC during dump
-                for (int i = 0; i < 2; i++) {
-                    String metaspaceSize = "-showversion"; // no-op
-                    if (gc == 1 && i == 1) {
-                        // This will cause GC to happen after we've allocated 1MB of metaspace objects
-                        // while processing the built-in SharedClassListFile.
-                        metaspaceSize = "-XX:MetaspaceSize=1M";
-                    }
-                    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-                                      coop, ckls, metaspaceSize,
-                                      "-XX:SharedArchiveFile=SharedArchiveFile" + i + ".jsa",
-                                      "-Xshare:dump", "-Xlog:cds=debug");
-                    OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "SharedArchiveFile" + i);
-                    CDSTestUtils.checkDump(out);
-                }
-                compare("SharedArchiveFile0.jsa", "SharedArchiveFile1.jsa");
-            }
+    public static void doTest(boolean compressed) throws Exception {
+        ArrayList<String> baseArgs = new ArrayList<>();
+
+        // Use the same heap size as make/Images.gmk
+        baseArgs.add("-Xmx128M");
+
+        if (Platform.is64bit()) {
+            // These options are available only on 64-bit.
+            String sign = (compressed) ?  "+" : "-";
+            baseArgs.add("-XX:" + sign + "UseCompressedOops");
+            baseArgs.add("-XX:" + sign + "UseCompressedClassPointers");
         }
+
+        String baseArchive = dump(baseArgs);
+
+        // (1) Dump with the same args. Should produce the same archive.
+        String baseArchive2 = dump(baseArgs);
+        compare(baseArchive, baseArchive2);
+
+
+        // (2) This will cause GC to happen after we've allocated 1MB of metaspace objects
+        // while processing the built-in SharedClassListFile.
+        String withGCArchive = dump(baseArgs, "-XX:MetaspaceSize=1M");
+        compare(baseArchive, withGCArchive);
+
+        // (3) This will cause archive to be relocated during dump time. We should
+        //     still get the same bits. (This simulates relocation that happens when
+        //     Address Space Layout Randomization prevents the archive space to
+        //     be mapped at the default location)
+        String relocatedArchive = dump(baseArgs, "-XX:+UnlockDiagnosticVMOptions", "-XX:ArchiveRelocationMode=1");
+        compare(baseArchive, relocatedArchive);
+    }
+
+    static int id = 0;
+    static String dump(ArrayList<String> args, String... more) throws Exception {
+        String logName = "SharedArchiveFile" + (id++);
+        String archiveName = logName + ".jsa";
+        args = (ArrayList<String>)args.clone();
+        args.add("-XX:SharedArchiveFile=" + archiveName);
+        args.add("-Xshare:dump");
+        args.add("-Xlog:cds=debug");
+        for (String m : more) {
+            args.add(m);
+        }
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
+        OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, logName);
+        CDSTestUtils.checkDump(out);
+
+        return archiveName;
     }
 
     static void compare(String file0, String file1) throws Exception {