Search in sources :

Example 1 with Symbol

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

the class BytecodeNode method initArguments.

@ExplodeLoop
private void initArguments(VirtualFrame frame) {
    Object[] arguments = frame.getArguments();
    boolean hasReceiver = !getMethod().isStatic();
    int receiverSlot = hasReceiver ? 1 : 0;
    int curSlot = 0;
    if (hasReceiver) {
        assert StaticObject.notNull((StaticObject) arguments[0]) : "null receiver in init arguments !";
        StaticObject receiver = (StaticObject) arguments[0];
        setLocalObject(frame, curSlot, receiver);
        checkNoForeignObjectAssumption(receiver);
        curSlot += JavaKind.Object.getSlotCount();
    }
    Symbol<Type>[] methodSignature = getMethod().getParsedSignature();
    int argCount = Signatures.parameterCount(methodSignature, false);
    CompilerAsserts.partialEvaluationConstant(argCount);
    for (int i = 0; i < argCount; ++i) {
        Symbol<Type> argType = Signatures.parameterType(methodSignature, i);
        if (argType.length() == 1) {
            // @formatter:off
            switch(argType.byteAt(0)) {
                case 'Z':
                    setLocalInt(frame, curSlot, ((boolean) arguments[i + receiverSlot]) ? 1 : 0);
                    break;
                case 'B':
                    setLocalInt(frame, curSlot, ((byte) arguments[i + receiverSlot]));
                    break;
                case 'S':
                    setLocalInt(frame, curSlot, ((short) arguments[i + receiverSlot]));
                    break;
                case 'C':
                    setLocalInt(frame, curSlot, ((char) arguments[i + receiverSlot]));
                    break;
                case 'I':
                    setLocalInt(frame, curSlot, (int) arguments[i + receiverSlot]);
                    break;
                case 'F':
                    setLocalFloat(frame, curSlot, (float) arguments[i + receiverSlot]);
                    break;
                case 'J':
                    setLocalLong(frame, curSlot, (long) arguments[i + receiverSlot]);
                    ++curSlot;
                    break;
                case 'D':
                    setLocalDouble(frame, curSlot, (double) arguments[i + receiverSlot]);
                    ++curSlot;
                    break;
                default:
                    CompilerDirectives.transferToInterpreter();
                    throw EspressoError.shouldNotReachHere("unexpected kind");
            }
        // @formatter:on
        } else {
            // Reference type.
            StaticObject argument = (StaticObject) arguments[i + receiverSlot];
            setLocalObject(frame, curSlot, argument);
            checkNoForeignObjectAssumption(argument);
        }
        ++curSlot;
    }
}
Also used : Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Symbol(com.oracle.truffle.espresso.descriptors.Symbol) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) TruffleSafepoint(com.oracle.truffle.api.TruffleSafepoint) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 2 with Symbol

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

the class ObjectKlass method getNestedTypeNames.

@TruffleBoundary
public List<Symbol<Name>> getNestedTypeNames() {
    ArrayList<Symbol<Name>> result = new ArrayList<>();
    InnerClassesAttribute innerClasses = getKlassVersion().innerClasses;
    if (innerClasses != null) {
        for (InnerClassesAttribute.Entry entry : innerClasses.entries()) {
            if (entry.innerClassIndex != 0) {
                result.add(getConstantPool().classAt(entry.innerClassIndex).getName(getConstantPool()));
            }
        }
    }
    return result;
}
Also used : Symbol(com.oracle.truffle.espresso.descriptors.Symbol) ArrayList(java.util.ArrayList) InnerClassesAttribute(com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 3 with Symbol

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

the class InnerClassRedefiner method fetchMissingInnerClasses.

private void fetchMissingInnerClasses(HotSwapClassInfo hotswapInfo) throws RedefintionNotSupportedException {
    StaticObject definingLoader = hotswapInfo.getClassLoader();
    ArrayList<Symbol<Symbol.Name>> innerNames = new ArrayList<>(1);
    try {
        searchConstantPoolForInnerClassNames(hotswapInfo, innerNames);
    } catch (ClassFormatError ex) {
        throw new RedefintionNotSupportedException(ErrorCodes.INVALID_CLASS_FORMAT);
    }
    // poke the defining guest classloader for the resources
    for (Symbol<Symbol.Name> innerName : innerNames) {
        if (!hotswapInfo.knowsInnerClass(innerName)) {
            byte[] classBytes = null;
            StaticObject resourceGuestString = context.getMeta().toGuestString(innerName + ".class");
            StaticObject inputStream = (StaticObject) context.getMeta().java_lang_ClassLoader_getResourceAsStream.invokeDirect(definingLoader, resourceGuestString);
            if (StaticObject.notNull(inputStream)) {
                classBytes = readAllBytes(inputStream);
            } else {
            // There is no safe way to retrieve the class bytes using e.g. a scheme using
            // j.l.ClassLoader#loadClass and special marker for the type to have the call
            // end up in defineClass where we could grab the bytes. Guest language
            // classloaders in many cases have caches for the class name that prevents
            // forcefully attempting to load previously not loadable classes.
            // without the class bytes, the matching is less precise and cached un-matched
            // inner class instances that are executed after redefintion will lead to
            // NoSuchMethod errors because they're marked as removed
            }
            if (classBytes != null) {
                hotswapInfo.addInnerClass(ClassInfo.create(innerName, classBytes, definingLoader, context));
            }
        }
    }
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Symbol(com.oracle.truffle.espresso.descriptors.Symbol) ArrayList(java.util.ArrayList)

Example 4 with Symbol

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

the class InnerClassRedefiner method findLoadedInnerClasses.

Set<ObjectKlass> findLoadedInnerClasses(Klass klass) {
    // we use a cache to store inner/outer class mappings
    Map<Symbol<Symbol.Type>, Set<ObjectKlass>> classLoaderMap = innerKlassCache.get(klass.getDefiningClassLoader());
    if (classLoaderMap == null) {
        classLoaderMap = new HashMap<>();
        // register a listener on the registry to fill in
        // future loaded anonymous inner classes
        ClassRegistry classRegistry = context.getRegistries().getClassRegistry(klass.getDefiningClassLoader());
        classRegistry.registerOnLoadListener(new DefineKlassListener() {

            @Override
            public void onKlassDefined(ObjectKlass objectKlass) {
                InnerClassRedefiner.this.onKlassDefined(objectKlass);
            }
        });
        // do a one-time look up of all currently loaded
        // classes for this loader and fill in the map
        List<Klass> loadedKlasses = classRegistry.getLoadedKlasses();
        for (Klass loadedKlass : loadedKlasses) {
            if (loadedKlass instanceof ObjectKlass) {
                ObjectKlass objectKlass = (ObjectKlass) loadedKlass;
                Matcher matcher = ANON_INNER_CLASS_PATTERN.matcher(loadedKlass.getNameAsString());
                if (matcher.matches()) {
                    Symbol<Symbol.Name> outerClassName = getOuterClassName(loadedKlass.getName());
                    if (outerClassName != null && outerClassName.length() > 0) {
                        Symbol<Symbol.Type> outerType = context.getTypes().fromName(outerClassName);
                        Set<ObjectKlass> innerKlasses = classLoaderMap.get(outerType);
                        if (innerKlasses == null) {
                            innerKlasses = new HashSet<>(1);
                            classLoaderMap.put(outerType, innerKlasses);
                        }
                        innerKlasses.add(objectKlass);
                    }
                }
            }
        }
        // add to cache
        innerKlassCache.put(klass.getDefiningClassLoader(), classLoaderMap);
    }
    Set<ObjectKlass> innerClasses = classLoaderMap.get(klass.getType());
    return innerClasses != null ? innerClasses : new HashSet<>(0);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ClassRegistry(com.oracle.truffle.espresso.impl.ClassRegistry) Matcher(java.util.regex.Matcher) Symbol(com.oracle.truffle.espresso.descriptors.Symbol) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass)

Example 5 with Symbol

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

the class InnerClassRedefiner method onKlassDefined.

private void onKlassDefined(ObjectKlass klass) {
    Matcher matcher = ANON_INNER_CLASS_PATTERN.matcher(klass.getNameAsString());
    if (matcher.matches()) {
        Map<Symbol<Symbol.Type>, Set<ObjectKlass>> classLoaderMap = innerKlassCache.get(klass.getDefiningClassLoader());
        // found inner class, now hunt down the outer
        Symbol<Symbol.Name> outerName = getOuterClassName(klass.getName());
        Symbol<Symbol.Type> outerType = context.getTypes().fromName(outerName);
        Set<ObjectKlass> innerKlasses = classLoaderMap.get(outerType);
        if (innerKlasses == null) {
            innerKlasses = new HashSet<>(1);
            classLoaderMap.put(outerType, innerKlasses);
        }
        innerKlasses.add(klass);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Matcher(java.util.regex.Matcher) Symbol(com.oracle.truffle.espresso.descriptors.Symbol) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass)

Aggregations

Symbol (com.oracle.truffle.espresso.descriptors.Symbol)15 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)8 ArrayList (java.util.ArrayList)6 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)4 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)4 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)3 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)3 DebugCloseable (com.oracle.truffle.espresso.perf.DebugCloseable)3 BootstrapMethodsAttribute (com.oracle.truffle.espresso.classfile.attributes.BootstrapMethodsAttribute)2 CodeAttribute (com.oracle.truffle.espresso.classfile.attributes.CodeAttribute)2 ConstantValueAttribute (com.oracle.truffle.espresso.classfile.attributes.ConstantValueAttribute)2 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)2 ExceptionsAttribute (com.oracle.truffle.espresso.classfile.attributes.ExceptionsAttribute)2 LineNumberTableAttribute (com.oracle.truffle.espresso.classfile.attributes.LineNumberTableAttribute)2 MethodParametersAttribute (com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute)2 NestHostAttribute (com.oracle.truffle.espresso.classfile.attributes.NestHostAttribute)2 NestMembersAttribute (com.oracle.truffle.espresso.classfile.attributes.NestMembersAttribute)2 PermittedSubclassesAttribute (com.oracle.truffle.espresso.classfile.attributes.PermittedSubclassesAttribute)2 RecordAttribute (com.oracle.truffle.espresso.classfile.attributes.RecordAttribute)2 SignatureAttribute (com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute)2