This commit is contained in:
wentch
2015-12-10 09:39:12 +08:00
parent 84ebb4ccc3
commit 22fe5eeaab
4 changed files with 19 additions and 79 deletions

View File

@@ -254,7 +254,7 @@ public abstract class Sncp {
//------------------------------------------------------------------------------
ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);
FieldVisitor fv;
DebugMethodVisitor mv;
AsmMethodVisitor mv;
AnnotationVisitor av0;
cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, supDynName, null);
@@ -287,7 +287,7 @@ public abstract class Sncp {
fv.visitEnd();
}
{ //构造函数
mv = new DebugMethodVisitor(cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null));
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null));
//mv.setDebug(true);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, supDynName, "<init>", "()V", false);
@@ -296,14 +296,14 @@ public abstract class Sncp {
mv.visitEnd();
}
{ // name()
mv = new DebugMethodVisitor(cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "name", "()Ljava/lang/String;", null, null));
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "name", "()Ljava/lang/String;", null, null));
mv.visitLdcInsn(name);
mv.visitInsn(ARETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{ // toString()
mv = new DebugMethodVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null));
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null));
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, newDynName, "_selfstring", "Ljava/lang/String;");
Label l1 = new Label();
@@ -329,7 +329,7 @@ public abstract class Sncp {
final Class[] paramtypes = method.getParameterTypes();
final int index = ++i;
{ //原始方法
mv = new DebugMethodVisitor(cw.visitMethod(ACC_PUBLIC + (method.isVarArgs() ? ACC_VARARGS : 0), method.getName(), methodDesc, null, null));
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC + (method.isVarArgs() ? ACC_VARARGS : 0), method.getName(), methodDesc, null, null));
//mv.setDebug(true);
{ //给参数加上 Annotation
final Annotation[][] anns = method.getParameterAnnotations();
@@ -381,7 +381,7 @@ public abstract class Sncp {
mv.visitEnd();
}
{ // _方法
mv = new DebugMethodVisitor(cw.visitMethod(ACC_PUBLIC + (method.isVarArgs() ? ACC_VARARGS : 0), "_" + method.getName(), "(ZZZ" + methodDesc.substring(1), null, null));
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC + (method.isVarArgs() ? ACC_VARARGS : 0), "_" + method.getName(), "(ZZZ" + methodDesc.substring(1), null, null));
//mv.setDebug(true);
{ //给参数加上 Annotation
final Annotation[][] anns = method.getParameterAnnotations();
@@ -909,7 +909,7 @@ public abstract class Sncp {
//------------------------------------------------------------------------------
ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);
FieldVisitor fv;
DebugMethodVisitor mv;
AsmMethodVisitor mv;
AnnotationVisitor av0;
cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, supDynName, null);
@@ -936,7 +936,7 @@ public abstract class Sncp {
fv.visitEnd();
}
{ //构造函数
mv = new DebugMethodVisitor(cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null));
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null));
//mv.setDebug(true);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, supDynName, "<init>", "()V", false);
@@ -945,26 +945,26 @@ public abstract class Sncp {
mv.visitEnd();
}
{ //init
mv = new DebugMethodVisitor(cw.visitMethod(ACC_PUBLIC, "init", "(" + anyValueDesc + ")V", null, null));
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "init", "(" + anyValueDesc + ")V", null, null));
mv.visitInsn(RETURN);
mv.visitMaxs(0, 2);
mv.visitEnd();
}
{ //destroy
mv = new DebugMethodVisitor(cw.visitMethod(ACC_PUBLIC, "destroy", "(" + anyValueDesc + ")V", null, null));
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "destroy", "(" + anyValueDesc + ")V", null, null));
mv.visitInsn(RETURN);
mv.visitMaxs(0, 2);
mv.visitEnd();
}
{ // name()
mv = new DebugMethodVisitor(cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "name", "()Ljava/lang/String;", null, null));
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "name", "()Ljava/lang/String;", null, null));
mv.visitLdcInsn(name);
mv.visitInsn(ARETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{ // toString()
mv = new DebugMethodVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null));
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null));
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, newDynName, "_selfstring", "Ljava/lang/String;");
Label l1 = new Label();
@@ -986,7 +986,7 @@ public abstract class Sncp {
final int index = ++i;
final java.lang.reflect.Method method = entry.method;
{
mv = new DebugMethodVisitor(cw.visitMethod(ACC_PUBLIC, method.getName(), Type.getMethodDescriptor(method), null, null));
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, method.getName(), Type.getMethodDescriptor(method), null, null));
//mv.setDebug(true);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, newDynName, "_client", clientDesc);

View File

@@ -188,7 +188,7 @@ public final class SncpDynServlet extends SncpServlet {
//-------------------------------------------------------------
ClassWriter cw = new ClassWriter(0);
FieldVisitor fv;
DebugMethodVisitor mv;
AsmMethodVisitor mv;
cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, supDynName, null);
@@ -200,7 +200,7 @@ public final class SncpDynServlet extends SncpServlet {
fv.visitEnd();
}
{ // constructor方法
mv = new DebugMethodVisitor(cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null));
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null));
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, supDynName, "<init>", "()V", false);
mv.visitInsn(RETURN);
@@ -214,7 +214,7 @@ public final class SncpDynServlet extends SncpServlet {
throw new RuntimeException(ex); //不可能会发生
}
{ // action方法
mv = new DebugMethodVisitor(cw.visitMethod(ACC_PUBLIC, "action", "(" + convertReaderDesc + convertWriterDesc + ")V", null, new String[]{"java/lang/Throwable"}));
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "action", "(" + convertReaderDesc + convertWriterDesc + ")V", null, new String[]{"java/lang/Throwable"}));
//mv.setDebug(true);
int iconst = ICONST_1;
int intconst = 1;

View File

@@ -12,13 +12,13 @@ import jdk.internal.org.objectweb.asm.*;
*
* @author zhangjx
*/
public class DebugMethodVisitor {
public class AsmMethodVisitor {
private final MethodVisitor visitor;
private boolean debug = false;
public DebugMethodVisitor setDebug(boolean d) {
public AsmMethodVisitor setDebug(boolean d) {
debug = d;
return this;
}
@@ -45,7 +45,7 @@ public class DebugMethodVisitor {
}
}
public DebugMethodVisitor(MethodVisitor visitor) {
public AsmMethodVisitor(MethodVisitor visitor) {
//super(Opcodes.ASM5, visitor);
this.visitor = visitor;
}

View File

@@ -18,66 +18,6 @@ import jdk.internal.org.objectweb.asm.Type;
* @param <T>
*/
public interface Creator<T> {
//
// static class PooledCreator<T> implements Creator<T> {
//
// private final T defValue;
//
// private final Reproduce<T, T> reproduce;
//
// private final ReferenceQueue<T> refQueue = new ReferenceQueue();
//
// private final Queue<T> queue;
//
// private final Creator<T> creator;
//
// public PooledCreator(int max, Class<T> clazz, Creator<T> creator) {
// this.creator = creator;
// this.defValue = creator.create();
// this.reproduce = Reproduce.create(clazz, clazz);
// this.queue = new ArrayBlockingQueue<>(Math.max(Runtime.getRuntime().availableProcessors() * 2, max));
// new Thread() {
// {
// setDaemon(true);
// setName(PooledCreator.class.getSimpleName() + " " + clazz.getSimpleName() + " Reference Handler");
// }
//
// @Override
// public void run() {
// try {
// for (;;) {
// T r = refQueue.remove().get();
// if (r == null) continue;
// reproduce.copy(r, defValue);
// queue.offer(r);
// }
// } catch (Exception e) {
// //do nothind
// }
// }
// }.start();
// }
//
// @Override
// public T create(Object... params) {
// T rs = queue.poll();
// if (rs == null) {
// rs = creator.create(params);
// }
// return new WeakReference<>(rs, refQueue).get();
// }
//
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Creator<T> create(int max, Class<T> clazz) {
// return new PooledCreator<>(max, clazz, create(clazz));
// }
//
// @SuppressWarnings("unchecked")
// public static <T> Creator<T> create(int max, Class<T> clazz, Creator<T> creator) {
// return new PooledCreator<>(max, clazz, creator);
// }
public T create(Object... params);