Skip to content

Commit

Permalink
[GR-10885] Fix issues with non-word-sized object references.
Browse files Browse the repository at this point in the history
PullRequest: graal/1849
  • Loading branch information
peter-hofer committed Jul 18, 2018
2 parents cc6eefc + 812be82 commit 88a739c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ public static void const2reg(CompilationResultBuilder crb, AMD64MacroAssembler m
}
} else if (crb.target.inlineObjects) {
crb.recordInlineDataInCode(input);
masm.movq(result, 0xDEADDEADDEADDEADL);
masm.movq(result, 0xDEADDEADDEADDEADL, true);
} else {
masm.movq(result, (AMD64Address) crb.recordDataReferenceInCode(input, 0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.thread.VMOperation;
import com.oracle.svm.core.thread.VMThreads;
import com.oracle.svm.core.util.VMError;

/**
* A Space is a collection of HeapChunks.
Expand Down Expand Up @@ -619,10 +620,9 @@ private Object copyAlignedObject(Object originalObj) {
final Pointer copyMemory = allocateMemory(copySize);
trace.string(" copyMemory: ").hex(copyMemory);
if (copyMemory.isNull()) {
/* TODO: Promotion failure! */
final Log failureLog = Log.log().string("[!SpaceImpl.copyAlignedObject:");
failureLog.string(" failure to allocate ").unsigned(copySize).string(" bytes").string("!]").newline();
return null;
throw VMError.shouldNotReachHere("Promotion failure");
}
/* - Copy the Object. */
final Pointer originalMemory = Word.objectToUntrackedPointer(originalObj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,15 @@ private static Object doCloneUninterruptibly(Object thisObject, Object thatObjec
*/
Pointer thisMemory = Word.objectToUntrackedPointer(thisObject);
UnsignedWord offset = firstFieldOffset;
if (!isWordAligned(offset) && offset.belowThan(size)) { // narrow references
thatMemory.writeInt(offset, thisMemory.readInt(offset));
offset = offset.add(Integer.BYTES);
}
while (offset.belowThan(size)) {
thatMemory.writeWord(offset, thisMemory.readWord(offset));
offset = offset.add(ConfigurationValues.getTarget().wordSize);
}
final Object result = thatMemory.toObjectNonNull();
return result;
return thatMemory.toObjectNonNull();
}

private static Object formatObjectImpl(Pointer memory, DynamicHub hub, UnsignedWord size, @ConstantParameter boolean constantSize, @ConstantParameter boolean fillContents, boolean rememberedSet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.oracle.svm.core.graal.meta;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -36,7 +37,6 @@
import org.graalvm.compiler.core.common.NumUtil;
import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.debug.Indent;
import org.graalvm.compiler.word.ObjectAccess;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.c.function.CodePointer;
import org.graalvm.word.Pointer;
Expand Down Expand Up @@ -390,14 +390,28 @@ private void patchData(AMD64InstructionPatcher patcher, SubstrateReferenceMap re

} else if (dataPatch.reference instanceof ConstantReference) {
ConstantReference ref = (ConstantReference) dataPatch.reference;
SubstrateObjectConstant objConst = (SubstrateObjectConstant) ref.getConstant();
PatchData data = patcher.findPatchData(dataPatch.pcOffset, 0);
SubstrateObjectConstant refConst = (SubstrateObjectConstant) ref.getConstant();
UnsignedWord refBits = ReferenceAccess.singleton().getCompressedRepresentation(refConst.getObject());

assert data.operandSize == ConfigurationValues.getObjectLayout().getReferenceSize();
long byteArrayBase = ConfigurationValues.getObjectLayout().getArrayElementOffset(JavaKind.Byte, 0);
int offsetInByteArray = NumUtil.safeToInt(byteArrayBase + data.operandPosition);
ObjectAccess.writeObject(compiledBytes, offsetInByteArray, objConst.getObject());
PatchData data = patcher.findPatchData(dataPatch.pcOffset, 0);
assert data.operandSize >= ConfigurationValues.getObjectLayout().getReferenceSize();

ByteOrder byteOrder = ConfigurationValues.getTarget().arch.getByteOrder();
assert byteOrder == ByteOrder.LITTLE_ENDIAN : "Code below assumes little-endian byte order";
ByteBuffer codeBuffer = ByteBuffer.wrap(compiledBytes).order(byteOrder);
codeBuffer.position(data.operandPosition);
if (data.operandSize == Long.BYTES) {
/*
* NOTE: some instructions use 8-byte immediates for constant object references
* even when we use 4-byte narrow references, so we still support patching them.
* Due to little-endian order, the reference map offset is still the same.
*/
codeBuffer.putLong(refBits.rawValue());
} else if (data.operandSize == Integer.BYTES) {
codeBuffer.putInt(NumUtil.safeToInt(refBits.rawValue()));
} else {
throw VMError.shouldNotReachHere("Unsupported constant reference operand size: " + data.operandSize);
}
referenceMap.markReferenceAtOffset(data.operandPosition, true);
}
}
Expand Down Expand Up @@ -441,7 +455,9 @@ private int patchCalls(AMD64InstructionPatcher patcher) {
* should be within a 32-bit address range.
*/
currentPos = NumUtil.roundUp(currentPos, 8);
ByteBuffer codeBuffer = ByteBuffer.wrap(compiledBytes).order(ConfigurationValues.getTarget().arch.getByteOrder());
ByteOrder byteOrder = ConfigurationValues.getTarget().arch.getByteOrder();
assert byteOrder == ByteOrder.LITTLE_ENDIAN : "Code below assumes little-endian byte order";
ByteBuffer codeBuffer = ByteBuffer.wrap(compiledBytes).order(byteOrder);
for (Entry<Long, Integer> entry : directTargets.entrySet()) {
long targetAddress = entry.getKey();
int trampolineOffset = entry.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ private static int compareThreadLocal(VMThreadLocalInfo info1, VMThreadLocalInfo
return 0;
}

/* Ensure that all objects are contiguous. */
int result = -Boolean.compare(info1.isObject, info2.isObject);
/* Order by size to avoid padding. */
int result = -Integer.compare(info1.sizeInBytes, info2.sizeInBytes);
if (result == 0) {
/* Order by size to avoid padding. */
result = -Integer.compare(info1.sizeInBytes, info2.sizeInBytes);
/* Ensure that all objects are contiguous. */
result = -Boolean.compare(info1.isObject, info2.isObject);
if (result == 0) {
/*
* Make the order deterministic by sorting by name. This is arbitrary, we can come
Expand Down

0 comments on commit 88a739c

Please sign in to comment.