visitLocalVariable

This commit is contained in:
redkale
2024-10-13 10:45:10 +08:00
parent 909b813573
commit 1cc659276b
10 changed files with 142 additions and 6 deletions

View File

@@ -165,6 +165,8 @@ public abstract class JsonDynEncoder<T> extends ObjectEncoder<JsonWriter, T> {
mv = (cw.visitMethod(
ACC_PUBLIC, "<init>", "(" + jsonfactoryDesc + typeDesc + objEncoderDesc + ")V", null, null));
// mv.setDebug(true);
Label label0 = new Label();
mv.visitLabel(label0);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 2);
@@ -210,12 +212,21 @@ public abstract class JsonDynEncoder<T> extends ObjectEncoder<JsonWriter, T> {
mv.visitFieldInsn(PUTFIELD, newDynName, fieldName + "FirstFieldChars", "[C");
}
mv.visitInsn(RETURN);
Label label2 = new Label();
mv.visitLabel(label2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, label0, label2, 0);
mv.visitLocalVariable("factory", jsonfactoryDesc, null, label0, label2, 1);
mv.visitLocalVariable("type", typeDesc, null, label0, label2, 2);
mv.visitLocalVariable("objectEncoderSelf", objEncoderDesc, null, label0, label2, 3);
mv.visitMaxs(1 + elements.size(), 1 + elements.size());
mv.visitEnd();
}
{ // convertTo 方法
mv = (cw.visitMethod(ACC_PUBLIC, "convertTo", "(" + jsonwriterDesc + valtypeDesc + ")V", null, null));
Label commaLabel = null;
Label label0 = new Label();
mv.visitLabel(label0);
// mv.setDebug(true);
{ // if (value == null) { out.writeObjectNull(null); return; }
mv.visitVarInsn(ALOAD, 2);
@@ -432,6 +443,8 @@ public abstract class JsonDynEncoder<T> extends ObjectEncoder<JsonWriter, T> {
if (!mustHadComma) { // boolean comma = false;
mv.visitInsn(ICONST_0);
mv.visitVarInsn(ISTORE, 3);
commaLabel = new Label();
mv.visitLabel(commaLabel);
}
for (AccessibleObject element : elements) {
elementIndex++;
@@ -658,6 +671,14 @@ public abstract class JsonDynEncoder<T> extends ObjectEncoder<JsonWriter, T> {
}
}
mv.visitInsn(RETURN);
Label label2 = new Label();
mv.visitLabel(label2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, label0, label2, 0);
mv.visitLocalVariable("out", "Lorg/redkale/convert/json/JsonWriter;", null, label0, label2, 1);
mv.visitLocalVariable("value", "Lorg/redkale/test/convert/json/Message;", null, label0, label2, 2);
if (commaLabel != null) {
mv.visitLocalVariable("comma", "Z", null, commaLabel, label2, 3);
}
mv.visitMaxs(maxLocals, maxLocals);
mv.visitEnd();
}

View File

@@ -134,6 +134,8 @@ public abstract class ProtobufDynEncoder<T> extends ProtobufObjectEncoder<T> {
{ // 构造函数
mv = (cw.visitMethod(
ACC_PUBLIC, "<init>", "(" + pbfactoryDesc + typeDesc + pbencoderDesc + ")V", null, null));
Label label0 = new Label();
mv.visitLabel(label0);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 2);
@@ -141,12 +143,20 @@ public abstract class ProtobufDynEncoder<T> extends ProtobufObjectEncoder<T> {
mv.visitMethodInsn(
INVOKESPECIAL, supDynName, "<init>", "(" + pbfactoryDesc + typeDesc + pbencoderDesc + ")V", false);
mv.visitInsn(RETURN);
Label label2 = new Label();
mv.visitLabel(label2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, label0, label2, 0);
mv.visitLocalVariable("factory", pbfactoryDesc, null, label0, label2, 1);
mv.visitLocalVariable("type", typeDesc, null, label0, label2, 2);
mv.visitLocalVariable("objectEncoder", pbencoderDesc, null, label0, label2, 3);
mv.visitMaxs(4, 4);
mv.visitEnd();
}
{ // convertTo 方法
mv = (cw.visitMethod(
ACC_PUBLIC, "convertTo", "(" + pbwriterDesc + enMemberDesc + valtypeDesc + ")V", null, null));
Label label0 = new Label();
mv.visitLabel(label0);
// if (value == null) return;
mv.visitVarInsn(ALOAD, 3); // value
Label ifLabel = new Label();
@@ -168,6 +178,8 @@ public abstract class ProtobufDynEncoder<T> extends ProtobufObjectEncoder<T> {
"(" + pbwriterDesc + enMemberDesc + objectDesc + ")" + pbwriterDesc,
false);
mv.visitVarInsn(ASTORE, 4);
Label sublabel = new Label();
mv.visitLabel(sublabel);
mv.visitVarInsn(ALOAD, 4);
mv.visitVarInsn(ALOAD, 3);
@@ -291,6 +303,13 @@ public abstract class ProtobufDynEncoder<T> extends ProtobufObjectEncoder<T> {
INVOKEVIRTUAL, newDynName, "offerWriter", "(" + pbwriterDesc + pbwriterDesc + ")V", false);
mv.visitInsn(RETURN);
Label label2 = new Label();
mv.visitLabel(label2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, label0, label2, 0);
mv.visitLocalVariable("out", pbwriterDesc, null, label0, label2, 1);
mv.visitLocalVariable("parentMember", enMemberDesc, null, label0, label2, 2);
mv.visitLocalVariable("value", valtypeDesc, null, label0, label2, 3);
mv.visitLocalVariable("subout", pbwriterDesc, null, sublabel, label2, 4);
mv.visitMaxs(4, 3);
mv.visitEnd();
}

View File

@@ -553,8 +553,8 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
final String interDesc = org.redkale.asm.Type.getDescriptor(this.getClass());
final String requestSupDesc = org.redkale.asm.Type.getDescriptor(Request.class);
final String responseSupDesc = org.redkale.asm.Type.getDescriptor(Response.class);
final String requestDesc = org.redkale.asm.Type.getDescriptor(HttpRequest.class);
final String responseDesc = org.redkale.asm.Type.getDescriptor(HttpResponse.class);
final String reqDesc = org.redkale.asm.Type.getDescriptor(HttpRequest.class);
final String respDesc = org.redkale.asm.Type.getDescriptor(HttpResponse.class);
final String factfield = "_factServlet";
StringBuilder tmpps = new StringBuilder();
for (Class cz : method.getParameterTypes()) {
@@ -593,16 +593,22 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
mv.visitEnd();
}
{
mv = (cw.visitMethod(ACC_PUBLIC, "execute", "(" + requestDesc + responseDesc + ")V", null, new String[] {
mv = (cw.visitMethod(ACC_PUBLIC, "execute", "(" + reqDesc + respDesc + ")V", null, new String[] {
"java/io/IOException"
}));
Label label0 = new Label();
mv.visitLabel(label0);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, newDynName, factfield, interDesc);
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(
INVOKEVIRTUAL, interName, method.getName(), "(" + requestDesc + responseDesc + ")V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, interName, method.getName(), "(" + reqDesc + respDesc + ")V", false);
mv.visitInsn(RETURN);
Label label2 = new Label();
mv.visitLabel(label2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, label0, label2, 0);
mv.visitLocalVariable("req", reqDesc, null, label0, label2, 1);
mv.visitLocalVariable("resp", respDesc, null, label0, label2, 2);
mv.visitMaxs(3, 3);
mv.visitEnd();
}
@@ -618,7 +624,7 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
mv.visitTypeInsn(CHECKCAST, HttpRequest.class.getName().replace('.', '/'));
mv.visitVarInsn(ALOAD, 2);
mv.visitTypeInsn(CHECKCAST, HttpResponse.class.getName().replace('.', '/'));
mv.visitMethodInsn(INVOKEVIRTUAL, newDynName, "execute", "(" + requestDesc + responseDesc + ")V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, newDynName, "execute", "(" + reqDesc + respDesc + ")V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(3, 3);
mv.visitEnd();

View File

@@ -2136,6 +2136,8 @@ public final class Rest {
ACC_PUBLIC, entry.newMethodName, "(" + reqDesc + respDesc + ")V", null, new String[] {
"java/io/IOException"
}));
Label label0 = new Label();
mv.visitLabel(label0);
// mv.setDebug(true);
mv.debugLine();
@@ -3990,6 +3992,11 @@ public final class Rest {
mv.visitInsn(RETURN);
maxLocals++;
}
Label label2 = new Label();
mv.visitLabel(label2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, label0, label2, 0);
mv.visitLocalVariable("req", reqDesc, null, label0, label2, 1);
mv.visitLocalVariable("resp", respDesc, null, label0, label2, 2);
mv.visitMaxs(maxStack, maxLocals);
mappingMap.put("params", paramMaps);
@@ -4013,6 +4020,8 @@ public final class Rest {
}
{
mv = new MethodDebugVisitor(cw2.visitMethod(0, "<init>", "(L" + newDynName + ";)V", null, null));
Label sublabel0 = new Label();
mv.visitLabel(sublabel0);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, httpServletName, "<init>", "()V", false);
mv.visitVarInsn(ALOAD, 0);
@@ -4026,6 +4035,16 @@ public final class Rest {
mv.visitInsn(entry.nonBlocking ? ICONST_1 : ICONST_0);
mv.visitFieldInsn(PUTFIELD, newDynName + "$" + entry.newActionClassName, "_nonBlocking", "Z");
mv.visitInsn(RETURN);
Label sublabel2 = new Label();
mv.visitLabel(sublabel2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, sublabel0, sublabel2, 0);
mv.visitLocalVariable(
"parentServlet",
"L" + newDynName + "$" + entry.newActionClassName + ";",
null,
sublabel0,
sublabel2,
1);
mv.visitMaxs(2, 2);
mv.visitEnd();
}
@@ -4045,6 +4064,8 @@ public final class Rest {
cw2.visitMethod(ACC_PUBLIC, "execute", "(" + reqDesc + respDesc + ")V", null, new String[] {
"java/io/IOException"
}));
Label sublabel0 = new Label();
mv.visitLabel(sublabel0);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(
GETFIELD,
@@ -4056,6 +4077,11 @@ public final class Rest {
mv.visitMethodInsn(
INVOKEVIRTUAL, newDynName, entry.newMethodName, "(" + reqDesc + respDesc + ")V", false);
mv.visitInsn(RETURN);
Label sublabel2 = new Label();
mv.visitLabel(sublabel2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, sublabel0, sublabel2, 0);
mv.visitLocalVariable("req", reqDesc, null, sublabel0, sublabel2, 1);
mv.visitLocalVariable("resp", respDesc, null, sublabel0, sublabel2, 2);
mv.visitMaxs(3, 3);
mv.visitEnd();
}

View File

@@ -127,6 +127,8 @@ public abstract class EntityFullFunc<T> {
}
{ // getObject(DataResultSetRow row)
mv = cw.visitMethod(ACC_PUBLIC, "getObject", "(" + rowDesc + ")" + entityDesc, null, null);
Label label0 = new Label();
mv.visitLabel(label0);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "wasNull", "()Z", true);
Label ifLabel = new Label();
@@ -143,6 +145,8 @@ public abstract class EntityFullFunc<T> {
mv.visitMethodInsn(INVOKEINTERFACE, creatorName, "create", "([Ljava/lang/Object;)Ljava/lang/Object;", true);
mv.visitTypeInsn(CHECKCAST, entityName);
mv.visitVarInsn(ASTORE, 2);
Label label1 = new Label();
mv.visitLabel(label1);
for (int i = 0; i < attrs.length; i++) {
final int colIndex = i + 1;
@@ -442,6 +446,11 @@ public abstract class EntityFullFunc<T> {
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitInsn(ARETURN);
Label label2 = new Label();
mv.visitLabel(label2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, label0, label2, 0);
mv.visitLocalVariable("row", rowDesc, null, label0, label2, 1);
mv.visitLocalVariable("obj", entityDesc, null, label1, label2, 2);
mv.visitMaxs(5, 3);
mv.visitEnd();
}
@@ -458,6 +467,8 @@ public abstract class EntityFullFunc<T> {
{ // getObject(Serializable... values)
mv = cw.visitMethod(ACC_PUBLIC | ACC_VARARGS, "getObject", "(" + serisDesc + ")" + entityDesc, null, null);
Label label0 = new Label();
mv.visitLabel(label0);
// creator.create()
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, supDynName, "creator", creatorDesc);
@@ -466,6 +477,8 @@ public abstract class EntityFullFunc<T> {
mv.visitMethodInsn(INVOKEINTERFACE, creatorName, "create", "([Ljava/lang/Object;)" + objectDesc, true);
mv.visitTypeInsn(CHECKCAST, entityName);
mv.visitVarInsn(ASTORE, 2);
Label label1 = new Label();
mv.visitLabel(label1);
for (int i = 0; i < attrs.length; i++) {
final int attrIndex = i;
@@ -777,6 +790,11 @@ public abstract class EntityFullFunc<T> {
}
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitInsn(ARETURN);
Label label2 = new Label();
mv.visitLabel(label2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, label0, label2, 0);
mv.visitLocalVariable("values", serisDesc, null, label0, label2, 1);
mv.visitLocalVariable("obj", entityDesc, null, label1, label2, 2);
mv.visitMaxs(3, 3);
mv.visitEnd();
}

View File

@@ -1102,6 +1102,8 @@ public interface Attribute<T, F> {
}
{ // get 方法
mv = cw.visitMethod(ACC_PUBLIC, "get", "(" + interDesc + ")" + columnDesc, null, null);
Label label0 = new Label();
mv.visitLabel(label0);
int m = 1;
if (tgetter == null) {
if (tfield == null) {
@@ -1142,11 +1144,17 @@ public interface Attribute<T, F> {
}
}
mv.visitInsn(ARETURN);
Label label2 = new Label();
mv.visitLabel(label2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, label0, label2, 0);
mv.visitLocalVariable("obj", interDesc, null, label0, label2, 1);
mv.visitMaxs(m, 2);
mv.visitEnd();
}
{ // set 方法
mv = cw.visitMethod(ACC_PUBLIC, "set", "(" + interDesc + columnDesc + ")V", null, null);
Label label0 = new Label();
mv.visitLabel(label0);
int m = 2;
if (tsetter == null) {
if (tfield == null || java.lang.reflect.Modifier.isFinal(tfield.getModifiers())) {
@@ -1187,6 +1195,11 @@ public interface Attribute<T, F> {
INVOKEVIRTUAL, interName, tsetter.getName(), Type.getMethodDescriptor(tsetter), false);
}
mv.visitInsn(RETURN);
Label label2 = new Label();
mv.visitLabel(label2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, label0, label2, 0);
mv.visitLocalVariable("obj", interDesc, null, label0, label2, 1);
mv.visitLocalVariable("value", columnDesc, null, label0, label2, 2);
mv.visitMaxs(m, 3);
mv.visitEnd();
}

View File

@@ -719,6 +719,8 @@ public interface Copier<S, D> extends BiFunction<S, D, D> {
if (srcIsMap) { // Map -> JavaBean
{
mv = (cw.visitMethod(ACC_PUBLIC, "apply", "(" + srcDesc + destDesc + ")" + destDesc, null, null));
Label label0 = new Label();
mv.visitLabel(label0);
// mv.setDebug(true);
{
// if(src == null) return null;
@@ -760,6 +762,11 @@ public interface Copier<S, D> extends BiFunction<S, D, D> {
srcClass.isInterface());
mv.visitVarInsn(ALOAD, 2);
mv.visitInsn(ARETURN);
Label label2 = new Label();
mv.visitLabel(label2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, label0, label2, 0);
mv.visitLocalVariable("src", srcDesc, null, label0, label2, 1);
mv.visitLocalVariable("dest", destDesc, null, label0, label2, 2);
mv.visitMaxs(2, 3);
mv.visitEnd();
}
@@ -841,6 +848,8 @@ public interface Copier<S, D> extends BiFunction<S, D, D> {
}
} else { // JavaBean -> Map/JavaBean
mv = (cw.visitMethod(ACC_PUBLIC, "apply", "(" + srcDesc + destDesc + ")" + destDesc, null, null));
Label label0 = new Label();
mv.visitLabel(label0);
// mv.setDebug(true);
{
// if(src == null) return null;
@@ -1310,6 +1319,11 @@ public interface Copier<S, D> extends BiFunction<S, D, D> {
}
mv.visitVarInsn(ALOAD, 2);
mv.visitInsn(ARETURN);
Label label2 = new Label();
mv.visitLabel(label2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, label0, label2, 0);
mv.visitLocalVariable("src", srcDesc, null, label0, label2, 1);
mv.visitLocalVariable("dest", destDesc, null, label0, label2, 2);
mv.visitMaxs(3, 3);
mv.visitEnd();
}

View File

@@ -461,6 +461,8 @@ public interface Creator<T> {
{ // create 方法
mv = cw.visitMethod(
ACC_PUBLIC + ACC_VARARGS, "create", "([Ljava/lang/Object;)L" + interName + ";", null, null);
Label label0 = new Label();
mv.visitLabel(label0);
if (constructorParameters.length > 0 && constructorParameters[0] != null) {
av0 = mv.visitAnnotation(Type.getDescriptor(ConstructorParameters.class), true);
AnnotationVisitor av1 = av0.visitArray("value");
@@ -547,6 +549,10 @@ public interface Creator<T> {
// ---------------------------------------
mv.visitMethodInsn(INVOKESPECIAL, interName, "<init>", Type.getConstructorDescriptor(constructor), false);
mv.visitInsn(ARETURN);
Label label2 = new Label();
mv.visitLabel(label2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, label0, label2, 0);
mv.visitLocalVariable("params", "[Ljava/lang/Object;", null, label0, label2, 1);
mv.visitMaxs(3, 2);
mv.visitEnd();
}

View File

@@ -264,9 +264,15 @@ class Inners {
}
{ // apply 方法
mv = cw.visitMethod(ACC_PUBLIC, "apply", "(I)[" + interDesc, null, null);
Label label0 = new Label();
mv.visitLabel(label0);
mv.visitVarInsn(ILOAD, 1);
mv.visitTypeInsn(ANEWARRAY, interName);
mv.visitInsn(ARETURN);
Label label2 = new Label();
mv.visitLabel(label2);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, label0, label2, 0);
mv.visitLocalVariable("size", "I", null, label0, label2, 1);
mv.visitMaxs(1, 2);
mv.visitEnd();
}

View File

@@ -134,6 +134,8 @@ public interface Invoker<C, R> {
"(" + interDesc + "[Ljava/lang/Object;)" + returnDesc,
null,
null));
Label label00 = new Label();
mv.visitLabel(label00);
Label label0 = new Label();
Label label1 = new Label();
@@ -182,6 +184,11 @@ public interface Invoker<C, R> {
INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/Throwable;)V", false);
mv.visitInsn(ATHROW);
}
Label label22 = new Label();
mv.visitLabel(label22);
mv.visitLocalVariable("this", "L" + newDynName + ";", null, label00, label22, 0);
mv.visitLocalVariable("obj", interDesc, null, label00, label22, 1);
mv.visitLocalVariable("params", "[Ljava/lang/Object;", null, label00, label22, 2);
mv.visitMaxs(3 + method.getParameterCount(), 4);
mv.visitEnd();
}