use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class ObjectGetFieldNode method doForeignValue.
@Specialization(guards = { "receiver.isForeignObject()", "isValueField(context)" })
char doForeignValue(StaticObject receiver, @CachedLibrary(limit = "CACHED_LIBRARY_LIMIT") InteropLibrary interopLibrary, @Bind("getContext()") EspressoContext context, @Cached BranchProfile error) {
try {
String foreignString = interopLibrary.asString(receiver.rawForeignObject());
if (foreignString.length() != 1) {
error.enter();
Meta meta = context.getMeta();
throw meta.throwExceptionWithMessage(meta.java_lang_ClassCastException, "Multicharacter foreign string cannot be cast to char");
}
return foreignString.charAt(0);
} catch (UnsupportedMessageException e) {
error.enter();
Meta meta = context.getMeta();
throw meta.throwExceptionWithMessage(meta.java_lang_ClassCastException, "Non-string foreign object cannot be cast to character");
}
}
use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class EspressoReferenceArrayStoreNode method arrayStore.
public void arrayStore(EspressoContext context, StaticObject value, int index, StaticObject array) {
if (Integer.compareUnsigned(index, array.length()) >= 0) {
enterOutOfBound();
Meta meta = context.getMeta();
throw meta.throwException(meta.java_lang_ArrayIndexOutOfBoundsException);
}
if (!StaticObject.isNull(value) && !instanceOfDynamic.execute(value.getKlass(), ((ArrayKlass) array.getKlass()).getComponentType())) {
enterArrayStoreEx();
Meta meta = context.getMeta();
throw meta.throwException(meta.java_lang_ArrayStoreException);
}
(array.<StaticObject[]>unwrap())[index] = value;
}
use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class InvokeVirtual method methodLookup.
static Method.MethodVersion methodLookup(Method resolutionSeed, Klass receiverKlass) {
if (resolutionSeed.isRemovedByRedefition()) {
/*
* Accept a slow path once the method has been removed put method behind a boundary to
* avoid a deopt loop.
*/
return resolutionSeed.getContext().getClassRedefinition().handleRemovedMethod(resolutionSeed, receiverKlass).getMethodVersion();
}
/*
* Surprisingly, INVOKEVIRTUAL can try to invoke interface methods, even non-default ones.
* Good thing is, miranda methods are taken care of at vtable creation !
*/
int vtableIndex = resolutionSeed.getVTableIndex();
Method.MethodVersion target;
if (receiverKlass.isArray()) {
target = receiverKlass.getSuperKlass().vtableLookup(vtableIndex).getMethodVersion();
} else {
target = receiverKlass.vtableLookup(vtableIndex).getMethodVersion();
}
if (!target.getMethod().hasCode()) {
Meta meta = receiverKlass.getMeta();
throw meta.throwException(meta.java_lang_AbstractMethodError);
}
return target;
}
use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class EspressoBindings method readMember.
@ExportMessage
Object readMember(String member, @CachedLibrary("this") InteropLibrary self, @Exclusive @Cached BranchProfile error) throws UnknownIdentifierException {
if (!isMemberReadable(member)) {
error.enter();
throw UnknownIdentifierException.create(member);
}
EspressoContext context = EspressoContext.get(self);
if (withNativeJavaVM && JAVA_VM.equals(member)) {
return context.getVM().getJavaVM();
}
Meta meta = context.getMeta();
try {
StaticObject clazz = (StaticObject) meta.java_lang_Class_forName_String_boolean_ClassLoader.invokeDirect(null, meta.toGuestString(member), false, loader);
return clazz.getMirrorKlass();
} catch (EspressoException e) {
error.enter();
if (InterpreterToVM.instanceOf(e.getGuestException(), meta.java_lang_ClassNotFoundException)) {
throw UnknownIdentifierException.create(member, e);
}
// exception during class loading
throw e;
}
}
use of com.oracle.truffle.espresso.meta.Meta 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);
}
Aggregations