Search in sources :

Example 61 with Meta

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);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) NativeSignature(com.oracle.truffle.espresso.ffi.NativeSignature) Signature(com.oracle.truffle.espresso.descriptors.Symbol.Signature) Method(com.oracle.truffle.espresso.impl.Method) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 62 with Meta

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;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) DebugCloseable(com.oracle.truffle.espresso.perf.DebugCloseable)

Example 63 with Meta

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;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) ClassfileStream(com.oracle.truffle.espresso.classfile.ClassfileStream)

Example 64 with Meta

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;
}
Also used : NestHostAttribute(com.oracle.truffle.espresso.classfile.attributes.NestHostAttribute) Meta(com.oracle.truffle.espresso.meta.Meta) RuntimeConstantPool(com.oracle.truffle.espresso.classfile.RuntimeConstantPool)

Example 65 with Meta

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);
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta)

Aggregations

Meta (com.oracle.truffle.espresso.meta.Meta)82 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)29 Method (com.oracle.truffle.espresso.impl.Method)27 ExportMessage (com.oracle.truffle.api.library.ExportMessage)24 Klass (com.oracle.truffle.espresso.impl.Klass)21 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)21 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)21 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)20 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)17 ArityException (com.oracle.truffle.api.interop.ArityException)9 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)9 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)9 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)8 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)6 NativeType (com.oracle.truffle.espresso.ffi.NativeType)4 Field (com.oracle.truffle.espresso.impl.Field)4 ArrayList (java.util.ArrayList)4 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)3 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)3 RuntimeConstantPool (com.oracle.truffle.espresso.classfile.RuntimeConstantPool)3