use of org.graalvm.word.Pointer in project graal by oracle.
the class AMD64CGlobalDataLoadAddressOp method emitCode.
@Override
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
if (SubstrateUtil.HOSTED) {
// AOT compilation: record patch that is fixed up later
int before = masm.position();
AMD64Address address = masm.getPlaceholder(before);
if (dataInfo.isSymbolReference()) {
// Pure symbol reference: the data contains the symbol's address, load it
masm.movq(asRegister(result), address);
} else {
// Data: load its address
masm.leaq(asRegister(result), address);
}
crb.compilationResult.recordDataPatch(before, new CGlobalDataReference(dataInfo));
} else {
// Runtime compilation: compute the actual address
Pointer globalsBase = CGlobalDataInfo.CGLOBALDATA_RUNTIME_BASE_ADDRESS.get();
Pointer address = globalsBase.add(dataInfo.getOffset());
masm.movq(asRegister(result), address.rawValue());
if (dataInfo.isSymbolReference()) {
// load data, which contains symbol's address
masm.movq(asRegister(result), new AMD64Address(asRegister(result)));
}
}
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class WordTest method cast.
@Snippet
public static long cast(long input) {
WordBase base = WordFactory.signed(input);
UnsignedWord unsigned = (UnsignedWord) base;
Pointer pointer = (Pointer) unsigned;
Word word = (Word) pointer;
return word.rawValue();
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class JNIFunctions method RegisterNatives.
/*
* jint RegisterNatives(JNIEnv *env, jclass clazz, const JNINativeMethod *methods, jint
* nMethods);
*/
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnJniErr.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static int RegisterNatives(JNIEnvironment env, JNIObjectHandle hclazz, JNINativeMethod methods, int nmethods) {
Class<?> clazz = JNIObjectHandles.getObject(hclazz);
Pointer p = (Pointer) methods;
for (int i = 0; i < nmethods; i++) {
JNINativeMethod entry = (JNINativeMethod) p;
String name = CTypeConversion.toJavaString(entry.name());
String signature = CTypeConversion.toJavaString(entry.signature());
CFunctionPointer fnPtr = entry.fnPtr();
String declaringClass = MetaUtil.toInternalName(clazz.getName());
JNINativeLinkage linkage = JNIReflectionDictionary.singleton().getLinkage(declaringClass, name, signature);
if (linkage != null) {
linkage.setEntryPoint(fnPtr);
} else {
return JNIErrors.JNI_ERR();
}
p = p.add(SizeOf.get(JNINativeMethod.class));
}
return JNIErrors.JNI_OK();
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class AMD64StringSubstitutions method indexOf.
// Only exists in JDK <= 8
@MethodSubstitution(isStatic = true, optional = true)
public static int indexOf(char[] source, int sourceOffset, int sourceCount, @ConstantNodeParameter char[] target, int targetOffset, int targetCount, int origFromIndex) {
int fromIndex = origFromIndex;
if (fromIndex >= sourceCount) {
return (targetCount == 0 ? sourceCount : -1);
}
if (fromIndex < 0) {
fromIndex = 0;
}
if (targetCount == 0) {
// The empty string is in every string.
return fromIndex;
}
int totalOffset = sourceOffset + fromIndex;
if (sourceCount - fromIndex < targetCount) {
// The empty string contains nothing except the empty string.
return -1;
}
assert sourceCount - fromIndex > 0 && targetCount > 0;
Pointer sourcePointer = Word.objectToTrackedPointer(source).add(charArrayBaseOffset(INJECTED)).add(totalOffset * charArrayIndexScale(INJECTED));
Pointer targetPointer = Word.objectToTrackedPointer(target).add(charArrayBaseOffset(INJECTED)).add(targetOffset * charArrayIndexScale(INJECTED));
int result = AMD64StringIndexOfNode.optimizedStringIndexPointer(sourcePointer, sourceCount - fromIndex, targetPointer, targetCount);
if (result >= 0) {
return result + totalOffset;
}
return result;
}
use of org.graalvm.word.Pointer in project graal by oracle.
the class PosixOSInterface method freeVirtualMemoryAligned.
@Override
public boolean freeVirtualMemoryAligned(PointerBase start, UnsignedWord size, UnsignedWord alignment) {
final UnsignedWord pageSize = getPageSize();
// Re-discover the paged-aligned ends of the memory region.
final Pointer end = ((Pointer) start).add(size);
final Pointer pagedStart = PointerUtils.roundDown(start, pageSize);
final Pointer pagedEnd = PointerUtils.roundUp(end, pageSize);
final UnsignedWord pagedSize = pagedEnd.subtract(pagedStart);
// Return that virtual address space to the operating system.
return freeVirtualMemory(pagedStart, pagedSize);
}
Aggregations