Search in sources :

Example 6 with Name

use of com.oracle.truffle.espresso.descriptors.Symbol.Name in project graal by oracle.

the class VM method defineJavaBaseModule.

@SuppressWarnings("try")
public void defineJavaBaseModule(StaticObject module, String[] packages, SubstitutionProfiler profiler) {
    Meta meta = getMeta();
    StaticObject loader = meta.java_lang_Module_loader.getObject(module);
    if (!StaticObject.isNull(loader)) {
        profiler.profile(10);
        throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "Class loader must be the bootclass loader");
    }
    PackageTable pkgTable = getRegistries().getBootClassRegistry().packages();
    ModuleEntry javaBaseEntry = getRegistries().getJavaBaseModule();
    try (EntryTable.BlockLock block = pkgTable.write()) {
        if (getRegistries().javaBaseDefined()) {
            profiler.profile(9);
            throw meta.throwException(meta.java_lang_InternalError);
        }
        for (String pkg : packages) {
            Symbol<Name> pkgName = getNames().getOrCreate(pkg);
            if (pkgTable.lookup(pkgName) == null) {
                pkgTable.createAndAddEntry(pkgName, javaBaseEntry);
            }
        }
        javaBaseEntry.setModule(module);
        meta.HIDDEN_MODULE_ENTRY.setHiddenObject(module, javaBaseEntry);
        getRegistries().processFixupList(module);
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) EntryTable(com.oracle.truffle.espresso.impl.EntryTable) ModuleEntry(com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry) PackageTable(com.oracle.truffle.espresso.impl.PackageTable) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 7 with Name

use of com.oracle.truffle.espresso.descriptors.Symbol.Name in project graal by oracle.

the class VM method JVM_GetSimpleBinaryName.

@VmImpl(isJni = true)
@JavaType(String.class)
public StaticObject JVM_GetSimpleBinaryName(@JavaType(Class.class) StaticObject self) {
    Klass k = self.getMirrorKlass();
    if (k.isPrimitive() || k.isArray()) {
        return StaticObject.NULL;
    }
    ObjectKlass klass = (ObjectKlass) k;
    RuntimeConstantPool pool = klass.getConstantPool();
    InnerClassesAttribute inner = klass.getInnerClasses();
    for (InnerClassesAttribute.Entry entry : inner.entries()) {
        int innerClassIndex = entry.innerClassIndex;
        if (innerClassIndex != 0) {
            if (pool.classAt(innerClassIndex).getName(pool) == klass.getName()) {
                if (pool.resolvedKlassAt(k, innerClassIndex) == k) {
                    if (entry.innerNameIndex != 0) {
                        Symbol<Name> innerName = pool.symbolAt(entry.innerNameIndex);
                        return getMeta().toGuestString(innerName);
                    } else {
                        break;
                    }
                }
            }
        }
    }
    return StaticObject.NULL;
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) RuntimeConstantPool(com.oracle.truffle.espresso.classfile.RuntimeConstantPool) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) NoSafepoint(com.oracle.truffle.espresso.jni.NoSafepoint) InnerClassesAttribute(com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 8 with Name

use of com.oracle.truffle.espresso.descriptors.Symbol.Name in project graal by oracle.

the class MethodVerifier method verifyInvokeDynamic.

private void verifyInvokeDynamic(int bci, OperandStack stack) {
    // Check padding
    verifyGuarantee(code.readByte(bci + 2) == 0 && code.readByte(bci + 3) == 0, "bytes 3 and 4 after invokedynamic must be 0.");
    PoolConstant pc = poolAt(code.readCPI(bci));
    // Check CP validity
    verifyGuarantee(pc.tag() == ConstantPool.Tag.INVOKEDYNAMIC, "Invalid CP constant for INVOKEDYNAMIC: " + pc.toString());
    pc.validate(pool);
    InvokeDynamicConstant idc = (InvokeDynamicConstant) pc;
    Symbol<Name> name = idc.getName(pool);
    // Check invokedynamic does not call initializers
    verifyGuarantee(!isInstanceInit(name) && !isClassInit(name), "Invalid bootstrap method name: " + name);
    // Check and pop arguments
    Operand[] parsedSig = getOperandSig(idc.getSignature(pool));
    assert parsedSig.length > 0 : "Empty descriptor for method";
    for (int i = parsedSig.length - 2; i >= 0; i--) {
        stack.pop(parsedSig[i]);
    }
    // push result
    Operand returnKind = parsedSig[parsedSig.length - 1];
    if (returnKind != Void) {
        stack.push(returnKind);
    }
}
Also used : PoolConstant(com.oracle.truffle.espresso.classfile.constantpool.PoolConstant) InvokeDynamicConstant(com.oracle.truffle.espresso.classfile.constantpool.InvokeDynamicConstant) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 9 with Name

use of com.oracle.truffle.espresso.descriptors.Symbol.Name in project graal by oracle.

the class MethodVerifier method verifyInvokeInterface.

private void verifyInvokeInterface(int bci, OperandStack stack) {
    // Check padding.
    verifyGuarantee(code.readUByte(bci + 4) == 0, "4th byte after INVOKEINTERFACE must be 0.");
    // Check CP validity
    MethodRefConstant mrc = getMethodRefConstant(bci);
    // Checks versioning
    Symbol<Name> calledMethodName = mrc.getName(pool);
    // Check guest is not invoking <clinit>
    verifyGuarantee(!isClassInit(calledMethodName), "Invocation of class initializer!");
    // Only INVOKESPECIAL can call <init>
    verifyGuarantee(!isInstanceInit(calledMethodName), "Invocation of instance initializer with opcode other than INVOKESPECIAL");
    Symbol<Signature> calledMethodSignature = mrc.getSignature(pool);
    Operand[] parsedSig = getOperandSig(calledMethodSignature);
    // Check signature is well formed.
    assert parsedSig.length > 0 : "Method ref with no return value !";
    // Pop arguments
    // Check signature conforms with count argument
    int count = code.readUByte(bci + 3);
    verifyGuarantee(count > 0, "Invalid count argument for INVOKEINTERFACE: " + count);
    // Has a receiver.
    int descCount = 1;
    for (int i = parsedSig.length - 2; i >= 0; i--) {
        descCount++;
        if (isType2(parsedSig[i])) {
            descCount++;
        }
        stack.pop(parsedSig[i]);
    }
    verifyGuarantee(count == descCount, "Inconsistent redundant argument count for INVOKEINTERFACE.");
    assert Validation.validClassNameEntry(mrc.getHolderKlassName(pool));
    Symbol<Type> methodHolder = getTypes().fromName(mrc.getHolderKlassName(pool));
    Operand methodHolderOp = kindToOperand(methodHolder);
    checkInit(stack.popRef(methodHolderOp));
    Operand returnOp = parsedSig[parsedSig.length - 1];
    if (!(returnOp == Void)) {
        stack.push(returnOp);
    }
}
Also used : Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) MethodRefConstant(com.oracle.truffle.espresso.classfile.constantpool.MethodRefConstant) Signature(com.oracle.truffle.espresso.descriptors.Symbol.Signature) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 10 with Name

use of com.oracle.truffle.espresso.descriptors.Symbol.Name in project graal by oracle.

the class VM method fillInElement.

private void fillInElement(@JavaType(StackTraceElement.class) StaticObject ste, VM.StackElement element, Method classGetName) {
    Method m = element.getMethod();
    Klass k = m.getDeclaringKlass();
    StaticObject guestClass = k.mirror();
    StaticObject loader = k.getDefiningClassLoader();
    ModuleEntry module = k.module();
    // Fill in class name
    getMeta().java_lang_StackTraceElement_declaringClass.setObject(ste, classGetName.invokeDirect(guestClass));
    getMeta().java_lang_StackTraceElement_declaringClassObject.setObject(ste, guestClass);
    // Fill in loader name
    if (!StaticObject.isNull(loader)) {
        StaticObject loaderName = getMeta().java_lang_ClassLoader_name.getObject(loader);
        if (!StaticObject.isNull(loader)) {
            getMeta().java_lang_StackTraceElement_classLoaderName.setObject(ste, loaderName);
        }
    }
    // Fill in method name
    Symbol<Name> mname = m.getName();
    getMeta().java_lang_StackTraceElement_methodName.setObject(ste, getMeta().toGuestString(mname));
    // Fill in module
    if (module.isNamed()) {
        getMeta().java_lang_StackTraceElement_moduleName.setObject(ste, getMeta().toGuestString(module.getName()));
    // TODO: module version
    }
    // Fill in source information
    getMeta().java_lang_StackTraceElement_fileName.setObject(ste, getMeta().toGuestString(m.getSourceFile()));
    getMeta().java_lang_StackTraceElement_lineNumber.setInt(ste, m.bciToLineNumber(element.getBCI()));
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) ModuleEntry(com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry) Method(com.oracle.truffle.espresso.impl.Method) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Aggregations

Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)27 Klass (com.oracle.truffle.espresso.impl.Klass)10 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)9 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)9 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)9 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)8 Meta (com.oracle.truffle.espresso.meta.Meta)8 Method (com.oracle.truffle.espresso.impl.Method)7 BootstrapMethodsAttribute (com.oracle.truffle.espresso.classfile.attributes.BootstrapMethodsAttribute)6 CodeAttribute (com.oracle.truffle.espresso.classfile.attributes.CodeAttribute)6 ConstantValueAttribute (com.oracle.truffle.espresso.classfile.attributes.ConstantValueAttribute)6 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)6 ExceptionsAttribute (com.oracle.truffle.espresso.classfile.attributes.ExceptionsAttribute)6 LineNumberTableAttribute (com.oracle.truffle.espresso.classfile.attributes.LineNumberTableAttribute)6 MethodParametersAttribute (com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute)6 NestHostAttribute (com.oracle.truffle.espresso.classfile.attributes.NestHostAttribute)6 NestMembersAttribute (com.oracle.truffle.espresso.classfile.attributes.NestMembersAttribute)6 PermittedSubclassesAttribute (com.oracle.truffle.espresso.classfile.attributes.PermittedSubclassesAttribute)6 RecordAttribute (com.oracle.truffle.espresso.classfile.attributes.RecordAttribute)6 SignatureAttribute (com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute)6