use of org.apache.tapestry5.internal.plastic.asm.tree.MethodNode in project tapestry-5 by apache.
the class Analyzer method computeInitialFrame.
/**
* Computes the initial execution stack frame of the given method.
*
* @param owner the internal name of the class to which 'method' belongs.
* @param method the method to be analyzed.
* @return the initial execution stack frame of the 'method'.
*/
private Frame<V> computeInitialFrame(final String owner, final MethodNode method) {
Frame<V> frame = newFrame(method.maxLocals, method.maxStack);
int currentLocal = 0;
boolean isInstanceMethod = (method.access & ACC_STATIC) == 0;
if (isInstanceMethod) {
Type ownerType = Type.getObjectType(owner);
frame.setLocal(currentLocal, interpreter.newParameterValue(isInstanceMethod, currentLocal, ownerType));
currentLocal++;
}
Type[] argumentTypes = Type.getArgumentTypes(method.desc);
for (Type argumentType : argumentTypes) {
frame.setLocal(currentLocal, interpreter.newParameterValue(isInstanceMethod, currentLocal, argumentType));
currentLocal++;
if (argumentType.getSize() == 2) {
frame.setLocal(currentLocal, interpreter.newEmptyValue(currentLocal));
currentLocal++;
}
}
while (currentLocal < method.maxLocals) {
frame.setLocal(currentLocal, interpreter.newEmptyValue(currentLocal));
currentLocal++;
}
frame.setReturn(interpreter.newReturnTypeValue(Type.getReturnType(method.desc)));
return frame;
}
use of org.apache.tapestry5.internal.plastic.asm.tree.MethodNode in project tapestry-5 by apache.
the class CheckClassAdapter method printAnalyzerResult.
static void printAnalyzerResult(final MethodNode method, final Analyzer<BasicValue> analyzer, final PrintWriter printWriter) {
Textifier textifier = new Textifier();
TraceMethodVisitor traceMethodVisitor = new TraceMethodVisitor(textifier);
printWriter.println(method.name + method.desc);
for (int i = 0; i < method.instructions.size(); ++i) {
method.instructions.get(i).accept(traceMethodVisitor);
StringBuilder stringBuilder = new StringBuilder();
Frame<BasicValue> frame = analyzer.getFrames()[i];
if (frame == null) {
stringBuilder.append('?');
} else {
for (int j = 0; j < frame.getLocals(); ++j) {
stringBuilder.append(getUnqualifiedName(frame.getLocal(j).toString())).append(' ');
}
stringBuilder.append(" : ");
for (int j = 0; j < frame.getStackSize(); ++j) {
stringBuilder.append(getUnqualifiedName(frame.getStack(j).toString())).append(' ');
}
}
while (stringBuilder.length() < method.maxStack + method.maxLocals + 1) {
stringBuilder.append(' ');
}
printWriter.print(Integer.toString(i + 100000).substring(1));
printWriter.print(" " + stringBuilder + " : " + textifier.text.get(textifier.text.size() - 1));
}
for (TryCatchBlockNode tryCatchBlock : method.tryCatchBlocks) {
tryCatchBlock.accept(traceMethodVisitor);
printWriter.print(" " + textifier.text.get(textifier.text.size() - 1));
}
printWriter.println();
}
use of org.apache.tapestry5.internal.plastic.asm.tree.MethodNode in project tapestry-5 by apache.
the class CheckClassAdapter method verify.
/**
* Checks the given class.
*
* @param classReader the class to be checked.
* @param loader a <code>ClassLoader</code> which will be used to load referenced classes. May be
* {@literal null}.
* @param printResults whether to print the results of the bytecode verification.
* @param printWriter where the results (or the stack trace in case of error) must be printed.
*/
public static void verify(final ClassReader classReader, final ClassLoader loader, final boolean printResults, final PrintWriter printWriter) {
ClassNode classNode = new ClassNode();
classReader.accept(new CheckClassAdapter(/*latest*/
Opcodes.ASM10_EXPERIMENTAL, classNode, false) {
}, ClassReader.SKIP_DEBUG);
Type syperType = classNode.superName == null ? null : Type.getObjectType(classNode.superName);
List<MethodNode> methods = classNode.methods;
List<Type> interfaces = new ArrayList<>();
for (String interfaceName : classNode.interfaces) {
interfaces.add(Type.getObjectType(interfaceName));
}
for (MethodNode method : methods) {
SimpleVerifier verifier = new SimpleVerifier(Type.getObjectType(classNode.name), syperType, interfaces, (classNode.access & Opcodes.ACC_INTERFACE) != 0);
Analyzer<BasicValue> analyzer = new Analyzer<>(verifier);
if (loader != null) {
verifier.setClassLoader(loader);
}
try {
analyzer.analyze(classNode.name, method);
} catch (AnalyzerException e) {
e.printStackTrace(printWriter);
}
if (printResults) {
printAnalyzerResult(method, analyzer, printWriter);
}
}
printWriter.flush();
}
use of org.apache.tapestry5.internal.plastic.asm.tree.MethodNode in project tapestry-5 by apache.
the class MethodAdviceManager method createNewMethod.
private void createNewMethod() {
String[] exceptions = advisedMethodNode.exceptions == null ? null : advisedMethodNode.exceptions.toArray(new String[0]);
// Remove the private flag, so that the MethodInvocation implementation (in the same package)
// can directly access the method without an additional access method.
MethodNode mn = new MethodNode(advisedMethodNode.access & ~Opcodes.ACC_PRIVATE, newMethodName, advisedMethodNode.desc, advisedMethodNode.signature, exceptions);
// Copy everything else about the advisedMethodNode over to the new node
advisedMethodNode.accept(mn);
// Add this new method, with the same implementation as the original method, to the
// PlasticClass
plasticClass.classNode.methods.add(mn);
}
use of org.apache.tapestry5.internal.plastic.asm.tree.MethodNode in project tapestry-5 by apache.
the class PlasticClassImpl method getJavaParameterTypes.
private static List<Class> getJavaParameterTypes(MethodNode methodNode) {
final ClassLoader classLoader = PlasticInternalUtils.class.getClassLoader();
Type[] parameterTypes = Type.getArgumentTypes(methodNode.desc);
List<Class> list = new ArrayList<>();
for (Type type : parameterTypes) {
try {
list.add(PlasticInternalUtils.toClass(classLoader, type.getClassName()));
} catch (ClassNotFoundException e) {
// shouldn't happen anyway
throw new RuntimeException(e);
}
}
return list;
}
Aggregations