Search in sources :

Example 6 with Symbol

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

the class JDWPContextImpl method getNestedTypes.

@Override
public KlassRef[] getNestedTypes(KlassRef klass) {
    if (klass instanceof ObjectKlass) {
        ArrayList<KlassRef> result = new ArrayList<>();
        ObjectKlass objectKlass = (ObjectKlass) klass;
        List<Symbol<Symbol.Name>> nestedTypeNames = objectKlass.getNestedTypeNames();
        StaticObject classLoader = objectKlass.getDefiningClassLoader();
        for (Symbol<Symbol.Name> nestedType : nestedTypeNames) {
            Symbol<Symbol.Type> type = context.getTypes().fromClassGetName(nestedType.toString());
            KlassRef loadedKlass = context.getRegistries().findLoadedClass(type, classLoader);
            if (loadedKlass != null && loadedKlass != klass) {
                result.add(loadedKlass);
            }
        }
        return result.toArray(new KlassRef[0]);
    }
    return null;
}
Also used : Symbol(com.oracle.truffle.espresso.descriptors.Symbol) ArrayList(java.util.ArrayList) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) KlassRef(com.oracle.truffle.espresso.jdwp.api.KlassRef)

Example 7 with Symbol

use of com.oracle.truffle.espresso.descriptors.Symbol 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 8 with Symbol

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

the class InnerClassRedefiner method getGlobalClassInfo.

public ImmutableClassInfo getGlobalClassInfo(Klass klass) {
    StaticObject classLoader = klass.getDefiningClassLoader();
    Map<Symbol<Symbol.Name>, ImmutableClassInfo> infos = innerClassInfoMap.get(classLoader);
    if (infos == null) {
        infos = new HashMap<>(1);
        innerClassInfoMap.put(classLoader, infos);
    }
    ImmutableClassInfo result = infos.get(klass.getName());
    if (result == null) {
        result = ClassInfo.create(klass, this);
        infos.put(klass.getName(), result);
    }
    return result;
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Symbol(com.oracle.truffle.espresso.descriptors.Symbol)

Example 9 with Symbol

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

the class InnerClassRedefiner method commit.

public void commit(HotSwapClassInfo[] infos) {
    // first remove the previous info
    for (HotSwapClassInfo info : infos) {
        StaticObject classLoader = info.getClassLoader();
        Map<Symbol<Symbol.Name>, ImmutableClassInfo> classLoaderMap = innerClassInfoMap.get(classLoader);
        if (classLoaderMap != null) {
            classLoaderMap.remove(info.getNewName());
        }
    }
    for (HotSwapClassInfo hotSwapInfo : infos) {
        StaticObject classLoader = hotSwapInfo.getClassLoader();
        Map<Symbol<Symbol.Name>, ImmutableClassInfo> classLoaderMap = innerClassInfoMap.get(classLoader);
        if (classLoaderMap == null) {
            classLoaderMap = new HashMap<>(1);
            innerClassInfoMap.put(classLoader, classLoaderMap);
        }
        // update the cache with the new class info
        classLoaderMap.put(hotSwapInfo.getName(), ClassInfo.copyFrom(hotSwapInfo));
    }
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Symbol(com.oracle.truffle.espresso.descriptors.Symbol)

Example 10 with Symbol

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

the class InnerClassRedefiner method matchAnonymousInnerClasses.

public HotSwapClassInfo[] matchAnonymousInnerClasses(List<RedefineInfo> redefineInfos, List<ObjectKlass> removedInnerClasses) throws RedefintionNotSupportedException {
    hotswapState.clear();
    ArrayList<RedefineInfo> unhandled = new ArrayList<>(redefineInfos);
    Map<Symbol<Symbol.Name>, HotSwapClassInfo> handled = new HashMap<>(redefineInfos.size());
    // build inner/outer relationship from top-level to leaf class in order
    // each round below handles classes where the outer class was previously
    // handled
    int handledSize = 0;
    int previousHandledSize = -1;
    while (!unhandled.isEmpty() && handledSize > previousHandledSize) {
        Iterator<RedefineInfo> it = unhandled.iterator();
        while (it.hasNext()) {
            RedefineInfo redefineInfo = it.next();
            Symbol<Symbol.Name> klassName = ClassfileParser.getClassName(redefineInfo.getClassBytes(), context);
            Matcher matcher = ANON_INNER_CLASS_PATTERN.matcher(klassName.toString());
            if (matcher.matches()) {
                // don't assume that associated old klass instance represents this redefineInfo
                redefineInfo.clearKlass();
                // anonymous inner class or nested named
                // inner class of an anonymous inner class
                // get the outer classinfo if present
                HotSwapClassInfo info = handled.get(getOuterClassName(klassName));
                if (info != null) {
                    HotSwapClassInfo classInfo = ClassInfo.create(klassName, redefineInfo.getClassBytes(), info.getClassLoader(), context);
                    info.addInnerClass(classInfo);
                    handled.put(klassName, classInfo);
                    it.remove();
                }
            } else {
                // pure named class
                it.remove();
                if (redefineInfo.getKlass() != null) {
                    HotSwapClassInfo classInfo = ClassInfo.create(redefineInfo, context);
                    handled.put(klassName, classInfo);
                    hotswapState.put(klassName, classInfo);
                }
            }
        }
        previousHandledSize = handledSize;
        handledSize = handled.size();
    }
    // store renaming rules to be used for constant pool patching when class renaming happens
    Map<StaticObject, Map<Symbol<Symbol.Name>, Symbol<Symbol.Name>>> renamingRules = new HashMap<>(0);
    // begin matching from collected top-level classes
    for (HotSwapClassInfo info : hotswapState.values()) {
        matchClassInfo(info, removedInnerClasses, renamingRules);
    }
    // get the full list of changed classes
    ArrayList<HotSwapClassInfo> result = new ArrayList<>();
    collectAllHotswapClasses(hotswapState.values(), result);
    // now, do the constant pool patching
    for (HotSwapClassInfo classInfo : result) {
        if (classInfo.getBytes() != null) {
            Map<Symbol<Symbol.Name>, Symbol<Symbol.Name>> rules = renamingRules.get(classInfo.getClassLoader());
            if (rules != null && !rules.isEmpty()) {
                try {
                    classInfo.patchBytes(ConstantPoolPatcher.patchConstantPool(classInfo.getBytes(), rules, context));
                } catch (ClassFormatError ex) {
                    throw new RedefintionNotSupportedException(ErrorCodes.INVALID_CLASS_FORMAT);
                }
            }
        }
    }
    hotswapState.clear();
    return result.toArray(new HotSwapClassInfo[0]);
}
Also used : RedefineInfo(com.oracle.truffle.espresso.jdwp.api.RedefineInfo) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) Matcher(java.util.regex.Matcher) Symbol(com.oracle.truffle.espresso.descriptors.Symbol) ArrayList(java.util.ArrayList) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) HashMap(java.util.HashMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap)

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