use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class JniEnv method CallStaticObjectMethodVarargs.
// endregion CallNonvirtual*Method
// region CallStatic*Method
@JniImpl
@JavaType(Object.class)
public StaticObject CallStaticObjectMethodVarargs(@JavaType(Class.class) StaticObject clazz, @Handle(Method.class) long methodId, @Pointer TruffleObject varargsPtr) {
Method method = methodIds.getObject(methodId);
assert method.isStatic();
assert (clazz.getMirrorKlass()) == method.getDeclaringKlass();
Object result = method.invokeDirect(null, popVarArgs(varargsPtr, method.getParsedSignature()));
return getMeta().asObject(result);
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class JniEnv method GetMethodID.
/**
* <h3>jmethodID GetMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig);</h3>
* <p>
* Returns the method ID for an instance (nonstatic) method of a class or interface. The method
* may be defined in one of the clazz’s superclasses and inherited by clazz. The method is
* determined by its name and signature.
* <p>
* GetMethodID() causes an uninitialized class to be initialized.
* <p>
* To obtain the method ID of a constructor, supply <init> as the method name and void (V) as
* the return type.
*
* @param clazz a Java class object.
* @param namePtr the method name in a 0-terminated modified UTF-8 string.
* @param signaturePtr the method signature in 0-terminated modified UTF-8 string.
* @return a method ID, or NULL if the specified method cannot be found.
* @throws NoSuchMethodError if the specified method cannot be found.
* @throws ExceptionInInitializerError if the class initializer fails due to an exception.
* @throws OutOfMemoryError if the system runs out of memory.
*/
@JniImpl
@Handle(Method.class)
public long GetMethodID(@JavaType(Class.class) StaticObject clazz, @Pointer TruffleObject namePtr, @Pointer TruffleObject signaturePtr) {
String name = NativeUtils.interopPointerToString(namePtr);
String signature = NativeUtils.interopPointerToString(signaturePtr);
assert name != null && signature != null;
Method method = null;
Symbol<Name> methodName = getNames().lookup(name);
if (methodName != null) {
Symbol<Signature> methodSignature = getSignatures().lookupValidSignature(signature);
if (methodSignature != null) {
Klass klass = clazz.getMirrorKlass();
klass.safeInitialize();
// Lookup only if name and type are known symbols.
method = klass.lookupMethod(methodName, methodSignature, klass);
}
}
if (method == null || method.isStatic()) {
Meta meta = getMeta();
throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchMethodError, name);
}
return methodIds.handlify(method);
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class JniEnv method callVirtualMethodGeneric.
// endregion Set*Field
// region Call*Method
private Object callVirtualMethodGeneric(StaticObject receiver, @Handle(Method.class) long methodId, @Pointer TruffleObject varargsPtr) {
assert !receiver.getKlass().isInterface();
Method resolutionSeed = methodIds.getObject(methodId);
assert !resolutionSeed.isStatic();
assert resolutionSeed.getDeclaringKlass().isAssignableFrom(receiver.getKlass());
Object[] args = popVarArgs(varargsPtr, resolutionSeed.getParsedSignature());
Method target;
if (resolutionSeed.getDeclaringKlass().isInterface()) {
if (!resolutionSeed.isPrivate() && !resolutionSeed.isStatic()) {
target = ((ObjectKlass) receiver.getKlass()).itableLookup(resolutionSeed.getDeclaringKlass(), resolutionSeed.getITableIndex());
} else {
target = resolutionSeed;
}
} else {
if (resolutionSeed.isConstructor()) {
target = resolutionSeed;
} else if (resolutionSeed.isVirtualCall()) {
target = receiver.getKlass().vtableLookup(resolutionSeed.getVTableIndex());
} else {
target = resolutionSeed;
}
}
assert target != null;
assert target.getName() == resolutionSeed.getName() && resolutionSeed.getRawSignature() == target.getRawSignature();
return target.invokeDirect(receiver, args);
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class JniEnv method CallNonvirtualVoidMethodVarargs.
@JniImpl
public void CallNonvirtualVoidMethodVarargs(@JavaType(Object.class) StaticObject receiver, @JavaType(Class.class) StaticObject clazz, @Handle(Method.class) long methodId, @Pointer TruffleObject varargsPtr) {
Method method = methodIds.getObject(methodId);
assert !method.isStatic();
assert (clazz.getMirrorKlass()) == method.getDeclaringKlass();
Object result = method.invokeDirect(receiver, popVarArgs(varargsPtr, method.getParsedSignature()));
assert result instanceof StaticObject && StaticObject.isNull((StaticObject) result) : "void methods must return StaticObject.NULL";
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class JniEnv method ExceptionDescribe.
/**
* <h3>void ExceptionDescribe(JNIEnv *env);</h3>
* <p>
* Prints an exception and a backtrace of the stack to a system error-reporting channel, such as
* stderr. This is a convenience routine provided for debugging.
*/
@JniImpl
public void ExceptionDescribe() {
EspressoException ex = getPendingEspressoException();
if (ex != null) {
StaticObject guestException = ex.getGuestException();
assert InterpreterToVM.instanceOf(guestException, getMeta().java_lang_Throwable);
// Dynamic lookup.
Method printStackTrace = guestException.getKlass().lookupMethod(Name.printStackTrace, Signature._void);
printStackTrace.invokeDirect(guestException);
// Restore exception cleared by invokeDirect.
setPendingException(ex);
}
}
Aggregations