changeset 52091:b25bfa10f52f

8212005: Epsilon elastic TLAB sizing may cause misalignment Reviewed-by: rkennke, tschatzl
author shade
date Thu, 11 Oct 2018 10:42:17 +0200
parents b698138cf69b
children 4cffba2df537
files src/hotspot/share/gc/epsilon/epsilonHeap.cpp test/hotspot/jtreg/gc/epsilon/TestAlignment.java
diffstat 2 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/epsilon/epsilonHeap.cpp	Wed Oct 10 16:56:18 2018 +0200
+++ b/src/hotspot/share/gc/epsilon/epsilonHeap.cpp	Thu Oct 11 10:42:17 2018 +0200
@@ -118,6 +118,8 @@
 }
 
 HeapWord* EpsilonHeap::allocate_work(size_t size) {
+  assert(is_object_aligned(size), "Allocation size should be aligned: " SIZE_FORMAT, size);
+
   HeapWord* res = _space->par_allocate(size);
 
   while (res == NULL) {
@@ -168,6 +170,7 @@
     }
   }
 
+  assert(is_object_aligned(res), "Object should be aligned: " PTR_FORMAT, p2i(res));
   return res;
 }
 
@@ -211,6 +214,9 @@
   // Always honor boundaries
   size = MAX2(min_size, MIN2(_max_tlab_size, size));
 
+  // Always honor alignment
+  size = align_up(size, MinObjAlignment);
+
   if (log_is_enabled(Trace, gc)) {
     ResourceMark rm;
     log_trace(gc)("TLAB size for \"%s\" (Requested: " SIZE_FORMAT "K, Min: " SIZE_FORMAT
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/gc/epsilon/TestAlignment.java	Thu Oct 11 10:42:17 2018 +0200
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2018, Red Hat, Inc. 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 TestAlignment
+ * @key gc
+ * @requires vm.gc.Epsilon & !vm.graal.enabled
+ * @summary Check Epsilon runs fine with (un)usual alignments
+ * @bug 8212005
+ * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:+UseTLAB TestAlignment
+ * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:-UseTLAB TestAlignment
+ * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:+UseTLAB -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 TestAlignment
+ * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xmx128m -XX:+UseEpsilonGC -XX:-UseTLAB -XX:+IgnoreUnrecognizedVMOptions -XX:ObjectAlignmentInBytes=16 TestAlignment
+ */
+
+public class TestAlignment {
+    static Object sink;
+
+    public static void main(String[] args) throws Exception {
+        for (int c = 0; c < 1000; c++) {
+            sink = new byte[c];
+        }
+    }
+}