use of com.oracle.svm.core.c.function.CEntryPointOptions in project graal by oracle.
the class NativeImageGenerator method registerEntryPoints.
private void registerEntryPoints(Map<Method, CEntryPointData> entryPoints) {
for (Method m : loader.findAnnotatedMethods(CEntryPoint.class)) {
if (!Modifier.isStatic(m.getModifiers())) {
throw UserError.abort("entry point method " + m.getDeclaringClass().getName() + "." + m.getName() + " is not static. Add a static modifier to the method.");
}
boolean include = true;
CEntryPointOptions options = m.getAnnotation(CEntryPointOptions.class);
if (options != null) {
BooleanSupplier instance;
try {
Constructor<? extends BooleanSupplier> constructor = options.include().getDeclaredConstructor();
constructor.setAccessible(true);
instance = constructor.newInstance();
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
throw VMError.shouldNotReachHere(ex);
}
include = instance.getAsBoolean();
}
if (include) {
entryPoints.put(m, CEntryPointData.create(m));
}
}
}
use of com.oracle.svm.core.c.function.CEntryPointOptions in project graal by oracle.
the class JNIFunctions method UnregisterNatives.
/*
* jint UnregisterNatives(JNIEnv *env, jclass clazz);
*/
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnJniErr.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static int UnregisterNatives(JNIEnvironment env, JNIObjectHandle hclazz) {
Class<?> clazz = JNIObjectHandles.getObject(hclazz);
String internalName = MetaUtil.toInternalName(clazz.getName());
for (JNINativeLinkage linkage : JNIReflectionDictionary.singleton().getLinkages(internalName)) {
linkage.unsetEntryPoint();
}
return JNIErrors.JNI_OK();
}
use of com.oracle.svm.core.c.function.CEntryPointOptions in project graal by oracle.
the class JNIFunctions method GetStringUTFRegion.
/*
* void GetStringUTFRegion(JNIEnv *env, jstring str, jsize start, jsize len, char *buf);
*/
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerVoid.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static void GetStringUTFRegion(JNIEnvironment env, JNIObjectHandle hstr, int start, int len, CCharPointer buf) {
String str = JNIObjectHandles.getObject(hstr);
if (start < 0) {
throw new StringIndexOutOfBoundsException(start);
}
if (start + len > str.length()) {
throw new StringIndexOutOfBoundsException(start + len);
}
if (len < 0) {
throw new StringIndexOutOfBoundsException(len);
}
// estimate: caller must pre-allocate
int capacity = Utf8.maxUtf8ByteLength(len, true);
// enough
ByteBuffer buffer = SubstrateUtil.wrapAsByteBuffer(buf, capacity);
Utf8.substringToUtf8(buffer, str, start, start + len, true);
}
use of com.oracle.svm.core.c.function.CEntryPointOptions in project graal by oracle.
the class JNIFunctions method GetStringRegion.
/*
* void GetStringRegion(JNIEnv *env, jstring str, jsize start, jsize len, jchar *buf);
*/
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerVoid.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static void GetStringRegion(JNIEnvironment env, JNIObjectHandle hstr, int start, int len, CShortPointer buf) {
String str = JNIObjectHandles.getObject(hstr);
if (start < 0) {
throw new StringIndexOutOfBoundsException(start);
}
if (start + len > str.length()) {
throw new StringIndexOutOfBoundsException(start + len);
}
if (len < 0) {
throw new StringIndexOutOfBoundsException(len);
}
for (int i = 0; i < len; i++) {
char c = str.charAt(start + i);
buf.write(i, (short) c);
}
}
use of com.oracle.svm.core.c.function.CEntryPointOptions in project graal by oracle.
the class JNIFunctions method FromReflectedField.
/*
* jfieldID FromReflectedField(JNIEnv *env, jobject field);
*/
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnNullWord.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static JNIFieldId FromReflectedField(JNIEnvironment env, JNIObjectHandle fieldHandle) {
JNIFieldId fieldId = Word.zero();
if (JNIAccessFeature.singleton().haveJavaRuntimeReflectionSupport()) {
Field obj = JNIObjectHandles.getObject(fieldHandle);
if (obj != null) {
boolean isStatic = Modifier.isStatic(obj.getModifiers());
fieldId = JNIReflectionDictionary.singleton().getFieldID(obj.getDeclaringClass(), obj.getName());
}
}
return fieldId;
}
Aggregations