use of com.oracle.truffle.espresso.classfile.constantpool.NameAndTypeConstant 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);
}
use of com.oracle.truffle.espresso.classfile.constantpool.NameAndTypeConstant in project graal by oracle.
the class ClassInfo method create.
public static HotSwapClassInfo create(ObjectKlass klass, Symbol<Name> name, byte[] bytes, StaticObject definingLoader, EspressoContext context) {
Symbol<Type> type = context.getTypes().fromName(name);
ParserKlass parserKlass = ClassfileParser.parse(new ClassfileStream(bytes, null), definingLoader, type, context);
StringBuilder hierarchy = new StringBuilder();
StringBuilder methods = new StringBuilder();
StringBuilder fields = new StringBuilder();
StringBuilder enclosing = new StringBuilder();
Matcher matcher = InnerClassRedefiner.ANON_INNER_CLASS_PATTERN.matcher(name.toString());
if (matcher.matches()) {
// fingerprints are only relevant for inner classes
hierarchy.append(parserKlass.getSuperKlass().toString()).append(";");
for (Symbol<Type> itf : parserKlass.getSuperInterfaces()) {
hierarchy.append(itf.toString()).append(";");
}
for (ParserMethod method : parserKlass.getMethods()) {
methods.append(method.getName().toString()).append(";");
methods.append(method.getSignature().toString()).append(";");
}
for (ParserField field : parserKlass.getFields()) {
fields.append(field.getType().toString()).append(";");
fields.append(field.getName().toString()).append(";");
}
ConstantPool pool = parserKlass.getConstantPool();
EnclosingMethodAttribute attr = (EnclosingMethodAttribute) parserKlass.getAttribute(EnclosingMethodAttribute.NAME);
NameAndTypeConstant nmt = pool.nameAndTypeAt(attr.getMethodIndex());
enclosing.append(nmt.getName(pool)).append(";").append(nmt.getDescriptor(pool));
}
return new HotSwapClassInfo(klass, name, definingLoader, hierarchy.toString(), methods.toString(), fields.toString(), enclosing.toString(), new ArrayList<>(1), bytes);
}
use of com.oracle.truffle.espresso.classfile.constantpool.NameAndTypeConstant in project graal by oracle.
the class VM method JVM_GetEnclosingMethodInfo.
@VmImpl(isJni = true)
@JavaType(Object[].class)
public StaticObject JVM_GetEnclosingMethodInfo(@JavaType(Class.class) StaticObject self) {
Meta meta = getMeta();
InterpreterToVM vm = meta.getInterpreterToVM();
if (self.getMirrorKlass() instanceof ObjectKlass) {
ObjectKlass klass = (ObjectKlass) self.getMirrorKlass();
EnclosingMethodAttribute enclosingMethodAttr = klass.getEnclosingMethod();
if (enclosingMethodAttr == null) {
return StaticObject.NULL;
}
int classIndex = enclosingMethodAttr.getClassIndex();
if (classIndex == 0) {
return StaticObject.NULL;
}
StaticObject arr = meta.java_lang_Object.allocateReferenceArray(3);
RuntimeConstantPool pool = klass.getConstantPool();
Klass enclosingKlass = pool.resolvedKlassAt(klass, classIndex);
vm.setArrayObject(enclosingKlass.mirror(), 0, arr);
int methodIndex = enclosingMethodAttr.getMethodIndex();
if (methodIndex != 0) {
NameAndTypeConstant nmt = pool.nameAndTypeAt(methodIndex);
StaticObject name = meta.toGuestString(nmt.getName(pool));
StaticObject desc = meta.toGuestString(nmt.getDescriptor(pool));
vm.setArrayObject(name, 1, arr);
vm.setArrayObject(desc, 2, arr);
}
return arr;
}
return StaticObject.NULL;
}
Aggregations