Search in sources :

Example 41 with Pointer

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)));
        }
    }
}
Also used : CGlobalDataReference(com.oracle.svm.core.graal.code.CGlobalDataReference) Pointer(org.graalvm.word.Pointer) AMD64Address(org.graalvm.compiler.asm.amd64.AMD64Address)

Example 42 with Pointer

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();
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Word(org.graalvm.compiler.word.Word) UnsignedWord(org.graalvm.word.UnsignedWord) WordBase(org.graalvm.word.WordBase) Pointer(org.graalvm.word.Pointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 43 with Pointer

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();
}
Also used : JNINativeMethod(com.oracle.svm.jni.nativeapi.JNINativeMethod) InvokeCFunctionPointer(org.graalvm.nativeimage.c.function.InvokeCFunctionPointer) CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) WordPointer(org.graalvm.nativeimage.c.type.WordPointer) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer) CShortPointer(org.graalvm.nativeimage.c.type.CShortPointer) JNIJavaVMPointer(com.oracle.svm.jni.nativeapi.JNIJavaVMPointer) Pointer(org.graalvm.word.Pointer) InvokeCFunctionPointer(org.graalvm.nativeimage.c.function.InvokeCFunctionPointer) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) JNINativeLinkage(com.oracle.svm.jni.access.JNINativeLinkage) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 44 with Pointer

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;
}
Also used : Pointer(org.graalvm.word.Pointer) MethodSubstitution(org.graalvm.compiler.api.replacements.MethodSubstitution)

Example 45 with Pointer

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);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer)

Aggregations

Pointer (org.graalvm.word.Pointer)103 UnsignedWord (org.graalvm.word.UnsignedWord)45 Log (com.oracle.svm.core.log.Log)30 CodePointer (org.graalvm.nativeimage.c.function.CodePointer)17 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)15 Snippet (org.graalvm.compiler.api.replacements.Snippet)14 Word (org.graalvm.compiler.word.Word)12 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)9 HotSpotReplacementsUtil.registerAsWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord)7 AlwaysInline (com.oracle.svm.core.annotate.AlwaysInline)5 NeverInline (com.oracle.svm.core.annotate.NeverInline)5 KnownIntrinsics.readCallerStackPointer (com.oracle.svm.core.snippets.KnownIntrinsics.readCallerStackPointer)5 KlassPointer (org.graalvm.compiler.hotspot.word.KlassPointer)4 DynamicHub (com.oracle.svm.core.hub.DynamicHub)3 CCharPointerPointer (org.graalvm.nativeimage.c.type.CCharPointerPointer)3 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)3 SignedWord (org.graalvm.word.SignedWord)3 DeoptimizedFrame (com.oracle.svm.core.deopt.DeoptimizedFrame)2 AlignedHeader (com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader)2 Dirent.direntPointer (com.oracle.svm.core.posix.headers.Dirent.direntPointer)2