Search in sources :

Example 11 with Name

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

the class MethodVerifier method verifyInvokeSpecial.

private void verifyInvokeSpecial(int bci, OperandStack stack, Locals locals) {
    // Check CP validity
    MethodRefConstant mrc = getMethodRefConstant(bci);
    // Checks versioning
    if (version51OrEarlier()) {
        verifyGuarantee(mrc.tag() != INTERFACE_METHOD_REF, "invokeSpecial refers to an interface method with classfile version " + majorVersion);
    }
    Symbol<Name> calledMethodName = mrc.getName(pool);
    // Check guest is not invoking <clinit>
    verifyGuarantee(!isClassInit(calledMethodName), "Invocation of class initializer!");
    Operand returnOp = popSignatureGetReturnOP(stack, mrc);
    assert Validation.validClassNameEntry(mrc.getHolderKlassName(pool));
    Symbol<Type> methodHolder = getTypes().fromName(mrc.getHolderKlassName(pool));
    Operand methodHolderOp = kindToOperand(methodHolder);
    if (isInstanceInit(calledMethodName)) {
        UninitReferenceOperand toInit = (UninitReferenceOperand) stack.popUninitRef(methodHolderOp);
        if (toInit.isUninitThis()) {
            verifyGuarantee(Name._init_.equals(methodName), "Encountered UninitializedThis outside of Constructor: " + toInit);
            boolean isValidInitThis = toInit.getType() == methodHolder || // have been handled by the previous check.
            toInit.getKlass().getSuperKlass().getType() == methodHolder;
            verifyGuarantee(isValidInitThis, "<init> method must call this.<init> or super.<init>");
            calledConstructor = true;
        } else {
            verifyGuarantee(code.opcode(toInit.newBCI) == NEW, "There is no NEW bytecode at bci: " + toInit.newBCI);
            // according to JCK's "vm/classfmt/ins/instr_03608m1" :
            // 
            // Calling parent's initializer of uninitialized new object is
            // illegal, but serialization does just that.
            // 
            // In particular, it generates a class whose method executes NEW
            // j.l.Number (an abstract class), then calls j.l.Object.<init> on
            // it.
            // 
            // A workaround would be to check if the underlying class is
            // abstract/interface, but that would feel really silly...
            verifyGuarantee(toInit.getType() == methodHolder, "Calling wrong initializer for a new object.");
        }
        Operand stackOp = stack.initUninit(toInit);
        locals.initUninit(toInit, stackOp);
        checkProtectedMember(stackOp, methodHolder, mrc, true);
    } else {
        verifyGuarantee(checkMethodSpecialAccess(methodHolderOp), "invokespecial must specify a method in this class or a super class");
        Operand stackOp = checkInit(stack.popRef(methodHolderOp));
        /**
         * 4.10.1.9.invokespecial:
         *
         * invokespecial, for other than an instance initialization method, must name a method
         * in the current class/interface or a superclass / superinterface.
         */
        verifyGuarantee(checkReceiverSpecialAccess(stackOp), "Invalid use of INVOKESPECIAL");
    }
    if (!(returnOp == Void)) {
        stack.push(returnOp);
    }
}
Also used : Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) MethodRefConstant(com.oracle.truffle.espresso.classfile.constantpool.MethodRefConstant) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 12 with Name

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

the class ClassInfo method create.

public static ImmutableClassInfo create(Klass klass, InnerClassRedefiner innerClassRedefiner) {
    StringBuilder hierarchy = new StringBuilder();
    StringBuilder methods = new StringBuilder();
    StringBuilder fields = new StringBuilder();
    StringBuilder enclosing = new StringBuilder();
    Symbol<Name> name = klass.getName();
    Matcher matcher = InnerClassRedefiner.ANON_INNER_CLASS_PATTERN.matcher(name.toString());
    if (matcher.matches()) {
        // fingerprints are only relevant for inner classes
        hierarchy.append(klass.getSuperClass().getTypeAsString()).append(";");
        for (Klass itf : klass.getImplementedInterfaces()) {
            hierarchy.append(itf.getTypeAsString()).append(";");
        }
        for (Method method : klass.getDeclaredMethods()) {
            methods.append(method.getNameAsString()).append(";");
            methods.append(method.getSignatureAsString()).append(";");
        }
        for (Field field : klass.getDeclaredFields()) {
            fields.append(field.getTypeAsString()).append(";");
            fields.append(field.getNameAsString()).append(";");
        }
        ObjectKlass objectKlass = (ObjectKlass) klass;
        ConstantPool pool = klass.getConstantPool();
        NameAndTypeConstant nmt = pool.nameAndTypeAt(objectKlass.getEnclosingMethod().getMethodIndex());
        enclosing.append(nmt.getName(pool)).append(";").append(nmt.getDescriptor(pool));
    }
    // find all currently loaded direct inner classes and create class infos
    ArrayList<ImmutableClassInfo> inners = new ArrayList<>(1);
    Set<ObjectKlass> loadedInnerClasses = innerClassRedefiner.findLoadedInnerClasses(klass);
    for (Klass inner : loadedInnerClasses) {
        matcher = InnerClassRedefiner.ANON_INNER_CLASS_PATTERN.matcher(inner.getNameAsString());
        // only add anonymous inner classes
        if (matcher.matches()) {
            inners.add(innerClassRedefiner.getGlobalClassInfo(inner));
        }
    }
    return new ImmutableClassInfo((ObjectKlass) klass, name, klass.getDefiningClassLoader(), hierarchy.toString(), methods.toString(), fields.toString(), enclosing.toString(), inners, null);
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ParserMethod(com.oracle.truffle.espresso.impl.ParserMethod) Method(com.oracle.truffle.espresso.impl.Method) NameAndTypeConstant(com.oracle.truffle.espresso.classfile.constantpool.NameAndTypeConstant) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name) Field(com.oracle.truffle.espresso.impl.Field) ParserField(com.oracle.truffle.espresso.impl.ParserField) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ParserKlass(com.oracle.truffle.espresso.impl.ParserKlass) ConstantPool(com.oracle.truffle.espresso.classfile.ConstantPool)

Example 13 with Name

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

the class Substitutions method registerStaticSubstitution.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static void registerStaticSubstitution(JavaSubstitution.Factory substitutorFactory) {
    List<Symbol<Type>> parameterTypes = new ArrayList<>();
    for (int i = substitutorFactory.hasReceiver() ? 1 : 0; i < substitutorFactory.parameterTypes().length; i++) {
        String type = substitutorFactory.parameterTypes()[i];
        parameterTypes.add(StaticSymbols.putType(type));
    }
    Symbol<Type> returnType = StaticSymbols.putType(substitutorFactory.returnType());
    Symbol<Signature> signature = StaticSymbols.putSignature(returnType, parameterTypes.toArray(Symbol.EMPTY_ARRAY));
    EspressoRootNodeFactory factory = new EspressoRootNodeFactory() {

        @Override
        public EspressoRootNode createNodeIfValid(Method methodToSubstitute, boolean forceValid) {
            if (!substitutorFactory.isValidFor(methodToSubstitute.getJavaVersion())) {
                return null;
            }
            StaticObject classLoader = methodToSubstitute.getDeclaringKlass().getDefiningClassLoader();
            if (forceValid || ClassRegistry.loaderIsBootOrPlatform(classLoader, methodToSubstitute.getMeta())) {
                return EspressoRootNode.create(null, new IntrinsicSubstitutorNode(substitutorFactory, methodToSubstitute));
            }
            getLogger().warning(new Supplier<String>() {

                @Override
                public String get() {
                    StaticObject givenLoader = methodToSubstitute.getDeclaringKlass().getDefiningClassLoader();
                    return "Static substitution for " + methodToSubstitute + " does not apply.\n" + "\tExpected class loader: Boot (null) or platform class loader\n" + "\tGiven class loader: " + EspressoInterop.toDisplayString(givenLoader, false) + "\n";
                }
            });
            return null;
        }
    };
    String[] classNames = substitutorFactory.substitutionClassNames();
    String[] methodNames = substitutorFactory.getMethodNames();
    for (int i = 0; i < classNames.length; i++) {
        assert classNames[i].startsWith("Target_");
        Symbol<Type> classType = StaticSymbols.putType("L" + classNames[i].substring("Target_".length()).replace('_', '/') + ";");
        Symbol<Name> methodName = StaticSymbols.putName(methodNames[i]);
        registerStaticSubstitution(classType, methodName, signature, factory, true);
    }
}
Also used : Symbol(com.oracle.truffle.espresso.descriptors.Symbol) ArrayList(java.util.ArrayList) Method(com.oracle.truffle.espresso.impl.Method) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Signature(com.oracle.truffle.espresso.descriptors.Symbol.Signature) IntrinsicSubstitutorNode(com.oracle.truffle.espresso.nodes.IntrinsicSubstitutorNode)

Example 14 with Name

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

the class Target_java_lang_invoke_MethodHandleNatives method getMembers.

// TODO(garcia) verifyConstants
@Substitution
public static int getMembers(@JavaType(Class.class) StaticObject defc, @JavaType(String.class) StaticObject matchName, @JavaType(String.class) StaticObject matchSig, int matchFlags, @JavaType(Class.class) StaticObject originalCaller, int skip, @JavaType(internalName = "[Ljava/lang/invoke/MemberName;") StaticObject resultsArr, @Inject Meta meta) {
    if (StaticObject.isNull(defc) || StaticObject.isNull(resultsArr)) {
        return -1;
    }
    EspressoContext context = meta.getContext();
    StaticObject[] results = resultsArr.unwrap();
    Symbol<Name> name = null;
    if (!StaticObject.isNull(matchName)) {
        name = context.getNames().lookup(meta.toHostString(matchName));
        if (name == null) {
            return 0;
        }
    }
    String sig = meta.toHostString(matchSig);
    if (sig == null) {
        return 0;
    }
    Klass caller = null;
    if (!StaticObject.isNull(originalCaller)) {
        caller = originalCaller.getMirrorKlass();
        if (caller == null) {
            return -1;
        }
    }
    return findMemberNames(defc.getMirrorKlass(), name, sig, matchFlags, caller, skip, results);
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) EspressoContext(com.oracle.truffle.espresso.runtime.EspressoContext) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 15 with Name

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

the class VM method computeEnclosingClass.

/**
 * Return the enclosing class; or null for: primitives, arrays, anonymous classes (declared
 * inside methods).
 */
private static Klass computeEnclosingClass(ObjectKlass klass) {
    InnerClassesAttribute innerClasses = (InnerClassesAttribute) klass.getAttribute(InnerClassesAttribute.NAME);
    if (innerClasses == null) {
        return null;
    }
    RuntimeConstantPool pool = klass.getConstantPool();
    boolean found = false;
    Klass outerKlass = null;
    for (InnerClassesAttribute.Entry entry : innerClasses.entries()) {
        if (entry.innerClassIndex != 0) {
            Symbol<Name> innerDescriptor = pool.classAt(entry.innerClassIndex).getName(pool);
            // Check decriptors/names before resolving.
            if (innerDescriptor.equals(klass.getName())) {
                Klass innerKlass = pool.resolvedKlassAt(klass, entry.innerClassIndex);
                found = (innerKlass == klass);
                if (found && entry.outerClassIndex != 0) {
                    outerKlass = pool.resolvedKlassAt(klass, entry.outerClassIndex);
                }
            }
        }
        if (found) {
            break;
        }
    }
    // the system could allow a spoof of an inner class to gain access rights.
    return outerKlass;
}
Also used : RuntimeConstantPool(com.oracle.truffle.espresso.classfile.RuntimeConstantPool) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) InnerClassesAttribute(com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute) 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