You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by danielsun1106 <gi...@git.apache.org> on 2017/02/10 16:23:09 UTC

[GitHub] groovy pull request #496: Add a ASMifier tab to AstBrowser

GitHub user danielsun1106 opened a pull request:

    https://github.com/apache/groovy/pull/496

    Add a ASMifier tab to AstBrowser

    **Source code:**
    ```groovy
    println 123
    ```
    
    **The output of ASMifier:**
    ```java
    import java.util.*;
    import org.objectweb.asm.*;
    public class script1486743662486Dump implements Opcodes {
    
    public static byte[] dump () throws Exception {
    
    ClassWriter cw = new ClassWriter(0);
    FieldVisitor fv;
    MethodVisitor mv;
    AnnotationVisitor av0;
    
    cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "script1486743662486", null, "groovy/lang/Script", null);
    
    cw.visitSource("script1486743662486.groovy", null);
    
    {
    fv = cw.visitField(ACC_PRIVATE + ACC_STATIC + ACC_SYNTHETIC, "$staticClassInfo", "Lorg/codehaus/groovy/reflection/ClassInfo;", null, null);
    fv.visitEnd();
    }
    {
    fv = cw.visitField(ACC_PUBLIC + ACC_STATIC + ACC_TRANSIENT + ACC_SYNTHETIC, "__$stMC", "Z", null, null);
    fv.visitEnd();
    }
    {
    fv = cw.visitField(ACC_PRIVATE + ACC_STATIC + ACC_SYNTHETIC, "$callSiteArray", "Ljava/lang/ref/SoftReference;", null, null);
    fv.visitEnd();
    }
    {
    mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "groovy/lang/Script", "<init>", "()V", false);
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitMethodInsn(INVOKESTATIC, "script1486743662486", "$getCallSiteArray", "()[Lorg/codehaus/groovy/runtime/callsite/CallSite;", false);
    mv.visitVarInsn(ASTORE, 1);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("this", "Lscript1486743662486;", null, l0, l1, 0);
    mv.visitMaxs(1, 2);
    mv.visitEnd();
    }
    {
    mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(Lgroovy/lang/Binding;)V", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitMethodInsn(INVOKESTATIC, "script1486743662486", "$getCallSiteArray", "()[Lorg/codehaus/groovy/runtime/callsite/CallSite;", false);
    mv.visitVarInsn(ASTORE, 2);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKESPECIAL, "groovy/lang/Script", "<init>", "(Lgroovy/lang/Binding;)V", false);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("this", "Lscript1486743662486;", null, l0, l1, 0);
    mv.visitLocalVariable("context", "Lgroovy/lang/Binding;", null, l0, l1, 1);
    mv.visitMaxs(2, 3);
    mv.visitEnd();
    }
    {
    mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC + ACC_VARARGS, "main", "([Ljava/lang/String;)V", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitMethodInsn(INVOKESTATIC, "script1486743662486", "$getCallSiteArray", "()[Lorg/codehaus/groovy/runtime/callsite/CallSite;", false);
    mv.visitVarInsn(ASTORE, 1);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitLdcInsn(new Integer(0));
    mv.visitInsn(AALOAD);
    mv.visitLdcInsn(Type.getType("Lorg/codehaus/groovy/runtime/InvokerHelper;"));
    mv.visitLdcInsn(Type.getType("Lscript1486743662486;"));
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKEINTERFACE, "org/codehaus/groovy/runtime/callsite/CallSite", "call", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
    mv.visitInsn(POP);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("args", "[Ljava/lang/String;", null, l0, l1, 0);
    mv.visitMaxs(4, 2);
    mv.visitEnd();
    }
    {
    mv = cw.visitMethod(ACC_PUBLIC, "run", "()Ljava/lang/Object;", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitMethodInsn(INVOKESTATIC, "script1486743662486", "$getCallSiteArray", "()[Lorg/codehaus/groovy/runtime/callsite/CallSite;", false);
    mv.visitVarInsn(ASTORE, 1);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLineNumber(1, l1);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitLdcInsn(new Integer(1));
    mv.visitInsn(AALOAD);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitIntInsn(BIPUSH, 123);
    mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
    mv.visitMethodInsn(INVOKEINTERFACE, "org/codehaus/groovy/runtime/callsite/CallSite", "callCurrent", "(Lgroovy/lang/GroovyObject;Ljava/lang/Object;)Ljava/lang/Object;", true);
    mv.visitInsn(ARETURN);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitInsn(ACONST_NULL);
    mv.visitInsn(ARETURN);
    mv.visitLocalVariable("this", "Lscript1486743662486;", null, l0, l2, 0);
    mv.visitMaxs(3, 2);
    mv.visitEnd();
    }
    {
    mv = cw.visitMethod(ACC_PROTECTED + ACC_SYNTHETIC, "$getStaticMetaClass", "()Lgroovy/lang/MetaClass;", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false);
    mv.visitLdcInsn(Type.getType("Lscript1486743662486;"));
    Label l0 = new Label();
    mv.visitJumpInsn(IF_ACMPEQ, l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/ScriptBytecodeAdapter", "initMetaClass", "(Ljava/lang/Object;)Lgroovy/lang/MetaClass;", false);
    mv.visitInsn(ARETURN);
    mv.visitLabel(l0);
    mv.visitFieldInsn(GETSTATIC, "script1486743662486", "$staticClassInfo", "Lorg/codehaus/groovy/reflection/ClassInfo;");
    mv.visitVarInsn(ASTORE, 1);
    mv.visitVarInsn(ALOAD, 1);
    Label l1 = new Label();
    mv.visitJumpInsn(IFNONNULL, l1);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false);
    mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/reflection/ClassInfo", "getClassInfo", "(Ljava/lang/Class;)Lorg/codehaus/groovy/reflection/ClassInfo;", false);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ASTORE, 1);
    mv.visitFieldInsn(PUTSTATIC, "script1486743662486", "$staticClassInfo", "Lorg/codehaus/groovy/reflection/ClassInfo;");
    mv.visitLabel(l1);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "org/codehaus/groovy/reflection/ClassInfo", "getMetaClass", "()Lgroovy/lang/MetaClass;", false);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(2, 2);
    mv.visitEnd();
    }
    {
    mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC + ACC_SYNTHETIC, "$createCallSiteArray_1", "([Ljava/lang/String;)V", null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitLdcInsn(new Integer(0));
    mv.visitLdcInsn("runScript");
    mv.visitInsn(AASTORE);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitLdcInsn(new Integer(1));
    mv.visitLdcInsn("println");
    mv.visitInsn(AASTORE);
    mv.visitInsn(RETURN);
    mv.visitMaxs(3, 1);
    mv.visitEnd();
    }
    {
    mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC + ACC_SYNTHETIC, "$createCallSiteArray", "()Lorg/codehaus/groovy/runtime/callsite/CallSiteArray;", null, null);
    mv.visitCode();
    mv.visitLdcInsn(new Integer(2));
    mv.visitTypeInsn(ANEWARRAY, "java/lang/String");
    mv.visitVarInsn(ASTORE, 0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESTATIC, "script1486743662486", "$createCallSiteArray_1", "([Ljava/lang/String;)V", false);
    mv.visitTypeInsn(NEW, "org/codehaus/groovy/runtime/callsite/CallSiteArray");
    mv.visitInsn(DUP);
    mv.visitLdcInsn(Type.getType("Lscript1486743662486;"));
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "org/codehaus/groovy/runtime/callsite/CallSiteArray", "<init>", "(Ljava/lang/Class;[Ljava/lang/String;)V", false);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(4, 1);
    mv.visitEnd();
    }
    {
    mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC + ACC_SYNTHETIC, "$getCallSiteArray", "()[Lorg/codehaus/groovy/runtime/callsite/CallSite;", null, null);
    mv.visitCode();
    mv.visitFieldInsn(GETSTATIC, "script1486743662486", "$callSiteArray", "Ljava/lang/ref/SoftReference;");
    Label l0 = new Label();
    mv.visitJumpInsn(IFNULL, l0);
    mv.visitFieldInsn(GETSTATIC, "script1486743662486", "$callSiteArray", "Ljava/lang/ref/SoftReference;");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/ref/SoftReference", "get", "()Ljava/lang/Object;", false);
    mv.visitTypeInsn(CHECKCAST, "org/codehaus/groovy/runtime/callsite/CallSiteArray");
    mv.visitInsn(DUP);
    mv.visitVarInsn(ASTORE, 0);
    Label l1 = new Label();
    mv.visitJumpInsn(IFNONNULL, l1);
    mv.visitLabel(l0);
    mv.visitMethodInsn(INVOKESTATIC, "script1486743662486", "$createCallSiteArray", "()Lorg/codehaus/groovy/runtime/callsite/CallSiteArray;", false);
    mv.visitVarInsn(ASTORE, 0);
    mv.visitTypeInsn(NEW, "java/lang/ref/SoftReference");
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/ref/SoftReference", "<init>", "(Ljava/lang/Object;)V", false);
    mv.visitFieldInsn(PUTSTATIC, "script1486743662486", "$callSiteArray", "Ljava/lang/ref/SoftReference;");
    mv.visitLabel(l1);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, "org/codehaus/groovy/runtime/callsite/CallSiteArray", "array", "[Lorg/codehaus/groovy/runtime/callsite/CallSite;");
    mv.visitInsn(ARETURN);
    mv.visitMaxs(3, 1);
    mv.visitEnd();
    }
    cw.visitEnd();
    
    return cw.toByteArray();
    }
    }
    
    ```

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/danielsun1106/groovy asmifier

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/496.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #496
    
----
commit 78748d727cece727f25ba9a403111a5db04300a0
Author: Daniel Sun <re...@hotmail.com>
Date:   2017-02-10T16:16:31Z

    Add a ASMifier tab to AstBrowser

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] groovy pull request #496: Add a ASMifier tab to AstBrowser

Posted by danielsun1106 <gi...@git.apache.org>.
Github user danielsun1106 closed the pull request at:

    https://github.com/apache/groovy/pull/496


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] groovy pull request #496: Add a ASMifier tab to AstBrowser

Posted by jwagenleitner <gi...@git.apache.org>.
Github user jwagenleitner commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/496#discussion_r100702338
  
    --- Diff: subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/AstBrowser.groovy ---
    @@ -403,9 +420,13 @@ class AstBrowser {
             def tabPane = mainSplitter.bottomComponent
             int tabCount = tabPane.getTabCount()
             for (int i = 0; i < tabCount; i++) {
    -            if (bytecodeView.is(tabPane.getComponentAt(i))) {
    +            def component = tabPane.getComponentAt(i);
    +            if (bytecodeView.is(component)) {
                     tabPane.setTitleAt(i, getByteCodeTitle())
                     break
    +            } else if (asmifierView.is(component)) {
    +                tabPane.setTitleAt(i, getASMifierTitle())
    +                break
    --- End diff --
    
    The `ASMifier` tab title doesn't update because of the `breaks`, if both `breaks` are removed that should fix it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---