Search in sources :

Example 41 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class AnnotationSubstitutionProcessor method handleMethodInAliasClass.

private void handleMethodInAliasClass(Executable annotatedMethod, Class<?> originalClass) {
    if (!NativeImageGenerator.includedIn(ImageSingletons.lookup(Platform.class), lookupAnnotation(annotatedMethod, Platforms.class))) {
        return;
    }
    Delete deleteAnnotation = lookupAnnotation(annotatedMethod, Delete.class);
    Substitute substituteAnnotation = lookupAnnotation(annotatedMethod, Substitute.class);
    AnnotateOriginal annotateOriginalAnnotation = lookupAnnotation(annotatedMethod, AnnotateOriginal.class);
    Alias aliasAnnotation = lookupAnnotation(annotatedMethod, Alias.class);
    int numAnnotations = (deleteAnnotation != null ? 1 : 0) + (substituteAnnotation != null ? 1 : 0) + (annotateOriginalAnnotation != null ? 1 : 0) + (aliasAnnotation != null ? 1 : 0);
    if (numAnnotations == 0) {
        guarantee(annotatedMethod instanceof Constructor, "One of @Delete, @Substitute, @AnnotateOriginal, or @Alias must be used: %s", annotatedMethod);
        return;
    }
    guarantee(numAnnotations == 1, "Only one of @Delete, @Substitute, @AnnotateOriginal, or @Alias can be used: %s", annotatedMethod);
    ResolvedJavaMethod annotated = metaAccess.lookupJavaMethod(annotatedMethod);
    ResolvedJavaMethod original = findOriginalMethod(annotatedMethod, originalClass);
    if (original == null) {
    /* Optional target that is not present, so nothing to do. */
    } else if (deleteAnnotation != null) {
        registerAsDeleted(annotated, original, deleteAnnotation);
    } else if (substituteAnnotation != null) {
        SubstitutionMethod substitution = new SubstitutionMethod(original, annotated);
        register(methodSubstitutions, annotated, original, substitution);
    } else if (annotateOriginalAnnotation != null) {
        AnnotatedMethod substitution = new AnnotatedMethod(original, annotated);
        register(methodSubstitutions, annotated, original, substitution);
    } else if (aliasAnnotation != null) {
        register(methodSubstitutions, annotated, original, original);
    }
}
Also used : Delete(com.oracle.svm.core.annotate.Delete) AnnotateOriginal(com.oracle.svm.core.annotate.AnnotateOriginal) CustomSubstitutionMethod(com.oracle.svm.hosted.annotation.CustomSubstitutionMethod) Alias(com.oracle.svm.core.annotate.Alias) Constructor(java.lang.reflect.Constructor) Substitute(com.oracle.svm.core.annotate.Substitute) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 42 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class JLineSubstitutions method create.

@SuppressWarnings("unused")
@Substitute
public static Terminal create(String ttyDevice) {
    Terminal t;
    try {
        t = new UnixTerminal();
        t.init();
    } catch (Exception e) {
        Log.error("Failed to construct terminal; falling back to UnsupportedTerminal", e);
        t = new UnsupportedTerminal();
    }
    Log.debug("Created Terminal: ", t);
    return t;
}
Also used : UnixTerminal(jline.UnixTerminal) UnsupportedTerminal(jline.UnsupportedTerminal) UnixTerminal(jline.UnixTerminal) Terminal(jline.Terminal) UnsupportedTerminal(jline.UnsupportedTerminal) IOException(java.io.IOException) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 43 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class VMThreadCounterOperation method init.

@Substitute
@SuppressWarnings("all")
private void init(ThreadGroup g, Runnable target, String name, long stackSize) {
    /*
         * This method is a copy of the original implementation, with unsupported features removed.
         */
    this.unsafeParkEvent = new AtomicReference<>();
    this.sleepParkEvent = new AtomicReference<>();
    if (name == null) {
        throw new NullPointerException("name cannot be null");
    }
    this.name = name;
    Thread parent = currentThread();
    if (g == null) {
        /* Use the parent thread group. */
        g = parent.getThreadGroup();
    }
    JavaThreads.toTarget(g).addUnstarted();
    this.group = g;
    this.daemon = parent.isDaemon();
    this.priority = parent.getPriority();
    this.target = target;
    setPriority(priority);
    /* Stash the specified stack size in case the VM cares */
    this.stackSize = stackSize;
    /* Set thread ID */
    tid = nextThreadID();
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 44 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class VMThreadCounterOperation method unpark.

/**
 * Unblock the given thread blocked on <tt>park</tt>, or, if it is not blocked, cause the
 * subsequent call to <tt>park</tt> not to block. Note: this operation is "unsafe" solely
 * because the caller must somehow ensure that the thread has not been destroyed. Nothing
 * special is usually required to ensure this when called from Java (in which there will
 * ordinarily be a live reference to the thread) but this is not nearly-automatically so when
 * calling from native code.
 *
 * @param threadObj the thread to unpark.
 */
@Substitute
private void unpark(Object threadObj) {
    if (threadObj == null) {
        throw new NullPointerException("Unsafe.unpark(thread == null)");
    } else if (!(threadObj instanceof Thread)) {
        throw new IllegalArgumentException("Unsafe.unpark(!(thread instanceof Thread))");
    }
    Thread thread = (Thread) threadObj;
    UnsafeParkSupport.unpark(thread);
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 45 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class GraalSubstitutions method parseBytecodes.

@Substitute
private static StructuredGraph parseBytecodes(ResolvedJavaMethod method, HighTierContext context, CanonicalizerPhase canonicalizer, StructuredGraph caller, boolean trackNodeSourcePosition) {
    DebugContext debug = caller.getDebug();
    StructuredGraph result = GraalSupport.decodeGraph(debug, null, null, (SubstrateMethod) method);
    assert result != null : "should not try to inline method when no graph is in the native image";
    assert !trackNodeSourcePosition || result.trackNodeSourcePosition();
    return result;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DebugContext(org.graalvm.compiler.debug.DebugContext) Substitute(com.oracle.svm.core.annotate.Substitute)

Aggregations

Substitute (com.oracle.svm.core.annotate.Substitute)69 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)18 SocketException (java.net.SocketException)11 IOException (java.io.IOException)10 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)10 PinnedObject (org.graalvm.nativeimage.PinnedObject)9 Util_java_io_FileDescriptor (com.oracle.svm.core.posix.PosixOSInterface.Util_java_io_FileDescriptor)8 FileDescriptor (java.io.FileDescriptor)8 CCharPointerHolder (org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder)8 ServerSocket (java.net.ServerSocket)7 Socket (com.oracle.svm.core.posix.headers.Socket)6 NativeTruffleContext (com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext)6 SignedWord (org.graalvm.word.SignedWord)6 InterruptedIOException (java.io.InterruptedIOException)5 Time.timeval (com.oracle.svm.core.posix.headers.Time.timeval)4 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)3 Stat.fstat (com.oracle.svm.core.posix.headers.Stat.fstat)3 Stat.stat (com.oracle.svm.core.posix.headers.Stat.stat)3 Time.timezone (com.oracle.svm.core.posix.headers.Time.timezone)3 LibFFI.ffi_cif (com.oracle.svm.truffle.nfi.libffi.LibFFI.ffi_cif)3