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);
}
}
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;
}
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();
}
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);
}
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;
}
Aggregations