use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class PosixJavaNIOSubstitutions method toByteArray.
// Checkstyle: resume
protected static byte[] toByteArray(CCharPointer cstr) {
UnsignedWord len = SubstrateUtil.strlen(cstr);
byte[] result = new byte[(int) len.rawValue()];
for (int i = 0; i < result.length; i++) {
result[i] = cstr.read(i);
}
return result;
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class NativeImage method getXmxValue.
protected String getXmxValue(int maxInstances) {
UnsignedWord memMax = PhysicalMemory.size().unsignedDivide(10).multiply(8).unsignedDivide(maxInstances);
String maxXmx = "14g";
if (memMax.aboveOrEqual(Word.unsigned(SubstrateOptionsParser.parseLong(maxXmx)))) {
return maxXmx;
}
return Long.toUnsignedString(memMax.rawValue());
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class JavaLangSubstitutions method identityHashCode.
@Substitute
private static int identityHashCode(Object obj) {
if (obj == null) {
return 0;
}
DynamicHub hub = KnownIntrinsics.readHub(obj);
int hashCodeOffset = hub.getHashCodeOffset();
if (hashCodeOffset == 0) {
throw VMError.shouldNotReachHere("identityHashCode called on illegal object");
}
UnsignedWord hashCodeOffsetWord = WordFactory.unsigned(hashCodeOffset);
int hashCode = ObjectAccess.readInt(obj, hashCodeOffsetWord);
if (hashCode != 0) {
return hashCode;
}
/* On the first invocation for an object create a new hash code. */
hashCode = IdentityHashCodeSupport.generateHashCode();
if (!UnsafeAccess.UNSAFE.compareAndSwapInt(obj, hashCodeOffset, 0, hashCode)) {
/* We lost the race, so there now must be a hash code installed from another thread. */
hashCode = ObjectAccess.readInt(obj, hashCodeOffsetWord);
}
VMError.guarantee(hashCode != 0, "Missing identity hash code");
return hashCode;
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class ReferenceMapDecoder method walkOffsetsFromPointer.
/**
* Walk the reference map encoding from a Pointer, applying a visitor to each Object reference.
*
* @param baseAddress A Pointer to a collections of primitives and Object references.
* @param referenceMapEncoding The encoding for the Object references in the collection.
* @param referenceMapIndex The start index for the particular reference map in the encoding.
* @param visitor The ObjectRefernceVisitor to be applied to each Object reference.
* @return false if any of the visits returned false, true otherwise.
*/
@AlwaysInline("de-virtualize calls to ObjectReferenceVisitor")
public static boolean walkOffsetsFromPointer(PointerBase baseAddress, byte[] referenceMapEncoding, long referenceMapIndex, ObjectReferenceVisitor visitor) {
assert referenceMapIndex != CodeInfoQueryResult.NO_REFERENCE_MAP;
assert referenceMapEncoding != null;
UnsignedWord uncompressedSize = WordFactory.unsigned(ConfigurationValues.getObjectLayout().getReferenceSize());
UnsignedWord compressedSize = WordFactory.unsigned(ConfigurationValues.getObjectLayout().getCompressedReferenceSize());
UnsignedWord slotSize = WordFactory.unsigned(SubstrateReferenceMap.getSlotSizeInBytes());
Pointer objRef = (Pointer) baseAddress;
long idx = referenceMapIndex;
while (true) {
int gap = ByteArrayReader.getU1(referenceMapEncoding, idx);
if (gap == GAP_END_OF_TABLE) {
break;
}
int count = ByteArrayReader.getS1(referenceMapEncoding, idx + 1);
// Skip a gap.
objRef = objRef.add(slotSize.multiply(gap));
// Visit the offsets.
boolean compressed = (count < 0);
UnsignedWord refSize = compressed ? compressedSize : uncompressedSize;
count = (count < 0) ? -count : count;
for (int c = 0; c < count; c += 1) {
final boolean visitResult = visitor.visitObjectReferenceInline(objRef, compressed);
if (!visitResult) {
return false;
}
objRef = objRef.add(refSize);
}
idx += 2;
}
return true;
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class CInterfaceTutorial method javaEntryPoint4.
@CEntryPoint(name = "java_entry_point4")
protected static void javaEntryPoint4(@SuppressWarnings("unused") IsolateThread thread, SUData sudata) {
int i = 0;
UnsignedWord u = sudata.getUB1Unsigned();
SignedWord s = sudata.getSB1Signed();
i = sudata.getUB1();
System.out.println(" getUB1() = " + i + (i < 0 ? "<" : ">=") + " 0");
System.out.println(" getUB1Unsigned() = " + u.rawValue() + (u.rawValue() < 0 ? "<" : ">=") + " 0");
i = sudata.getSB1();
System.out.println(" getSB1() = " + i + (i < 0 ? "<" : ">=") + " 0");
System.out.println(" getSB1Signed() = " + s.rawValue() + (s.rawValue() < 0 ? "<" : ">=") + " 0");
System.out.println("(byte) 245 = " + ((byte) 245));
System.out.println("(byte) 245 & 0xFF = " + (((byte) 245) & 0xFF));
System.out.println("sudata.getUB1Unsigned().aboveOrEqual(220) = " + sudata.getUB1Unsigned().aboveOrEqual(220));
System.out.println("sudata.getUB1Unsigned().aboveOrEqual(245) = " + sudata.getUB1Unsigned().aboveOrEqual(245));
System.out.println("sudata.getUB1Unsigned().aboveOrEqual((byte)220) = " + sudata.getUB1Unsigned().aboveOrEqual((byte) 220));
System.out.println("sudata.getUB1Unsigned().aboveOrEqual((byte)245) = " + sudata.getUB1Unsigned().aboveOrEqual((byte) 245));
System.out.println("sudata.getUB1() && 0xFF > 220 = " + ((sudata.getUB1() & 0xFF) > 220));
System.out.println("sudata.getUB1() && 0xFF > 245 = " + ((sudata.getUB1() & 0xFF) > 245));
}
Aggregations