8191362: [Graal] gc/g1/TestShrinkAuxiliaryData tests crash with "assert(check_klass_alignment(result)) failed: address not aligned"
Summary: Graal does not respect ObjectAlignmentInBytes VM option.
Reviewed-by: kvn
--- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java Tue Jan 09 22:30:20 2018 -0500
+++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java Wed Jan 10 09:04:11 2018 +0100
@@ -34,7 +34,6 @@
import java.util.Objects;
import jdk.vm.ci.code.CodeUtil;
-import jdk.vm.ci.code.TargetDescription;
import jdk.vm.ci.common.JVMCIError;
import jdk.vm.ci.meta.DeoptimizationAction;
import jdk.vm.ci.meta.DeoptimizationReason;
@@ -284,11 +283,9 @@
ResolvedJavaType elementType = lookupJavaType.getComponentType();
JavaKind elementKind = elementType.getJavaKind();
final int headerSize = getArrayBaseOffset(elementKind);
- TargetDescription target = runtime.getHostJVMCIBackend().getTarget();
int sizeOfElement = getArrayIndexScale(elementKind);
- int alignment = target.wordSize;
int log2ElementSize = CodeUtil.log2(sizeOfElement);
- return computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize);
+ return computeArrayAllocationSize(length, headerSize, log2ElementSize);
}
return lookupJavaType.instanceSize();
}
@@ -303,11 +300,13 @@
* alignment requirements.
*
* @param length the number of elements in the array
- * @param alignment the object alignment requirement
* @param headerSize the size of the array header
* @param log2ElementSize log2 of the size of an element in the array
+ * @return the size of the memory chunk
*/
- public static int computeArrayAllocationSize(int length, int alignment, int headerSize, int log2ElementSize) {
+ public int computeArrayAllocationSize(int length, int headerSize, int log2ElementSize) {
+ HotSpotVMConfig config = runtime.getConfig();
+ int alignment = config.objectAlignment;
int size = (length << log2ElementSize) + headerSize + (alignment - 1);
int mask = ~(alignment - 1);
return size & mask;
--- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfig.java Tue Jan 09 22:30:20 2018 -0500
+++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfig.java Wed Jan 10 09:04:11 2018 +0100
@@ -68,6 +68,8 @@
final boolean useCompressedOops = getFlag("UseCompressedOops", Boolean.class);
+ final int objectAlignment = getFlag("ObjectAlignmentInBytes", Integer.class);
+
final int prototypeMarkWordOffset = getFieldOffset("Klass::_prototype_header", Integer.class, "markOop");
final int subklassOffset = getFieldOffset("Klass::_subklass", Integer.class, "Klass*");
final int nextSiblingOffset = getFieldOffset("Klass::_next_sibling", Integer.class, "Klass*");
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/HotSpotReplacementsUtil.java Tue Jan 09 22:30:20 2018 -0500
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/HotSpotReplacementsUtil.java Wed Jan 10 09:04:11 2018 +0100
@@ -566,6 +566,28 @@
}
@Fold
+ public static int objectAlignment(@InjectedParameter GraalHotSpotVMConfig config) {
+ return config.objectAlignment;
+ }
+
+ /**
+ * Computes the size of the memory chunk allocated for an array. This size accounts for the
+ * array header size, body size and any padding after the last element to satisfy object
+ * alignment requirements.
+ *
+ * @param length the number of elements in the array
+ * @param headerSize the size of the array header
+ * @param log2ElementSize log2 of the size of an element in the array
+ * @return the size of the memory chunk
+ */
+ public static int arrayAllocationSize(int length, int headerSize, int log2ElementSize) {
+ int alignment = objectAlignment(INJECTED_VMCONFIG);
+ int size = (length << log2ElementSize) + headerSize + (alignment - 1);
+ int mask = ~(alignment - 1);
+ return size & mask;
+ }
+
+ @Fold
public static int instanceHeaderSize(@InjectedParameter GraalHotSpotVMConfig config) {
return config.useCompressedClassPointers ? (2 * wordSize()) - 4 : 2 * wordSize();
}
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/NewObjectSnippets.java Tue Jan 09 22:30:20 2018 -0500
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/NewObjectSnippets.java Wed Jan 10 09:04:11 2018 +0100
@@ -23,7 +23,6 @@
package org.graalvm.compiler.hotspot.replacements;
import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider.getArrayBaseOffset;
-import static jdk.vm.ci.hotspot.HotSpotMetaAccessProvider.computeArrayAllocationSize;
import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
import static org.graalvm.compiler.core.common.calc.UnsignedMath.belowThan;
import static org.graalvm.compiler.hotspot.GraalHotSpotVMConfig.INJECTED_VMCONFIG;
@@ -33,6 +32,7 @@
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.PROTOTYPE_MARK_WORD_LOCATION;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.TLAB_END_LOCATION;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.TLAB_TOP_LOCATION;
+import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayAllocationSize;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayKlassOffset;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayLengthOffset;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.config;
@@ -52,7 +52,6 @@
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.useBiasedLocking;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.useTLAB;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.verifyOop;
-import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.wordSize;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.writeTlabTop;
import static org.graalvm.compiler.hotspot.replacements.HotspotSnippetsOptions.ProfileAllocations;
import static org.graalvm.compiler.hotspot.replacements.HotspotSnippetsOptions.ProfileAllocationsContext;
@@ -315,8 +314,7 @@
private static Object allocateArrayImpl(KlassPointer hub, int length, Word prototypeMarkWord, int headerSize, int log2ElementSize, boolean fillContents, Register threadRegister,
boolean maybeUnroll, String typeContext, boolean skipNegativeCheck, OptionValues options, Counters counters) {
Object result;
- int alignment = wordSize();
- int allocationSize = computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize);
+ int allocationSize = arrayAllocationSize(length, headerSize, log2ElementSize);
Word thread = registerAsWord(threadRegister);
Word top = readTlabTop(thread);
Word end = readTlabEnd(thread);
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/stubs/NewArrayStub.java Tue Jan 09 22:30:20 2018 -0500
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/stubs/NewArrayStub.java Wed Jan 10 09:04:11 2018 +0100
@@ -23,6 +23,7 @@
package org.graalvm.compiler.hotspot.stubs;
import static org.graalvm.compiler.hotspot.GraalHotSpotVMConfig.INJECTED_VMCONFIG;
+import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayAllocationSize;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayPrototypeMarkWord;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.getAndClearObjectResult;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperElementTypeMask;
@@ -34,7 +35,6 @@
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.readLayoutHelper;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.useCMSIncrementalMode;
-import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.wordSize;
import static org.graalvm.compiler.hotspot.replacements.NewObjectSnippets.MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH;
import static org.graalvm.compiler.hotspot.replacements.NewObjectSnippets.formatArray;
import static org.graalvm.compiler.hotspot.stubs.NewInstanceStub.refillAllocate;
@@ -42,7 +42,6 @@
import static org.graalvm.compiler.hotspot.stubs.StubUtil.newDescriptor;
import static org.graalvm.compiler.hotspot.stubs.StubUtil.printf;
import static org.graalvm.compiler.hotspot.stubs.StubUtil.verifyObject;
-import static jdk.vm.ci.hotspot.HotSpotMetaAccessProvider.computeArrayAllocationSize;
import org.graalvm.compiler.api.replacements.Fold;
import org.graalvm.compiler.api.replacements.Snippet;
@@ -112,7 +111,7 @@
int log2ElementSize = (layoutHelper >> layoutHelperLog2ElementSizeShift(INJECTED_VMCONFIG)) & layoutHelperLog2ElementSizeMask(INJECTED_VMCONFIG);
int headerSize = (layoutHelper >> layoutHelperHeaderSizeShift(INJECTED_VMCONFIG)) & layoutHelperHeaderSizeMask(INJECTED_VMCONFIG);
int elementKind = (layoutHelper >> layoutHelperElementTypeShift(INJECTED_VMCONFIG)) & layoutHelperElementTypeMask(INJECTED_VMCONFIG);
- int sizeInBytes = computeArrayAllocationSize(length, wordSize(), headerSize, log2ElementSize);
+ int sizeInBytes = arrayAllocationSize(length, headerSize, log2ElementSize);
if (logging(options)) {
printf("newArray: element kind %d\n", elementKind);
printf("newArray: array length %d\n", length);