From 1f8faa8afd0ff57fedee15430f19a41317e571a1 Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Fri, 2 Feb 2018 09:19:42 +0800 Subject: [PATCH] =?UTF-8?q?AsmMethodVisitor=E7=B1=BB=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MethodDebugVisitor.java} | 9 ++-- src/org/redkale/net/http/HttpContext.java | 11 ++--- src/org/redkale/net/http/Rest.java | 45 ++++++++++--------- src/org/redkale/net/sncp/Sncp.java | 25 ++++++----- .../redkale/net/sncp/SncpAsyncHandler.java | 19 ++++---- src/org/redkale/net/sncp/SncpDynServlet.java | 7 +-- 6 files changed, 60 insertions(+), 56 deletions(-) rename src/org/redkale/{util/AsmMethodVisitor.java => asm/MethodDebugVisitor.java} (94%) diff --git a/src/org/redkale/util/AsmMethodVisitor.java b/src/org/redkale/asm/MethodDebugVisitor.java similarity index 94% rename from src/org/redkale/util/AsmMethodVisitor.java rename to src/org/redkale/asm/MethodDebugVisitor.java index ed25a2560..0e444331d 100644 --- a/src/org/redkale/util/AsmMethodVisitor.java +++ b/src/org/redkale/asm/MethodDebugVisitor.java @@ -3,10 +3,9 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package org.redkale.util; +package org.redkale.asm; import java.util.*; -import org.redkale.asm.*; /** * MethodVisitor 的调试类 @@ -15,13 +14,13 @@ import org.redkale.asm.*; * * @author zhangjx */ -public class AsmMethodVisitor { +public class MethodDebugVisitor { private final MethodVisitor visitor; private boolean debug = false; - public AsmMethodVisitor setDebug(boolean d) { + public MethodDebugVisitor setDebug(boolean d) { debug = d; return this; } @@ -55,7 +54,7 @@ public class AsmMethodVisitor { } } - public AsmMethodVisitor(MethodVisitor visitor) { + public MethodDebugVisitor(MethodVisitor visitor) { //super(Opcodes.ASM5, visitor); this.visitor = visitor; } diff --git a/src/org/redkale/net/http/HttpContext.java b/src/org/redkale/net/http/HttpContext.java index 21bb38b09..53a17145b 100644 --- a/src/org/redkale/net/http/HttpContext.java +++ b/src/org/redkale/net/http/HttpContext.java @@ -5,6 +5,7 @@ */ package org.redkale.net.http; +import org.redkale.asm.MethodDebugVisitor; import java.net.*; import java.nio.*; import java.nio.channels.CompletionHandler; @@ -78,7 +79,7 @@ public class HttpContext extends Context { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); FieldVisitor fv; - AsmMethodVisitor mv; + MethodDebugVisitor mv; AnnotationVisitor av0; cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, newDynName, null, handlerinterface ? "java/lang/Object" : handlerClassName, handlerinterface ? new String[]{handlerClassName} : new String[]{handlerName}); @@ -87,7 +88,7 @@ public class HttpContext extends Context { fv.visitEnd(); } {//构造方法 - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "", "(" + handlerDesc + ")V", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "", "(" + handlerDesc + ")V", null, null)); //mv.setDebug(true); { av0 = mv.visitAnnotation("Lorg/redkale/util/ConstructorParameters;", true); @@ -110,7 +111,7 @@ public class HttpContext extends Context { for (java.lang.reflect.Method method : handlerClass.getMethods()) { // if ("completed".equals(method.getName()) && method.getParameterCount() == 2) { - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "completed", Type.getMethodDescriptor(method), null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "completed", Type.getMethodDescriptor(method), null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, newDynName, "handler", handlerDesc); mv.visitVarInsn(ALOAD, 1); @@ -120,7 +121,7 @@ public class HttpContext extends Context { mv.visitMaxs(3, 3); mv.visitEnd(); } else if ("failed".equals(method.getName()) && method.getParameterCount() == 2) { - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "failed", Type.getMethodDescriptor(method), null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "failed", Type.getMethodDescriptor(method), null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, newDynName, "handler", handlerDesc); mv.visitVarInsn(ALOAD, 1); @@ -130,7 +131,7 @@ public class HttpContext extends Context { mv.visitMaxs(3, 3); mv.visitEnd(); } else if (handlerinterface || java.lang.reflect.Modifier.isAbstract(method.getModifiers())) { - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, method.getName(), Type.getMethodDescriptor(method), null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, method.getName(), Type.getMethodDescriptor(method), null, null)); Class returnType = method.getReturnType(); if (returnType == void.class) { mv.visitInsn(RETURN); diff --git a/src/org/redkale/net/http/Rest.java b/src/org/redkale/net/http/Rest.java index 3a2b05688..21df3dc3f 100644 --- a/src/org/redkale/net/http/Rest.java +++ b/src/org/redkale/net/http/Rest.java @@ -5,6 +5,7 @@ */ package org.redkale.net.http; +import org.redkale.asm.MethodDebugVisitor; import java.io.*; import java.lang.annotation.*; import static java.lang.annotation.ElementType.*; @@ -269,7 +270,7 @@ public final class Rest { ClassWriter cw = new ClassWriter(COMPUTE_FRAMES); FieldVisitor fv; - AsmMethodVisitor mv; + MethodDebugVisitor mv; AnnotationVisitor av0; cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, supDynName, null); @@ -319,7 +320,7 @@ public final class Rest { } } { //_DynWebSocketServlet构造函数 - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "", "()V", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "", "()V", null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, supDynName, "", "()V", false); mv.visitVarInsn(ALOAD, 0); @@ -351,7 +352,7 @@ public final class Rest { mv.visitEnd(); } { //createWebSocket 方法 - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PROTECTED, "createWebSocket", "()Lorg/redkale/net/http/WebSocket;", "()Lorg/redkale/net/http/WebSocket;", null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PROTECTED, "createWebSocket", "()Lorg/redkale/net/http/WebSocket;", "()Lorg/redkale/net/http/WebSocket;", null)); mv.visitTypeInsn(NEW, newDynName + "$" + newDynWebSokcetSimpleName); mv.visitInsn(DUP); for (int i = 0; i < resourcesFields.size(); i++) { @@ -364,7 +365,7 @@ public final class Rest { mv.visitEnd(); } { //createRestOnMessageConsumer - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PROTECTED, "createRestOnMessageConsumer", "()Ljava/util/function/BiConsumer;", "()Ljava/util/function/BiConsumer;", null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PROTECTED, "createRestOnMessageConsumer", "()Ljava/util/function/BiConsumer;", "()Ljava/util/function/BiConsumer;", null)); mv.visitTypeInsn(NEW, newDynConsumerFullName); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, newDynConsumerFullName, "", "()V", false); @@ -373,7 +374,7 @@ public final class Rest { mv.visitEnd(); } { //resourceName - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "resourceName", "()Ljava/lang/String;", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "resourceName", "()Ljava/lang/String;", null, null)); mv.visitLdcInsn(rwsname); mv.visitInsn(ARETURN); mv.visitMaxs(1, 1); @@ -417,7 +418,7 @@ public final class Rest { fv.visitEnd(); } { //空构造函数 - mv = new AsmMethodVisitor(cw2.visitMethod(ACC_PUBLIC, "", "()V", null, null)); + mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "", "()V", null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V", false); mv.visitInsn(RETURN); @@ -425,7 +426,7 @@ public final class Rest { mv.visitEnd(); } { //getNames - mv = new AsmMethodVisitor(cw2.visitMethod(ACC_PUBLIC, "getNames", "()[Ljava/lang/String;", null, null)); + mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "getNames", "()[Ljava/lang/String;", null, null)); pushInt(mv, paramap.size()); mv.visitTypeInsn(ANEWARRAY, "java/lang/String"); int index = -1; @@ -440,7 +441,7 @@ public final class Rest { mv.visitEnd(); } { //getValue - mv = new AsmMethodVisitor(cw2.visitMethod(ACC_PUBLIC, "getValue", "(Ljava/lang/String;)Ljava/lang/Object;", "(Ljava/lang/String;)TT;", null)); + mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "getValue", "(Ljava/lang/String;)Ljava/lang/Object;", "(Ljava/lang/String;)TT;", null)); for (Map.Entry en : paramap.entrySet()) { Class paramType = en.getValue().getType(); mv.visitLdcInsn(en.getKey()); @@ -463,7 +464,7 @@ public final class Rest { mv.visitEnd(); } { //execute - mv = new AsmMethodVisitor(cw2.visitMethod(ACC_PUBLIC, "execute", "(L" + newDynWebSokcetFullName + ";)V", null, null)); + mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "execute", "(L" + newDynWebSokcetFullName + ";)V", null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitFieldInsn(PUTFIELD, newDynMessageFullName + endfix, "_redkale_websocket", "L" + newDynWebSokcetFullName + ";"); @@ -477,7 +478,7 @@ public final class Rest { mv.visitEnd(); } { //run - mv = new AsmMethodVisitor(cw2.visitMethod(ACC_PUBLIC, "run", "()V", null, null)); + mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "run", "()V", null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, newDynMessageFullName + endfix, "_redkale_websocket", "L" + newDynWebSokcetFullName + ";"); @@ -492,7 +493,7 @@ public final class Rest { mv.visitEnd(); } { //toString - mv = new AsmMethodVisitor(cw2.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null)); + mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null)); mv.visitMethodInsn(INVOKESTATIC, "org/redkale/convert/json/JsonConvert", "root", "()Lorg/redkale/convert/json/JsonConvert;", false); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "org/redkale/convert/json/JsonConvert", "convertTo", "(Ljava/lang/Object;)Ljava/lang/String;", false); @@ -519,7 +520,7 @@ public final class Rest { fv.visitEnd(); } { //构造函数 - mv = new AsmMethodVisitor(cw2.visitMethod(ACC_PUBLIC, "", "()V", null, null)); + mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "", "()V", null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V", false); mv.visitInsn(RETURN); @@ -527,7 +528,7 @@ public final class Rest { mv.visitEnd(); } { //toString - mv = new AsmMethodVisitor(cw2.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null)); + mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null)); mv.visitMethodInsn(INVOKESTATIC, "org/redkale/convert/json/JsonConvert", "root", "()Lorg/redkale/convert/json/JsonConvert;", false); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "org/redkale/convert/json/JsonConvert", "convertTo", "(Ljava/lang/Object;)Ljava/lang/String;", false); @@ -546,7 +547,7 @@ public final class Rest { cw2.visitInnerClass(newDynWebSokcetFullName, newDynName, newDynWebSokcetSimpleName, ACC_PUBLIC + ACC_STATIC); { - mv = new AsmMethodVisitor(cw2.visitMethod(ACC_PUBLIC, "", "(" + resourceDescriptor + ")V", resourceGenericDescriptor == null ? null : ("(" + resourceGenericDescriptor + ")V"), null)); + mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "", "(" + resourceDescriptor + ")V", resourceGenericDescriptor == null ? null : ("(" + resourceGenericDescriptor + ")V"), null)); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, webSocketInternalName, "", "()V", false); for (int i = 0; i < resourcesFields.size(); i++) { @@ -576,7 +577,7 @@ public final class Rest { } { //构造函数 - mv = new AsmMethodVisitor(cw2.visitMethod(ACC_PUBLIC, "", "()V", null, null)); + mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "", "()V", null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V", false); mv.visitInsn(RETURN); @@ -585,7 +586,7 @@ public final class Rest { } { //accept函数 - mv = new AsmMethodVisitor(cw2.visitMethod(ACC_PUBLIC, "accept", "(Lorg/redkale/net/http/WebSocket;Ljava/lang/Object;)V", null, null)); + mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "accept", "(Lorg/redkale/net/http/WebSocket;Ljava/lang/Object;)V", null, null)); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, newDynWebSokcetFullName); mv.visitVarInsn(ASTORE, 3); @@ -616,7 +617,7 @@ public final class Rest { mv.visitEnd(); } {//虚拟accept函数 - mv = new AsmMethodVisitor(cw2.visitMethod(ACC_PUBLIC + ACC_BRIDGE + ACC_SYNTHETIC, "accept", "(Ljava/lang/Object;Ljava/lang/Object;)V", null, null)); + mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC + ACC_BRIDGE + ACC_SYNTHETIC, "accept", "(Ljava/lang/Object;Ljava/lang/Object;)V", null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, "org/redkale/net/http/WebSocket"); @@ -686,7 +687,7 @@ public final class Rest { if (!checkName(defmodulename)) throw new RuntimeException(serviceType.getName() + " have illeal " + RestService.class.getSimpleName() + ".value, only 0-9 a-z A-Z _ cannot begin 0-9"); ClassWriter cw = new ClassWriter(COMPUTE_FRAMES); FieldVisitor fv; - AsmMethodVisitor mv; + MethodDebugVisitor mv; AnnotationVisitor av0; Map classMap = new LinkedHashMap<>(); List> mappingMaps = new ArrayList<>(); @@ -746,7 +747,7 @@ public final class Rest { fv.visitEnd(); } { //构造函数 - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "", "()V", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "", "()V", null, null)); //mv.setDebug(true); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, supDynName, "", "()V", false); @@ -812,7 +813,7 @@ public final class Rest { final RestConvert[] rcs = method.getAnnotationsByType(RestConvert.class); if (rcs != null && rcs.length > 0) restConverts.add(rcs); - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, entry.name, "(" + reqDesc + respDesc + ")V", null, new String[]{"java/io/IOException"})); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, entry.name, "(" + reqDesc + respDesc + ")V", null, new String[]{"java/io/IOException"})); //mv.setDebug(true); mv.debugLine(); @@ -1668,7 +1669,7 @@ public final class Rest { //classMap.put("mappings", mappingMaps); //不显示太多信息 { //toString函数 - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null)); //mv.setDebug(true); mv.visitLdcInsn(JsonConvert.root().convertTo(classMap)); mv.visitInsn(ARETURN); @@ -1718,7 +1719,7 @@ public final class Rest { return true; } - private static void pushInt(AsmMethodVisitor mv, int num) { + private static void pushInt(MethodDebugVisitor mv, int num) { if (num < 6) { mv.visitInsn(ICONST_0 + num); } else if (num <= Byte.MAX_VALUE) { diff --git a/src/org/redkale/net/sncp/Sncp.java b/src/org/redkale/net/sncp/Sncp.java index 10759ab68..680651797 100644 --- a/src/org/redkale/net/sncp/Sncp.java +++ b/src/org/redkale/net/sncp/Sncp.java @@ -5,6 +5,7 @@ */ package org.redkale.net.sncp; +import org.redkale.asm.MethodDebugVisitor; import java.lang.annotation.Annotation; import java.lang.reflect.*; import java.net.InetSocketAddress; @@ -299,7 +300,7 @@ public abstract class Sncp { //------------------------------------------------------------------------------ ClassWriter cw = new ClassWriter(COMPUTE_FRAMES); FieldVisitor fv; - AsmMethodVisitor mv; + MethodDebugVisitor mv; AnnotationVisitor av0; cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, supDynName, null); @@ -334,7 +335,7 @@ public abstract class Sncp { fv.visitEnd(); } { //构造函数 - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "", "()V", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "", "()V", null, null)); //mv.setDebug(true); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, supDynName, "", "()V", false); @@ -343,7 +344,7 @@ public abstract class Sncp { mv.visitEnd(); } { // toString() - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, newDynName, FIELDPREFIX + "_client", clientDesc); Label l1 = new Label(); @@ -371,7 +372,7 @@ public abstract class Sncp { final Class[] paramtypes = method.getParameterTypes(); final int index = ++i; { //原始方法 - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC + (method.isVarArgs() ? ACC_VARARGS : 0), method.getName(), methodDesc, null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC + (method.isVarArgs() ? ACC_VARARGS : 0), method.getName(), methodDesc, null, null)); //mv.setDebug(true); { //给参数加上 Annotation final Annotation[][] anns = method.getParameterAnnotations(); @@ -430,7 +431,7 @@ public abstract class Sncp { mv.visitEnd(); } { // _方法 _方法比无_方法多了三个参数 - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC + (method.isVarArgs() ? ACC_VARARGS : 0), FIELDPREFIX + "_" + method.getName(), "(ZZZ" + methodDesc.substring(1), null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC + (method.isVarArgs() ? ACC_VARARGS : 0), FIELDPREFIX + "_" + method.getName(), "(ZZZ" + methodDesc.substring(1), null, null)); //mv.setDebug(true); { //给参数加上 Annotation final Annotation[][] anns = method.getParameterAnnotations(); @@ -901,7 +902,7 @@ public abstract class Sncp { //------------------------------------------------------------------------------ ClassWriter cw = new ClassWriter(COMPUTE_FRAMES); FieldVisitor fv; - AsmMethodVisitor mv; + MethodDebugVisitor mv; AnnotationVisitor av0; cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, serviceTypeOrImplClass.isInterface() ? "java/lang/Object" : supDynName, serviceTypeOrImplClass.isInterface() ? new String[]{supDynName} : null); @@ -936,7 +937,7 @@ public abstract class Sncp { fv.visitEnd(); } { //构造函数 - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "", "()V", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "", "()V", null, null)); //mv.setDebug(true); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, serviceTypeOrImplClass.isInterface() ? "java/lang/Object" : supDynName, "", "()V", false); @@ -945,19 +946,19 @@ public abstract class Sncp { mv.visitEnd(); } { //init - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "init", "(" + anyValueDesc + ")V", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "init", "(" + anyValueDesc + ")V", null, null)); mv.visitInsn(RETURN); mv.visitMaxs(0, 2); mv.visitEnd(); } { //destroy - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "destroy", "(" + anyValueDesc + ")V", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "destroy", "(" + anyValueDesc + ")V", null, null)); mv.visitInsn(RETURN); mv.visitMaxs(0, 2); mv.visitEnd(); } { // toString() - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, newDynName, FIELDPREFIX + "_client", clientDesc); Label l1 = new Label(); @@ -981,7 +982,7 @@ public abstract class Sncp { final int index = ++i; final java.lang.reflect.Method method = entry.method; { - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, method.getName(), Type.getMethodDescriptor(method), null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, method.getName(), Type.getMethodDescriptor(method), null, null)); //mv.setDebug(true); { //给参数加上 Annotation final Annotation[][] anns = method.getParameterAnnotations(); @@ -1090,7 +1091,7 @@ public abstract class Sncp { } - private static void pushInt(AsmMethodVisitor mv, int num) { + private static void pushInt(MethodDebugVisitor mv, int num) { if (num < 6) { mv.visitInsn(ICONST_0 + num); } else if (num <= Byte.MAX_VALUE) { diff --git a/src/org/redkale/net/sncp/SncpAsyncHandler.java b/src/org/redkale/net/sncp/SncpAsyncHandler.java index 7b7eb01d6..976669d26 100644 --- a/src/org/redkale/net/sncp/SncpAsyncHandler.java +++ b/src/org/redkale/net/sncp/SncpAsyncHandler.java @@ -5,6 +5,7 @@ */ package org.redkale.net.sncp; +import org.redkale.asm.MethodDebugVisitor; import java.nio.channels.CompletionHandler; import java.util.concurrent.CompletableFuture; import java.util.logging.Level; @@ -107,7 +108,7 @@ public interface SncpAsyncHandler extends CompletionHandler { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); FieldVisitor fv; - AsmMethodVisitor mv; + MethodDebugVisitor mv; AnnotationVisitor av0; cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, newDynName, null, handlerinterface ? "java/lang/Object" : handlerClassName, handlerinterface ? new String[]{handlerClassName, sncpHandlerName} : new String[]{sncpHandlerName}); @@ -120,7 +121,7 @@ public interface SncpAsyncHandler extends CompletionHandler { fv.visitEnd(); } {//构造方法 - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "", "(" + sncpHandlerDesc + ")V", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "", "(" + sncpHandlerDesc + ")V", null, null)); //mv.setDebug(true); { av0 = mv.visitAnnotation("org/redkale/util/ConstructorParameters;", true); @@ -143,7 +144,7 @@ public interface SncpAsyncHandler extends CompletionHandler { for (java.lang.reflect.Method method : handlerClass.getMethods()) { // if ("completed".equals(method.getName()) && method.getParameterCount() == 2) { - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "completed", Type.getMethodDescriptor(method), null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "completed", Type.getMethodDescriptor(method), null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, newDynName, "sncphandler", sncpHandlerDesc); mv.visitVarInsn(ALOAD, 1); @@ -153,7 +154,7 @@ public interface SncpAsyncHandler extends CompletionHandler { mv.visitMaxs(3, 3); mv.visitEnd(); } else if ("failed".equals(method.getName()) && method.getParameterCount() == 2) { - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "failed", Type.getMethodDescriptor(method), null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "failed", Type.getMethodDescriptor(method), null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, newDynName, "sncphandler", sncpHandlerDesc); mv.visitVarInsn(ALOAD, 1); @@ -163,7 +164,7 @@ public interface SncpAsyncHandler extends CompletionHandler { mv.visitMaxs(3, 3); mv.visitEnd(); } else if (handlerinterface || java.lang.reflect.Modifier.isAbstract(method.getModifiers())) { - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, method.getName(), Type.getMethodDescriptor(method), null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, method.getName(), Type.getMethodDescriptor(method), null, null)); Class returnType = method.getReturnType(); if (returnType == void.class) { mv.visitInsn(RETURN); @@ -192,7 +193,7 @@ public interface SncpAsyncHandler extends CompletionHandler { } } { // sncp_getParams - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "sncp_getParams", "()[Ljava/lang/Object;", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "sncp_getParams", "()[Ljava/lang/Object;", null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, newDynName, "sncphandler", sncpHandlerDesc); mv.visitMethodInsn(INVOKEINTERFACE, sncpHandlerName, "sncp_getParams", "()[Ljava/lang/Object;", true); @@ -201,7 +202,7 @@ public interface SncpAsyncHandler extends CompletionHandler { mv.visitEnd(); } { // sncp_setParams - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC + ACC_VARARGS, "sncp_setParams", "([Ljava/lang/Object;)V", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC + ACC_VARARGS, "sncp_setParams", "([Ljava/lang/Object;)V", null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, newDynName, "sncphandler", sncpHandlerDesc); mv.visitVarInsn(ALOAD, 1); @@ -211,7 +212,7 @@ public interface SncpAsyncHandler extends CompletionHandler { mv.visitEnd(); } { // sncp_setFuture - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "sncp_setFuture", "(" + sncpFutureDesc + ")V", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "sncp_setFuture", "(" + sncpFutureDesc + ")V", null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitFieldInsn(PUTFIELD, newDynName, "sncpfuture", sncpFutureDesc); @@ -220,7 +221,7 @@ public interface SncpAsyncHandler extends CompletionHandler { mv.visitEnd(); } { // sncp_getFuture - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "sncp_getFuture", "()" + sncpFutureDesc, null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "sncp_getFuture", "()" + sncpFutureDesc, null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, newDynName, "sncpfuture", sncpFutureDesc); mv.visitInsn(ARETURN); diff --git a/src/org/redkale/net/sncp/SncpDynServlet.java b/src/org/redkale/net/sncp/SncpDynServlet.java index f6f20a265..61ffdc913 100644 --- a/src/org/redkale/net/sncp/SncpDynServlet.java +++ b/src/org/redkale/net/sncp/SncpDynServlet.java @@ -5,6 +5,7 @@ */ package org.redkale.net.sncp; +import org.redkale.asm.MethodDebugVisitor; import static org.redkale.net.sncp.SncpRequest.DEFAULT_HEADER; import java.io.*; import java.lang.annotation.*; @@ -318,7 +319,7 @@ public final class SncpDynServlet extends SncpServlet { //------------------------------------------------------------- ClassWriter cw = new ClassWriter(COMPUTE_FRAMES); FieldVisitor fv; - AsmMethodVisitor mv; + MethodDebugVisitor mv; cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, supDynName, null); @@ -330,7 +331,7 @@ public final class SncpDynServlet extends SncpServlet { fv.visitEnd(); } { // constructor方法 - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "", "()V", null, null)); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "", "()V", null, null)); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, supDynName, "", "()V", false); mv.visitInsn(RETURN); @@ -346,7 +347,7 @@ public final class SncpDynServlet extends SncpServlet { int handlerFuncIndex = -1; Class handlerFuncClass = null; { // action方法 - mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "action", "(" + convertReaderDesc + convertWriterDesc + asyncHandlerDesc + ")V", null, new String[]{"java/lang/Throwable"})); + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "action", "(" + convertReaderDesc + convertWriterDesc + asyncHandlerDesc + ")V", null, new String[]{"java/lang/Throwable"})); //mv.setDebug(true); int iconst = ICONST_1; int intconst = 1;