# HG changeset patch # User shade # Date 1539182810 -7200 # Wed Oct 10 16:46:50 2018 +0200 # Node ID 7eb8b7d1931f8a606ae071164cf4df6de3e81177 # Parent f8626bcc169813a4b2a15880386b952719d1d6d1 8212005: Epsilon elastic TLAB sizing may cause misalignment Reviewed-by: XXX diff --git a/src/hotspot/share/gc/epsilon/epsilonHeap.cpp b/src/hotspot/share/gc/epsilon/epsilonHeap.cpp --- a/src/hotspot/share/gc/epsilon/epsilonHeap.cpp +++ b/src/hotspot/share/gc/epsilon/epsilonHeap.cpp @@ -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 diff --git a/test/hotspot/jtreg/gc/epsilon/TestAlignment.java b/test/hotspot/jtreg/gc/epsilon/TestAlignment.java new file mode 100644 --- /dev/null +++ b/test/hotspot/jtreg/gc/epsilon/TestAlignment.java @@ -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]; + } + } +}