use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class ArraycopySnippets method objectCopyForwardUninterruptibly.
@Uninterruptible(reason = "Only the first writeObject has a write-barrier.")
private static void objectCopyForwardUninterruptibly(Object fromArray, UnsignedWord fromOffset, Object toArray, UnsignedWord toOffset, UnsignedWord elementSize, UnsignedWord size) {
UnsignedWord copied = WordFactory.zero();
// TODO: I am explicitly not making the first read have a read barrier.
if (copied.belowThan(size)) {
BarrieredAccess.writeObject(toArray, toOffset.add(copied), ObjectAccess.readObject(fromArray, fromOffset.add(copied)));
copied = copied.add(elementSize);
while (copied.belowThan(size)) {
ObjectAccess.writeObject(toArray, toOffset.add(copied), ObjectAccess.readObject(fromArray, fromOffset.add(copied)));
copied = copied.add(elementSize);
}
}
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class PointerUtils method absoluteDifference.
/**
* Return the distance between two Pointers.
*
* @param pointer1 A first Pointer.
* @param pointer2 A second Pointer.
* @return The distance in bytes between the two Pointers.
*/
public static UnsignedWord absoluteDifference(PointerBase pointer1, PointerBase pointer2) {
Pointer p1 = (Pointer) pointer1;
Pointer p2 = (Pointer) pointer2;
final UnsignedWord result;
if (p1.aboveOrEqual(p2)) {
result = p1.subtract(p2);
} else {
result = p2.subtract(p1);
}
return result;
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class TimeUtils method weightedNanos.
/**
* Weight a nanosecond value by a percentage between 0 and 100.
*/
public static long weightedNanos(int percent, long nanos) {
final UnsignedWord unweightedNanos = WordFactory.unsigned(nanos);
final long result = unweightedNanos.unsignedDivide(100).multiply(percent).rawValue();
return result;
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class PosixOSInterface method writeBytesUninterruptibly.
@Override
@Uninterruptible(reason = "Bytes might be from an Object.")
public boolean writeBytesUninterruptibly(FileDescriptor descriptor, CCharPointer bytes, UnsignedWord length) {
CCharPointer curBuf = bytes;
UnsignedWord curLen = length;
while (curLen.notEqual(0)) {
int fd = Util_java_io_FileDescriptor.getFD(descriptor);
if (fd == -1) {
return false;
}
SignedWord n = UnistdNoTransitions.write(fd, curBuf, curLen);
if (n.equal(-1)) {
return false;
}
curBuf = curBuf.addressOf(n);
curLen = curLen.subtract((UnsignedWord) n);
}
return true;
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class JavaMainWrapper method getCRuntimeArgumentBlockLength.
/**
* Argv is an array of C strings (i.e. array of pointers to characters). Each entry points to a
* different C string corresponding to a program argument. The program argument strings
* themselves are located in a contiguous block of memory followed by the environment variables
* key-value strings:
*
* <pre>
* <argument_0>\n<argument_1>\n...<argument_n>\n
* <env_key_value_1>\n<env_key_value_2>\n...<env_key_value_n>\n
* </pre>
*
* @return maximum length of C chars that can be stored in the program argument part of the
* contiguous memory block without writing into the environment variables part.
*/
public static long getCRuntimeArgumentBlockLength() {
VMError.guarantee(argv.notEqual(WordFactory.zero()) && argc > 0, "Requires JavaMainWrapper.run(int, CCharPointerPointer) entry point!");
CCharPointer firstArgPos = argv.read(0);
if (argvLength.equal(WordFactory.zero())) {
// Get char* to last program argument
CCharPointer lastArgPos = argv.read(argc - 1);
// Determine the length of the last program argument
UnsignedWord lastArgLength = SubstrateUtil.strlen(lastArgPos);
// Determine maximum C string length that can be stored in the program argument part
argvLength = WordFactory.unsigned(lastArgPos.rawValue()).add(lastArgLength).subtract(WordFactory.unsigned(firstArgPos.rawValue()));
}
return argvLength.rawValue();
}
Aggregations