use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class JniEnv method GetStaticMethodID.
/**
* <h3>jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name, const char
* *sig);</h3>
* <p>
* Returns the method ID for a static method of a class. The method is specified by its name and
* signature.
* <p>
* GetStaticMethodID() causes an uninitialized class to be initialized.
*
* @param clazz a Java class object.
* @param namePtr the static method name in a 0-terminated modified UTF-8 string.
* @param signaturePtr the method signature in a 0-terminated modified UTF-8 string.
* @return a method ID, or NULL if the operation fails.
* @throws NoSuchMethodError if the specified static 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 GetStaticMethodID(@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) {
// Throw a NoSuchMethodError exception if we have an instance of a
// primitive java.lang.Class
Klass klass = clazz.getMirrorKlass();
if (klass.isPrimitive()) {
Meta meta = getMeta();
throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchMethodError, name);
}
klass.safeInitialize();
// Lookup only if name and type are known symbols.
if (Name._clinit_.equals(methodName)) {
// Never search superclasses for static initializers.
method = klass.lookupDeclaredMethod(methodName, methodSignature);
} else {
method = klass.lookupMethod(methodName, methodSignature);
}
}
}
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.meta.Meta in project graal by oracle.
the class ClassRegistry method defineKlass.
@SuppressWarnings("try")
public ObjectKlass defineKlass(Symbol<Type> typeOrNull, final byte[] bytes, ClassDefinitionInfo info) {
Meta meta = getMeta();
ParserKlass parserKlass;
try (DebugCloseable parse = KLASS_PARSE.scope(getContext().getTimers())) {
parserKlass = getParserKlass(bytes, typeOrNull, info);
}
Symbol<Type> type = typeOrNull == null ? parserKlass.getType() : typeOrNull;
if (info.addedToRegistry()) {
Klass maybeLoaded = findLoadedKlass(type);
if (maybeLoaded != null) {
throw meta.throwExceptionWithMessage(meta.java_lang_LinkageError, "Class " + type + " already defined");
}
}
Symbol<Type> superKlassType = parserKlass.getSuperKlass();
ObjectKlass klass = createKlass(meta, parserKlass, type, superKlassType, info);
if (info.addedToRegistry()) {
registerKlass(klass, type);
} else if (info.isStrongHidden()) {
registerStrongHiddenClass(klass);
}
return klass;
}
use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class ClassRegistry method getParserKlass.
private ParserKlass getParserKlass(byte[] bytes, Symbol<Type> typeOrNull, ClassDefinitionInfo info) {
// May throw guest ClassFormatError, NoClassDefFoundError.
ParserKlass parserKlass = ClassfileParser.parse(new ClassfileStream(bytes, null), getClassLoader(), typeOrNull, context, info);
Meta meta = getMeta();
if (!loaderIsBootOrPlatform(getClassLoader(), meta) && parserKlass.getName().toString().startsWith("java/")) {
throw meta.throwExceptionWithMessage(meta.java_lang_SecurityException, "Define class in prohibited package name: " + parserKlass.getName());
}
return parserKlass;
}
use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class ObjectKlass method nest.
@Override
public Klass nest() {
if (nest == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
NestHostAttribute nestHost = (NestHostAttribute) getAttribute(NestHostAttribute.NAME);
if (nestHost == null) {
nest = this;
} else {
RuntimeConstantPool thisPool = getConstantPool();
Klass host = thisPool.resolvedKlassAt(this, nestHost.hostClassIndex);
if (!host.nestMembersCheck(this)) {
Meta meta = getMeta();
throw meta.throwException(meta.java_lang_IncompatibleClassChangeError);
}
nest = host;
}
}
return nest;
}
use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class VirtualTable method checkOverride.
private static void checkOverride(ObjectKlass superKlass, Method.MethodVersion m, ArrayList<Method.MethodVersion> tmp, ObjectKlass.KlassVersion thisKlass, ArrayList<Method.MethodVersion> overrides, boolean isRedefinition) {
if (!overrides.isEmpty()) {
overrides.clear();
}
if (superKlass != null) {
superKlass.lookupVirtualMethodOverrides(m.getMethod(), thisKlass.getKlass(), overrides);
}
Method.MethodVersion toSet = m;
if (!overrides.isEmpty()) {
int count = 1;
for (Method.MethodVersion override : overrides) {
if (override.isFinalFlagSet()) {
Meta meta = m.getMethod().getDeclaringKlass().getMeta();
if (meta.getJavaVersion().java16OrLater()) {
throw meta.throwExceptionWithMessage(meta.java_lang_IncompatibleClassChangeError, "Overriding final method: " + override);
} else {
throw meta.throwExceptionWithMessage(meta.java_lang_VerifyError, "Overriding final method: " + override);
}
}
override.invalidateLeaf();
int pos = override.getVTableIndex();
if (count > 1) {
toSet = new Method(m.getMethod()).getMethodVersion();
}
toSet.setVTableIndex(pos, isRedefinition);
tmp.set(pos, toSet);
count++;
}
} else {
int pos = tmp.size();
toSet.setVTableIndex(pos, isRedefinition);
tmp.add(toSet);
}
}
Aggregations