From: Leo U. <leo...@ya...> - 2007-01-11 22:06:12
|
What's a little nifty beyond the byte code savings is that it appears that javac won't output the smaller byte codes as well. From compiling this: public void run(int i){ switch(i){ case 1: one(); return; case 2: one(); return; } } we get this bytecode: public void run(int); Code: 0: iload_1 1: lookupswitch{ //2 1: 28; 2: 33; default: 38 } 28: aload_0 29: invokevirtual #2; //Method one:()V 32: return 33: aload_0 34: invokevirtual #2; //Method one:()V 37: return 38: return I wonder if there are going to be any more opportunities like this to cut down on the code generated. The easiest suspects to investigate are going to be loops that output bytes. It wasn't that hard to see that the aloads could be moved out. leouser --- Leo User <leo...@ya...> wrote: > Hmmm, this does appear to work. You have to > manipulate the stack variable in the code generation > or it bombs but I was able to output and execute a > smaller call_function method. Now if we'd only be > able to get rid of the areturn instuction, we'd be > really swinging. > > leouser > > > --- Leo User <leo...@ya...> wrote: > > > Hmmm, > > > > I was looking at the byte code generated from a > leo > > file, specifically the call_function override it > > does > > on PyFunctionTable. This pattern emerged: > > 2866: aload_0 > > 2867: aload_2 > > 2868: invokevirtual > > 2869: areturn > > > > This appears to occur for each possible function > > invocation. Now in leoNodes(the file in question) > > it > > generates 386 invokevirtual calls. Each one > appears > > to be surrounded by the aload_* and areturn set. > I > > think it would be possible to simplify this > greatly > > by > > moving the aload_0 and aload_2 calls before the > > switch. "areturn" is trickier in that you don't > > want > > to fall into invoking the other methods after the > > method is called. But if we do move the aloads > > before > > the switch that saves us from generating 770 > > instructions(in this case). I think this could > > work, > > the loop in question appears to be this(from > > Module.java): > > for(i=0; i<labels.length; i++) { > > > > labels[i].setPosition(); > > > > code.aload(0); > > > > code.aload(2); > > > > code.invokevirtual( > > > > classfile.name, > > > > > > ((PyCodeConstant)codes.elementAt(i)).fname, > > > > "(" + $pyFrame + ")" + $pyObj); > > > > code.areturn(); > > > > } > > > > def.setPosition(); > > > > > > > > all that should need to be done is to move the > > aloads > > out of the loop and before the iconst call. > > > > aload(0) is loading "this" > > aload(2) is loading the PyFrame > > > > leouser > > > > > > > > > ____________________________________________________________________________________ > > Any questions? Get answers on any topic at > > www.Answers.yahoo.com. Try it now. > > > > > ------------------------------------------------------------------------- > > Take Surveys. Earn Cash. Influence the Future of > IT > > Join SourceForge.net's Techsay panel and you'll > get > > the chance to share your > > opinions on IT & business topics through brief > > surveys - and earn cash > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > _______________________________________________ > > Jython-dev mailing list > > Jyt...@li... > > > https://lists.sourceforge.net/lists/listinfo/jython-dev > > > > > > > ____________________________________________________________________________________ > Never Miss an Email > Stay connected with Yahoo! Mail on your mobile. Get > started! > http://mobile.yahoo.com/services?promote=mail > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get > the chance to share your > opinions on IT & business topics through brief > surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Jython-dev mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-dev > ____________________________________________________________________________________ Any questions? Get answers on any topic at www.Answers.yahoo.com. Try it now. |