use of org.objectweb.asm.tree.ClassNode in project presto by prestodb.
the class ClassInfoLoader method readClassInfoQuick.
private ClassInfo readClassInfoQuick(ParameterizedType type) {
// check for user supplied class node
ClassNode classNode = classNodes.get(type);
if (classNode != null) {
return new ClassInfo(this, classNode);
}
// check for user supplied byte code
ClassReader classReader;
byte[] bytecode = bytecodes.get(type);
if (bytecode != null) {
classReader = new ClassReader(bytecode);
} else {
// load class file from class loader
String classFileName = type.getClassName() + ".class";
try (InputStream is = classLoader.getResourceAsStream(classFileName)) {
classReader = new ClassReader(is);
} catch (IOException e) {
// check if class is already loaded
try {
Class<?> aClass = classLoader.loadClass(type.getJavaClassName());
return new ClassInfo(this, aClass);
} catch (ClassNotFoundException e1) {
throw new RuntimeException("Class not found " + type, e);
}
}
}
if (loadMethodNodes) {
// slower version that loads all operations
classNode = new ClassNode();
classReader.accept(new CheckClassAdapter(classNode, false), ClassReader.SKIP_DEBUG);
return new ClassInfo(this, classNode);
} else {
// optimized version
int header = classReader.header;
int access = classReader.readUnsignedShort(header);
char[] buf = new char[2048];
// read super class name
int superClassIndex = classReader.getItem(classReader.readUnsignedShort(header + 4));
ParameterizedType superClass;
if (superClassIndex == 0) {
superClass = null;
} else {
superClass = typeFromPathName(classReader.readUTF8(superClassIndex, buf));
}
// read each interface name
int interfaceCount = classReader.readUnsignedShort(header + 6);
ImmutableList.Builder<ParameterizedType> interfaces = ImmutableList.builder();
header += 8;
for (int i = 0; i < interfaceCount; ++i) {
interfaces.add(typeFromPathName(classReader.readClass(header, buf)));
header += 2;
}
return new ClassInfo(this, type, access, superClass, interfaces.build(), null);
}
}
use of org.objectweb.asm.tree.ClassNode in project presto by prestodb.
the class ClassInfoLoader method createClassInfoLoader.
public static ClassInfoLoader createClassInfoLoader(Iterable<ClassDefinition> classDefinitions, ClassLoader classLoader) {
ImmutableMap.Builder<ParameterizedType, ClassNode> classNodes = ImmutableMap.builder();
for (ClassDefinition classDefinition : classDefinitions) {
ClassNode classNode = new ClassNode();
classDefinition.visit(classNode);
classNodes.put(classDefinition.getType(), classNode);
}
return new ClassInfoLoader(classNodes.build(), ImmutableMap.of(), classLoader, true);
}
use of org.objectweb.asm.tree.ClassNode in project CodeChickenLib by Chicken-Bones.
the class ClassHeirachyManager method declareASM.
private static SuperCache declareASM(byte[] bytes) {
ClassNode node = ASMHelper.createClassNode(bytes);
String name = toKey(node.name);
SuperCache cache = getOrCreateCache(name);
cache.superclass = toKey(node.superName.replace('/', '.'));
cache.add(cache.superclass);
for (String iclass : node.interfaces) cache.add(toKey(iclass.replace('/', '.')));
return cache;
}
use of org.objectweb.asm.tree.ClassNode in project retrolambda by orfjackal.
the class LambdaClassesTest method readClass.
private static ClassNode readClass(String name) throws IOException {
ClassReader cr = new ClassReader(name);
ClassNode cls = new ClassNode();
cr.accept(cls, ClassReader.SKIP_CODE);
return cls;
}
use of org.objectweb.asm.tree.ClassNode in project neo4j by neo4j.
the class ByteCodeVerifier method classNode.
private static ClassNode classNode(ByteBuffer bytecode) {
byte[] bytes;
if (bytecode.hasArray()) {
bytes = bytecode.array();
} else {
bytes = new byte[bytecode.limit()];
bytecode.get(bytes);
}
ClassNode classNode = new ClassNode();
new ClassReader(bytes).accept(new CheckClassAdapter(classNode, false), SKIP_DEBUG);
return classNode;
}
Aggregations