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;
}
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);
}
}
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;
}
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));
}
}
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]);
}
Aggregations