Created
January 18, 2011 21:16
-
-
Save keithrbennett/785165 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Demonstrates javap -c revealing identifier names in a compiled JRuby script. | |
| # | |
| # Do: | |
| # jrubyc my_class.rb | |
| # javap -c my_class > my_class.decompiled.txt | |
| # less my_class.decompiled.txt | |
| class MyClass | |
| def initialize | |
| @a_number = java.lang.System.currentTimeMillis | |
| end | |
| def myFunc | |
| puts @a_number * 2 + 1 | |
| end | |
| end | |
| =begin | |
| Search for the Ruby identifiers MyClass, aNumber, myFunc in javap output below: | |
| --- | |
| Compiled from "my_class.rb" | |
| public class my_class extends org.jruby.ast.executable.AbstractScript{ | |
| public my_class(); | |
| Code: | |
| 0: aload_0 | |
| 1: invokespecial #18; //Method org/jruby/ast/executable/AbstractScript."<init>":()V | |
| 4: aload_0 | |
| 5: ldc #8; //String my_class.rb | |
| 7: putfield #22; //Field filename:Ljava/lang/String; | |
| 10: aload_0 | |
| 11: new #236; //class org/jruby/ast/executable/RuntimeCache | |
| 14: dup | |
| 15: invokespecial #237; //Method org/jruby/ast/executable/RuntimeCache."<init>":()V | |
| 18: putfield #241; //Field org/jruby/ast/executable/AbstractScript.runtimeCache:Lorg/jruby/ast/executable/RuntimeCache; | |
| 21: aload_0 | |
| 22: ldc #243; //String currentTimeMillis?N?System?N?lang?N?java?V?puts?F?+?N?*?N? | |
| 24: invokevirtual #246; //Method org/jruby/ast/executable/AbstractScript.initFromDescriptor:(Ljava/lang/String;)V | |
| 27: return | |
| public static org.jruby.runtime.builtin.IRubyObject __file__(my_class, org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.builtin.IRubyObject[], org.jruby.runtime.Block); | |
| Code: | |
| 0: aload_1 | |
| 1: invokevirtual #28; //Method org/jruby/runtime/ThreadContext.getRuntime:()Lorg/jruby/Ruby; | |
| 4: astore 6 | |
| 6: aload 6 | |
| 8: invokevirtual #34; //Method org/jruby/Ruby.getNil:()Lorg/jruby/runtime/builtin/IRubyObject; | |
| 11: astore 8 | |
| 13: aload_1 | |
| 14: iconst_0 | |
| 15: invokestatic #39; //Method setPosition:(Lorg/jruby/runtime/ThreadContext;I)V | |
| 18: aload_0 | |
| 19: aload_1 | |
| 20: aload_2 | |
| 21: getstatic #174; //Field org/jruby/runtime/Block.NULL_BLOCK:Lorg/jruby/runtime/Block; | |
| 24: invokestatic #170; //Method class_0$RUBY$MyClass:(Lmy_class;Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 27: areturn | |
| public org.jruby.runtime.builtin.IRubyObject __file__(org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.builtin.IRubyObject[], org.jruby.runtime.Block); | |
| Code: | |
| 0: aload_0 | |
| 1: aload_1 | |
| 2: aload_2 | |
| 3: aload_3 | |
| 4: aload 4 | |
| 6: invokestatic #37; //Method __file__:(Lmy_class;Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;[Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 9: areturn | |
| public static org.jruby.runtime.builtin.IRubyObject class_0$RUBY$MyClass(my_class, org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.Block); | |
| Code: | |
| 0: aload_1 | |
| 1: invokevirtual #28; //Method org/jruby/runtime/ThreadContext.getRuntime:()Lorg/jruby/Ruby; | |
| 4: dup | |
| 5: astore 5 | |
| 7: invokevirtual #34; //Method org/jruby/Ruby.getNil:()Lorg/jruby/runtime/builtin/IRubyObject; | |
| 10: astore 7 | |
| 12: aconst_null | |
| 13: aload_1 | |
| 14: aload 7 | |
| 16: invokestatic #47; //Method org/jruby/javasupport/util/RuntimeHelpers.prepareClassNamespace:(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;)Lorg/jruby/RubyModule; | |
| 19: swap | |
| 20: ldc #49; //String MyClass | |
| 22: swap | |
| 23: invokevirtual #55; //Method org/jruby/RubyModule.defineOrGetClassUnder:(Ljava/lang/String;Lorg/jruby/RubyClass;)Lorg/jruby/RubyClass; | |
| 26: dup | |
| 27: astore_2 | |
| 28: aload_1 | |
| 29: swap | |
| 30: aload_0 | |
| 31: aload_1 | |
| 32: ldc #57; //String | |
| 34: invokevirtual #61; //Method getScope0:(Lorg/jruby/runtime/ThreadContext;Ljava/lang/String;)Lorg/jruby/parser/StaticScope; | |
| 37: invokevirtual #65; //Method org/jruby/runtime/ThreadContext.preCompiledClassDummyScope:(Lorg/jruby/RubyModule;Lorg/jruby/parser/StaticScope;)V | |
| 40: aload_1 | |
| 41: iconst_2 | |
| 42: invokestatic #39; //Method setPosition:(Lorg/jruby/runtime/ThreadContext;I)V | |
| 45: aload_1 | |
| 46: aload_2 | |
| 47: aload_0 | |
| 48: ldc #108; //String initialize | |
| 50: ldc #109; //String method__1$RUBY$initialize | |
| 52: iconst_0 | |
| 53: anewarray #111; //class java/lang/String | |
| 56: iconst_0 | |
| 57: iconst_0 | |
| 58: iconst_0 | |
| 59: iconst_m1 | |
| 60: ldc #8; //String my_class.rb | |
| 62: ldc #112; //int 2 | |
| 64: getstatic #118; //Field org/jruby/internal/runtime/methods/CallConfiguration.FrameFullScopeNone:Lorg/jruby/internal/runtime/methods/CallConfiguration; | |
| 67: invokestatic #122; //Method org/jruby/javasupport/util/RuntimeHelpers.def:(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;IIIILjava/lang/String;ILorg/jruby/internal/runtime/methods/CallConfiguration;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 70: pop | |
| 71: aload_1 | |
| 72: bipush 6 | |
| 74: invokestatic #39; //Method setPosition:(Lorg/jruby/runtime/ThreadContext;I)V | |
| 77: aload_1 | |
| 78: aload_2 | |
| 79: aload_0 | |
| 80: ldc #150; //String myFunc | |
| 82: ldc #151; //String method__2$RUBY$myFunc | |
| 84: iconst_0 | |
| 85: anewarray #111; //class java/lang/String | |
| 88: iconst_0 | |
| 89: iconst_0 | |
| 90: iconst_0 | |
| 91: iconst_m1 | |
| 92: ldc #8; //String my_class.rb | |
| 94: ldc #152; //int 6 | |
| 96: getstatic #118; //Field org/jruby/internal/runtime/methods/CallConfiguration.FrameFullScopeNone:Lorg/jruby/internal/runtime/methods/CallConfiguration; | |
| 99: invokestatic #122; //Method org/jruby/javasupport/util/RuntimeHelpers.def:(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;IIIILjava/lang/String;ILorg/jruby/internal/runtime/methods/CallConfiguration;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 102: aload_1 | |
| 103: invokevirtual #155; //Method org/jruby/runtime/ThreadContext.postCompiledClass:()V | |
| 106: goto 114 | |
| 109: aload_1 | |
| 110: invokevirtual #155; //Method org/jruby/runtime/ThreadContext.postCompiledClass:()V | |
| 113: athrow | |
| 114: areturn | |
| Exception table: | |
| from to target type | |
| 40 102 109 any | |
| public static org.jruby.runtime.builtin.IRubyObject method__1$RUBY$initialize(my_class, org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.Block); | |
| Code: | |
| 0: aload_1 | |
| 1: invokevirtual #28; //Method org/jruby/runtime/ThreadContext.getRuntime:()Lorg/jruby/Ruby; | |
| 4: astore 5 | |
| 6: aload 5 | |
| 8: invokevirtual #34; //Method org/jruby/Ruby.getNil:()Lorg/jruby/runtime/builtin/IRubyObject; | |
| 11: astore 7 | |
| 13: aload_1 | |
| 14: iconst_3 | |
| 15: invokestatic #39; //Method setPosition:(Lorg/jruby/runtime/ThreadContext;I)V | |
| 18: aload_0 | |
| 19: aload 5 | |
| 21: ldc #68; //String @aNumber | |
| 23: aload_2 | |
| 24: aload_0 | |
| 25: invokevirtual #72; //Method getCallSite0:()Lorg/jruby/runtime/CallSite; | |
| 28: aload_1 | |
| 29: aload_2 | |
| 30: aload_0 | |
| 31: invokevirtual #75; //Method getCallSite1:()Lorg/jruby/runtime/CallSite; | |
| 34: aload_1 | |
| 35: aload_2 | |
| 36: aload_0 | |
| 37: invokevirtual #78; //Method getCallSite2:()Lorg/jruby/runtime/CallSite; | |
| 40: aload_1 | |
| 41: aload_2 | |
| 42: aload_0 | |
| 43: invokevirtual #81; //Method getCallSite3:()Lorg/jruby/runtime/CallSite; | |
| 46: aload_1 | |
| 47: aload_2 | |
| 48: aload_2 | |
| 49: invokevirtual #87; //Method org/jruby/runtime/CallSite.call:(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/builtin/IRubyObject;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 52: invokevirtual #87; //Method org/jruby/runtime/CallSite.call:(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/builtin/IRubyObject;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 55: invokevirtual #87; //Method org/jruby/runtime/CallSite.call:(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/builtin/IRubyObject;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 58: invokevirtual #87; //Method org/jruby/runtime/CallSite.call:(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/builtin/IRubyObject;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 61: invokevirtual #91; //Method setVariable0:(Lorg/jruby/Ruby;Ljava/lang/String;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/builtin/IRubyObject;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 64: areturn | |
| public static org.jruby.runtime.builtin.IRubyObject method__1$RUBY$initialize(my_class, org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.builtin.IRubyObject[], org.jruby.runtime.Block); | |
| Code: | |
| 0: aload_1 | |
| 1: aload_3 | |
| 2: iconst_0 | |
| 3: invokestatic #105; //Method org/jruby/javasupport/util/RuntimeHelpers.checkArgumentCount:(Lorg/jruby/runtime/ThreadContext;[Lorg/jruby/runtime/builtin/IRubyObject;I)V | |
| 6: aload_0 | |
| 7: aload_1 | |
| 8: aload_2 | |
| 9: aload 4 | |
| 11: invokestatic #107; //Method method__1$RUBY$initialize:(Lmy_class;Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 14: areturn | |
| public static org.jruby.runtime.builtin.IRubyObject method__2$RUBY$myFunc(my_class, org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.Block); | |
| Code: | |
| 0: aload_1 | |
| 1: invokevirtual #28; //Method org/jruby/runtime/ThreadContext.getRuntime:()Lorg/jruby/Ruby; | |
| 4: astore 5 | |
| 6: aload 5 | |
| 8: invokevirtual #34; //Method org/jruby/Ruby.getNil:()Lorg/jruby/runtime/builtin/IRubyObject; | |
| 11: astore 7 | |
| 13: aload_1 | |
| 14: bipush 7 | |
| 16: invokestatic #39; //Method setPosition:(Lorg/jruby/runtime/ThreadContext;I)V | |
| 19: aload_0 | |
| 20: invokevirtual #126; //Method getCallSite4:()Lorg/jruby/runtime/CallSite; | |
| 23: aload_1 | |
| 24: aload_2 | |
| 25: aload_2 | |
| 26: aload_0 | |
| 27: invokevirtual #129; //Method getCallSite5:()Lorg/jruby/runtime/CallSite; | |
| 30: aload_1 | |
| 31: aload_2 | |
| 32: aload_0 | |
| 33: invokevirtual #132; //Method getCallSite6:()Lorg/jruby/runtime/CallSite; | |
| 36: aload_1 | |
| 37: aload_2 | |
| 38: aload_0 | |
| 39: aload 5 | |
| 41: ldc #68; //String @aNumber | |
| 43: aload_2 | |
| 44: invokevirtual #136; //Method getVariable0:(Lorg/jruby/Ruby;Ljava/lang/String;Lorg/jruby/runtime/builtin/IRubyObject;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 47: ldc2_w #137; //long 2l | |
| 50: invokevirtual #141; //Method org/jruby/runtime/CallSite.call:(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/builtin/IRubyObject;J)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 53: ldc2_w #142; //long 1l | |
| 56: invokevirtual #141; //Method org/jruby/runtime/CallSite.call:(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/builtin/IRubyObject;J)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 59: invokevirtual #146; //Method org/jruby/runtime/CallSite.call:(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/builtin/IRubyObject;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 62: areturn | |
| public static org.jruby.runtime.builtin.IRubyObject method__2$RUBY$myFunc(my_class, org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.builtin.IRubyObject[], org.jruby.runtime.Block); | |
| Code: | |
| 0: aload_1 | |
| 1: aload_3 | |
| 2: iconst_0 | |
| 3: invokestatic #105; //Method org/jruby/javasupport/util/RuntimeHelpers.checkArgumentCount:(Lorg/jruby/runtime/ThreadContext;[Lorg/jruby/runtime/builtin/IRubyObject;I)V | |
| 6: aload_0 | |
| 7: aload_1 | |
| 8: aload_2 | |
| 9: aload 4 | |
| 11: invokestatic #149; //Method method__2$RUBY$myFunc:(Lmy_class;Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 14: areturn | |
| public static org.jruby.runtime.builtin.IRubyObject class_0$RUBY$MyClass(my_class, org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.builtin.IRubyObject[], org.jruby.runtime.Block); | |
| Code: | |
| 0: aload_1 | |
| 1: invokevirtual #28; //Method org/jruby/runtime/ThreadContext.getRuntime:()Lorg/jruby/Ruby; | |
| 4: aload_3 | |
| 5: iconst_0 | |
| 6: iconst_0 | |
| 7: invokestatic #168; //Method org/jruby/runtime/Arity.checkArgumentCount:(Lorg/jruby/Ruby;[Lorg/jruby/runtime/builtin/IRubyObject;II)I | |
| 10: pop | |
| 11: aload_0 | |
| 12: aload_1 | |
| 13: aload_2 | |
| 14: aload 4 | |
| 16: invokestatic #170; //Method class_0$RUBY$MyClass:(Lmy_class;Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 19: areturn | |
| public org.jruby.runtime.builtin.IRubyObject load(org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.builtin.IRubyObject[], org.jruby.runtime.Block); | |
| Code: | |
| 0: aload_1 | |
| 1: iconst_0 | |
| 2: anewarray #111; //class java/lang/String | |
| 5: invokestatic #180; //Method org/jruby/javasupport/util/RuntimeHelpers.preLoad:(Lorg/jruby/runtime/ThreadContext;[Ljava/lang/String;)V | |
| 8: aload_0 | |
| 9: aload_1 | |
| 10: aload_2 | |
| 11: aload_3 | |
| 12: aload 4 | |
| 14: invokestatic #37; //Method __file__:(Lmy_class;Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;[Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 17: aload_1 | |
| 18: invokestatic #184; //Method org/jruby/javasupport/util/RuntimeHelpers.postLoad:(Lorg/jruby/runtime/ThreadContext;)V | |
| 21: areturn | |
| 22: aload_1 | |
| 23: invokestatic #184; //Method org/jruby/javasupport/util/RuntimeHelpers.postLoad:(Lorg/jruby/runtime/ThreadContext;)V | |
| 26: athrow | |
| Exception table: | |
| from to target type | |
| 0 22 22 any | |
| public static void main(java.lang.String[]); | |
| Code: | |
| 0: new #2; //class my_class | |
| 3: dup | |
| 4: invokespecial #187; //Method "<init>":()V | |
| 7: dup | |
| 8: ldc #2; //class my_class | |
| 10: invokevirtual #193; //Method java/lang/Class.getClassLoader:()Ljava/lang/ClassLoader; | |
| 13: ldc #195; //String my_class.class | |
| 15: invokevirtual #201; //Method java/lang/ClassLoader.getResource:(Ljava/lang/String;)Ljava/net/URL; | |
| 18: invokevirtual #207; //Method java/lang/Object.toString:()Ljava/lang/String; | |
| 21: invokevirtual #211; //Method org/jruby/ast/executable/AbstractScript.setFilename:(Ljava/lang/String;)V | |
| 24: new #213; //class org/jruby/RubyInstanceConfig | |
| 27: dup | |
| 28: invokespecial #214; //Method org/jruby/RubyInstanceConfig."<init>":()V | |
| 31: dup | |
| 32: aload_0 | |
| 33: invokevirtual #217; //Method org/jruby/RubyInstanceConfig.setArgv:([Ljava/lang/String;)V | |
| 36: invokestatic #221; //Method org/jruby/Ruby.newInstance:(Lorg/jruby/RubyInstanceConfig;)Lorg/jruby/Ruby; | |
| 39: dup | |
| 40: invokevirtual #225; //Method org/jruby/Ruby.getCurrentContext:()Lorg/jruby/runtime/ThreadContext; | |
| 43: swap | |
| 44: invokevirtual #228; //Method org/jruby/Ruby.getTopSelf:()Lorg/jruby/runtime/builtin/IRubyObject; | |
| 47: getstatic #232; //Field org/jruby/runtime/builtin/IRubyObject.NULL_ARRAY:[Lorg/jruby/runtime/builtin/IRubyObject; | |
| 50: getstatic #174; //Field org/jruby/runtime/Block.NULL_BLOCK:Lorg/jruby/runtime/Block; | |
| 53: invokevirtual #234; //Method load:(Lorg/jruby/runtime/ThreadContext;Lorg/jruby/runtime/builtin/IRubyObject;[Lorg/jruby/runtime/builtin/IRubyObject;Lorg/jruby/runtime/Block;)Lorg/jruby/runtime/builtin/IRubyObject; | |
| 56: return | |
| } | |
| =end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment