use of org.graalvm.compiler.word.Word in project graal by oracle.
the class WriteBarrierSnippets method g1ArrayRangePostWriteBarrier.
@Snippet
public static void g1ArrayRangePostWriteBarrier(Address address, int length, @ConstantParameter int elementStride, @ConstantParameter Register threadRegister) {
if (length == 0) {
return;
}
Word thread = registerAsWord(threadRegister);
Word bufferAddress = thread.readWord(g1CardQueueBufferOffset(INJECTED_VMCONFIG));
Word indexAddress = thread.add(g1CardQueueIndexOffset(INJECTED_VMCONFIG));
long indexValue = thread.readWord(g1CardQueueIndexOffset(INJECTED_VMCONFIG)).rawValue();
int cardShift = cardTableShift(INJECTED_VMCONFIG);
final long cardStart = GraalHotSpotVMConfigNode.cardTableAddress();
long start = getPointerToFirstArrayElement(address, length, elementStride) >>> cardShift;
long end = getPointerToLastArrayElement(address, length, elementStride) >>> cardShift;
long count = end - start + 1;
while (count-- > 0) {
Word cardAddress = WordFactory.unsigned((start + cardStart) + count);
byte cardByte = cardAddress.readByte(0, GC_CARD_LOCATION);
// If the card is already dirty, (hence already enqueued) skip the insertion.
if (probability(NOT_FREQUENT_PROBABILITY, cardByte != g1YoungCardValue(INJECTED_VMCONFIG))) {
MembarNode.memoryBarrier(STORE_LOAD, GC_CARD_LOCATION);
byte cardByteReload = cardAddress.readByte(0, GC_CARD_LOCATION);
if (probability(NOT_FREQUENT_PROBABILITY, cardByteReload != dirtyCardValue(INJECTED_VMCONFIG))) {
cardAddress.writeByte(0, (byte) 0, GC_CARD_LOCATION);
// initialize a new one and add the card entry.
if (indexValue != 0) {
indexValue = indexValue - wordSize();
Word logAddress = bufferAddress.add(WordFactory.unsigned(indexValue));
// Log the object to be scanned as well as update
// the card queue's next index.
logAddress.writeWord(0, cardAddress, GC_LOG_LOCATION);
indexAddress.writeWord(0, WordFactory.unsigned(indexValue), GC_INDEX_LOCATION);
} else {
g1PostBarrierStub(G1WBPOSTCALL, cardAddress);
}
}
}
}
}
use of org.graalvm.compiler.word.Word in project graal by oracle.
the class ArrayCopySnippets method checkcastArraycopyWithSlowPathWork.
@Snippet(allowPartialIntrinsicArgumentMismatch = true)
public static void checkcastArraycopyWithSlowPathWork(Object src, int srcPos, Object dest, int destPos, int length, @ConstantParameter Counters counters) {
if (probability(FREQUENT_PROBABILITY, length > 0)) {
Object nonNullSrc = PiNode.asNonNullObject(src);
Object nonNullDest = PiNode.asNonNullObject(dest);
KlassPointer srcKlass = loadHub(nonNullSrc);
KlassPointer destKlass = loadHub(nonNullDest);
if (probability(LIKELY_PROBABILITY, srcKlass == destKlass)) {
// no storecheck required.
counters.objectCheckcastSameTypeCounter.inc();
counters.objectCheckcastSameTypeCopiedCounter.add(length);
ArrayCopyCallNode.arraycopyObjectKillsAny(nonNullSrc, srcPos, nonNullDest, destPos, length);
} else {
KlassPointer destElemKlass = destKlass.readKlassPointer(arrayClassElementOffset(INJECTED_VMCONFIG), OBJ_ARRAY_KLASS_ELEMENT_KLASS_LOCATION);
Word superCheckOffset = WordFactory.signed(destElemKlass.readInt(superCheckOffsetOffset(INJECTED_VMCONFIG), KLASS_SUPER_CHECK_OFFSET_LOCATION));
counters.objectCheckcastDifferentTypeCounter.inc();
counters.objectCheckcastDifferentTypeCopiedCounter.add(length);
int copiedElements = CheckcastArrayCopyCallNode.checkcastArraycopy(nonNullSrc, srcPos, nonNullDest, destPos, length, superCheckOffset, destElemKlass, false);
if (probability(SLOW_PATH_PROBABILITY, copiedElements != 0)) {
/*
* the stub doesn't throw the ArrayStoreException, but returns the number of
* copied elements (xor'd with -1).
*/
copiedElements ^= -1;
System.arraycopy(nonNullSrc, srcPos + copiedElements, nonNullDest, destPos + copiedElements, length - copiedElements);
}
}
}
}
use of org.graalvm.compiler.word.Word in project graal by oracle.
the class HashCodeSnippets method computeHashCode.
static int computeHashCode(final Object x) {
Word mark = loadWordFromObject(x, markOffset(INJECTED_VMCONFIG));
// this code is independent from biased locking (although it does not look that way)
final Word biasedLock = mark.and(biasedLockMaskInPlace(INJECTED_VMCONFIG));
if (probability(FAST_PATH_PROBABILITY, biasedLock.equal(WordFactory.unsigned(unlockedMask(INJECTED_VMCONFIG))))) {
int hash = (int) mark.unsignedShiftRight(identityHashCodeShift(INJECTED_VMCONFIG)).rawValue();
if (probability(FAST_PATH_PROBABILITY, hash != uninitializedIdentityHashCodeValue(INJECTED_VMCONFIG))) {
return hash;
}
}
return identityHashCode(IDENTITY_HASHCODE, x);
}
use of org.graalvm.compiler.word.Word in project graal by oracle.
the class LoadExceptionObjectSnippets method loadException.
@Snippet
public static Object loadException(@ConstantParameter Register threadRegister) {
Word thread = registerAsWord(threadRegister);
Object exception = readExceptionOop(thread);
writeExceptionOop(thread, null);
writeExceptionPc(thread, WordFactory.zero());
return piCastToSnippetReplaceeStamp(exception);
}
use of org.graalvm.compiler.word.Word in project graal by oracle.
the class Target_com_sun_security_auth_module_UnixSystem method getUnixInfo.
@Substitute
void getUnixInfo() {
int realUid = Unistd.getuid();
Word pwsize = WordFactory.signed(Unistd.sysconf(Unistd._SC_GETPW_R_SIZE_MAX()));
if (pwsize.lessThan(0)) {
// indicates no definitive bound: try different sizes
pwsize = WordFactory.signed(1024);
}
CCharPointer pwbuf = LibC.malloc(pwsize);
try {
passwd pwent = StackValue.get(SizeOf.get(passwd.class));
passwdPointer p = StackValue.get(SizeOf.get(passwdPointer.class));
int result;
do {
if (pwbuf.isNull()) {
throw new OutOfMemoryError("Native heap");
}
p.write(WordFactory.nullPointer());
result = Pwd.getpwuid_r(realUid, pwent, pwbuf, pwsize, p);
if (result == Errno.ERANGE()) {
pwsize = pwsize.add(pwsize);
pwbuf = LibC.realloc(pwbuf, pwsize);
} else if (result < 0 && result != Errno.EINTR()) {
throw new RuntimeException("getpwuid_r error: " + Errno.errno());
}
} while (result != 0);
this.uid = pwent.pw_uid();
this.gid = pwent.pw_gid();
this.username = CTypeConversion.toJavaString(pwent.pw_name());
} finally {
LibC.free(pwbuf);
}
int ngroups = Unistd.getgroups(0, WordFactory.nullPointer());
int[] groupIds = new int[ngroups];
try (PinnedObject pinnedGroupIds = PinnedObject.create(groupIds)) {
ngroups = Unistd.getgroups(groupIds.length, pinnedGroupIds.addressOfArrayElement(0));
}
this.groups = new long[ngroups];
for (int i = 0; i < this.groups.length; i++) {
this.groups[i] = groupIds[i];
}
}
Aggregations