8191362: [Graal] gc/g1/TestShrinkAuxiliaryData tests crash with "assert(check_klass_alignment(result)) failed: address not aligned"
Graal does not respect ObjectAlignmentInBytes VM option. Reviewed-by: kvn
This commit is contained in:
parent
ae186c5714
commit
15ef7c04a2
@ -34,7 +34,6 @@ import java.lang.reflect.Modifier;
|
||||
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 @@ public class HotSpotMetaAccessProvider implements MetaAccessProvider {
|
||||
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 @@ public class HotSpotMetaAccessProvider implements MetaAccessProvider {
|
||||
* 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;
|
||||
|
@ -68,6 +68,8 @@ class HotSpotVMConfig extends HotSpotVMConfigAccess {
|
||||
|
||||
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*");
|
||||
|
@ -565,6 +565,28 @@ public class HotSpotReplacementsUtil {
|
||||
return WordFactory.unsigned(ComputeObjectAddressNode.get(a, getArrayBaseOffset(JavaKind.Int)));
|
||||
}
|
||||
|
||||
@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();
|
||||
|
@ -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.
|
||||
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.
|
||||
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 @@ public class NewObjectSnippets implements Snippets {
|
||||
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);
|
||||
|
@ -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.
|
||||
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.handlePendingException
|
||||
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 @@ public class NewArrayStub extends SnippetStub {
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user