From 22fe5eeaab4a9d94e80266dc8d959cf7518b7075 Mon Sep 17 00:00:00 2001 From: wentch <22250530@qq.com> Date: Thu, 10 Dec 2015 09:39:12 +0800 Subject: [PATCH] --- src/org/redkale/net/sncp/Sncp.java | 26 ++++---- src/org/redkale/net/sncp/SncpDynServlet.java | 6 +- ...thodVisitor.java => AsmMethodVisitor.java} | 6 +- src/org/redkale/util/Creator.java | 60 ------------------- 4 files changed, 19 insertions(+), 79 deletions(-) rename src/org/redkale/util/{DebugMethodVisitor.java => AsmMethodVisitor.java} (94%) diff --git a/src/org/redkale/net/sncp/Sncp.java b/src/org/redkale/net/sncp/Sncp.java index 8bbe487fc..915acbfda 100644 --- a/src/org/redkale/net/sncp/Sncp.java +++ b/src/org/redkale/net/sncp/Sncp.java @@ -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, "", "()V", null, null)); + mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "", "()V", null, null)); //mv.setDebug(true); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, supDynName, "", "()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, "", "()V", null, null)); + mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "", "()V", null, null)); //mv.setDebug(true); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, supDynName, "", "()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); diff --git a/src/org/redkale/net/sncp/SncpDynServlet.java b/src/org/redkale/net/sncp/SncpDynServlet.java index da940fe7e..e5ec123f5 100644 --- a/src/org/redkale/net/sncp/SncpDynServlet.java +++ b/src/org/redkale/net/sncp/SncpDynServlet.java @@ -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, "", "()V", null, null)); + mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "", "()V", null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, supDynName, "", "()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; diff --git a/src/org/redkale/util/DebugMethodVisitor.java b/src/org/redkale/util/AsmMethodVisitor.java similarity index 94% rename from src/org/redkale/util/DebugMethodVisitor.java rename to src/org/redkale/util/AsmMethodVisitor.java index 3bd42caeb..a7b1ceed8 100644 --- a/src/org/redkale/util/DebugMethodVisitor.java +++ b/src/org/redkale/util/AsmMethodVisitor.java @@ -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; } diff --git a/src/org/redkale/util/Creator.java b/src/org/redkale/util/Creator.java index 66e41f022..1faa605bf 100644 --- a/src/org/redkale/util/Creator.java +++ b/src/org/redkale/util/Creator.java @@ -18,66 +18,6 @@ import jdk.internal.org.objectweb.asm.Type; * @param */ public interface Creator { -// -// static class PooledCreator implements Creator { -// -// private final T defValue; -// -// private final Reproduce reproduce; -// -// private final ReferenceQueue refQueue = new ReferenceQueue(); -// -// private final Queue queue; -// -// private final Creator creator; -// -// public PooledCreator(int max, Class clazz, Creator 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 Creator create(int max, Class clazz) { -// return new PooledCreator<>(max, clazz, create(clazz)); -// } -// -// @SuppressWarnings("unchecked") -// public static Creator create(int max, Class clazz, Creator creator) { -// return new PooledCreator<>(max, clazz, creator); -// } public T create(Object... params);