use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.
the class VM method JVM_FindClassFromCaller.
@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(Class.class)
public StaticObject JVM_FindClassFromCaller(@Pointer TruffleObject namePtr, boolean init, @JavaType(ClassLoader.class) StaticObject loader, @JavaType(Class.class) StaticObject caller) {
Meta meta = getMeta();
Symbol<Type> type = namePtrToInternal(namePtr);
Klass result;
if (Types.isPrimitive(type)) {
result = null;
} else {
StaticObject protectionDomain;
// manager to avoid the performance cost of getting the calling class.
if (!StaticObject.isNull(caller) && !StaticObject.isNull(loader)) {
protectionDomain = JVM_GetProtectionDomain(caller);
} else {
protectionDomain = StaticObject.NULL;
}
result = meta.resolveSymbolOrNull(type, loader, protectionDomain);
}
if (result == null) {
throw meta.throwExceptionWithMessage(meta.java_lang_ClassNotFoundException, NativeUtils.interopPointerToString(namePtr));
}
if (init) {
result.safeInitialize();
}
return result.mirror();
}
use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.
the class VM method JVM_FindClassFromBootLoader.
@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(Class.class)
public StaticObject JVM_FindClassFromBootLoader(@Pointer TruffleObject namePtr) {
String name = NativeUtils.interopPointerToString(namePtr);
if (name == null) {
return StaticObject.NULL;
}
String internalName = name;
if (!name.startsWith("[")) {
// Force 'L' type.
internalName = "L" + name + ";";
}
if (!Validation.validTypeDescriptor(ByteSequence.create(internalName), false)) {
return StaticObject.NULL;
}
Symbol<Type> type = getTypes().fromClassGetName(internalName);
if (Types.isPrimitive(type)) {
return StaticObject.NULL;
}
Klass klass = getMeta().resolveSymbolOrNull(type, StaticObject.NULL, StaticObject.NULL);
if (klass == null) {
return StaticObject.NULL;
}
return klass.mirror();
}
use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.
the class JniEnv method ToReflectedMethod.
// endregion Register/Unregister natives
// region Reflection
/**
* <h3>jobject ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID methodID, jboolean
* isStatic);</h3>
* <p>
* Converts a method ID derived from cls to a java.lang.reflect.Method or
* java.lang.reflect.Constructor object. isStatic must be set to JNI_TRUE if the method ID
* refers to a static field, and JNI_FALSE otherwise.
* <p>
* Throws OutOfMemoryError and returns 0 if fails.
*/
@JniImpl
@JavaType(java.lang.reflect.Executable.class)
public StaticObject ToReflectedMethod(@JavaType(Class.class) StaticObject unused, @Handle(Method.class) long methodId, @SuppressWarnings("unused") boolean isStatic) {
Method method = methodIds.getObject(methodId);
assert method.getDeclaringKlass().isAssignableFrom(unused.getMirrorKlass());
StaticObject methods = null;
if (method.isConstructor()) {
methods = getVM().JVM_GetClassDeclaredConstructors(method.getDeclaringKlass().mirror(), false);
} else {
methods = getVM().JVM_GetClassDeclaredMethods(method.getDeclaringKlass().mirror(), false);
}
for (StaticObject declMethod : methods.<StaticObject[]>unwrap()) {
assert InterpreterToVM.instanceOf(declMethod, getMeta().java_lang_reflect_Executable);
Method m = null;
if (method.isConstructor()) {
assert InterpreterToVM.instanceOf(declMethod, getMeta().java_lang_reflect_Constructor);
m = (Method) getMeta().HIDDEN_CONSTRUCTOR_KEY.getHiddenObject(declMethod);
} else {
assert InterpreterToVM.instanceOf(declMethod, getMeta().java_lang_reflect_Method);
m = (Method) getMeta().HIDDEN_METHOD_KEY.getHiddenObject(declMethod);
}
if (method == m) {
return declMethod;
}
}
throw EspressoError.shouldNotReachHere("Method/constructor not found ", method);
}
use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.
the class JniEnv method GetStaticFieldID.
/**
* <h3>jfieldID GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig);
* </h3>
* <p>
* Returns the field ID for a static field of a class. The field is specified by its name and
* signature. The GetStatic<type>Field and SetStatic<type>Field families of accessor functions
* use field IDs to retrieve static fields.
* <p>
* GetStaticFieldID() causes an uninitialized class to be initialized.
*
* @param clazz a Java class object.
* @param namePtr the static field name in a 0-terminated modified UTF-8 string.
* @param typePtr the field signature in a 0-terminated modified UTF-8 string.
* @return a field ID, or NULL if the specified static field cannot be found.
* @throws NoSuchFieldError if the specified static field 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(Field.class)
public long GetStaticFieldID(@JavaType(Class.class) StaticObject clazz, @Pointer TruffleObject namePtr, @Pointer TruffleObject typePtr) {
String name = NativeUtils.interopPointerToString(namePtr);
String type = NativeUtils.interopPointerToString(typePtr);
assert name != null && type != null;
Field field = null;
Symbol<Name> fieldName = getNames().lookup(name);
if (fieldName != null) {
Symbol<Type> fieldType = getTypes().lookup(type);
if (fieldType != null) {
Klass klass = clazz.getMirrorKlass();
klass.safeInitialize();
// Lookup only if name and type are known symbols.
field = klass.lookupField(fieldName, fieldType, Klass.LookupMode.STATIC_ONLY);
assert field == null || field.getType().equals(fieldType);
}
}
if (field == null || !field.isStatic()) {
Meta meta = getMeta();
throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchFieldError, name);
}
return fieldIds.handlify(field);
}
use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.
the class JniEnv method NewDirectByteBuffer.
// endregion Release*ArrayElements
// region DirectBuffers
/**
* <h3>jobject NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity);</h3>
* <p>
* Allocates and returns a direct java.nio.ByteBuffer referring to the block of memory starting
* at the memory address address and extending capacity bytes.
* <p>
* Native code that calls this function and returns the resulting byte-buffer object to
* Java-level code should ensure that the buffer refers to a valid region of memory that is
* accessible for reading and, if appropriate, writing. An attempt to access an invalid memory
* location from Java code will either return an arbitrary value, have no visible effect, or
* cause an unspecified exception to be thrown.
*
* @param addressPtr the starting address of the memory region (must not be NULL)
* @param capacity the size in bytes of the memory region (must be positive)
* @return a local reference to the newly-instantiated java.nio.ByteBuffer object. Returns NULL
* if an exception occurs, or if JNI access to direct buffers is not supported by this
* virtual machine.
* @throws OutOfMemoryError if allocation of the ByteBuffer object fails
*/
@JniImpl
@JavaType(internalName = "Ljava/nio/DirectByteBuffer;")
public StaticObject NewDirectByteBuffer(@Pointer TruffleObject addressPtr, long capacity) {
Meta meta = getMeta();
StaticObject instance = meta.java_nio_DirectByteBuffer.allocateInstance();
long address = NativeUtils.interopAsPointer(addressPtr);
meta.java_nio_DirectByteBuffer_init_long_int.invokeDirect(instance, address, (int) capacity);
return instance;
}
Aggregations