Java Bytecode Assembly, Interesting concepts in the art of Computer Science/Software Development, maybe from time to time other pesky corp. related development issues.

Saturday, January 31, 2009

Blog Template Hacking

I will probably be hacking the blog template from time to time, you can find the source of it hosted at this google code repository.

For those few that are not familiar with concept of Revision Control I will describe briefly why I choose to use it here, which should also explain the general idea behind the concept.

I will be hacking the template of the blog, this means I will be modifying the "code" of my blog, the reason I want to do this is simple: It affects the way you see it. This "code" is parsed by blogger backend server and rendered into HTML which is later parsed by your browser and displayed to your eyes (which by the way goes another parsing and interpretation by your brain before you can actually "see"/ "read" my blog). Parsing is the process of "understanding" a known format.

Now, due to the known fact that there is no software without bugs. Hacking surly means introducing bugs, considering the fact that I've never edited blogger templates before- The bug factor is even higher. Further more, bugs are here forever or as the saying goes "To err is human, to fix it divine" (A remix of Alexander Pope famous quote "To err is human, to forgive divine" by your humble).

To tackle this bug fixing process in a more profound process, one of the best techniques is going back step by step attempting to isolate what exactly caused the wrong behavior (the bug). This is where revision control system comes in- It allows you to retrieve older versions of the file, further more it allows you to display a difference between 2 versions of the same file in an easily accessible interface. This fits into the previously introduced metaphor of bug tackling: start from something that worked, search revision by revision until you find what broke it, understand why it's broken, fix the problem, ensure the fix works. Some folks forgot the import step of Learn from the error and think how to avoid it next time.

You can open your own Google code repository at the following link Google Code, as for document revisioning, you can do the same thing using Google Docs which allows out of the box "History" of your document modifications.


Thursday, January 29, 2009

TheServerSide bytecode article summary

Lets summarize what can be learned from the really brilliant TheServerSide article "The working developer's Guide to Java Bytecode"

  • The JVM is open to host different languages among them JRuby, Groovy and Jython all these translate to JVM bytecode for runtime. Java is translated in exactly the same process to bytecode using javac.

  • Bytecode is the assembly language of the JVM, you might as well think of the JVM as a globally available instruction set.

  • The translation of bytecode to human readable form is encouraged by Sun. Fact is Sun provides a tool called javap that allows you to do just that in an easily accessible way.

  • Bytecode works by calling instructions with their relevant data, for example a reference to a memory location that contains a string. What's interesting about this idea is that methods are also called by string reference- so for example if your default code is designed to call a method by the instruction invokevirtual #4 you could very replace that with invokevirtual #7 at runtime, this opens a huge range of possibilities for the application.

  • Inside the JVM the stack is divided into slots, each slot size is 4bytes (32bits).

  • The size of a bytecode instruction is 1 byte. Which makes this the simplest assembly language in the world. In fact the grand total of bytecode instructions existing is 224!

  • The method by which the JVM passes data between instructions is by putting and popping data into the stack. The calling context, before instructing the JVM to execute a bytecode instruction loads data into the stack, the instruction in turn once called pops data out of the stack. The amount of loaded data by the caller must match the amount that would be popped otherwise we have a Buffer Overflow, something that does not exist in the JVM (As far as I know).

I've just covered the first section of the article, you are encouraged to read the whole thing. Please by all means don't retain yourself from commenting with ideas and requests regarding additional covering you would like to read. Also, I should mention that people wishing to participate in the writing of this blog are welcome to do.

Please contact me at maxim.veksler@gmail.com for further discussion.


Sunday, January 25, 2009

Bytecode Learning Path

Continuing with the learning path, A good knowledge basis must be built.

Lets start with a few relevant reading material :
Continuing with some books that cover this topic from different angles. I hope that in due time I would be able to lay a better review about them... after I read them.

And here are some projects that deal with Java bytecode manipulation

These should give you a good starting point in exploring the Byte coded wonders of the JVM. Welcome to the world of "Real Programmers".

Last but not least, a link to some more tools and related artifacts for folks looking to toy with Bytecode http://www.artima.com/insidejvm/resources/index.html


Java Byte Code Assembly

I have decided to learn how to write Java bytecode, this issue fascinates me.

I think it's amazing to be able to understand what goes under the hood of the code, this will allow me to see a much bigger picture of the Java world. Also, with knowledge comes power - Being able to read assembly means being able to write it... and that is all I agree to say about this. For more information ask phrack.org.

This blog will document and hopefully share with you my dear reader interesting ideas, projects and hacks I learn along the way.


Enjoy, have fun and be nice!

Maxim Veksler.

About Me

My photo
Tel Aviv, Israel
I work in one of Israel's Hi-Tech company's. I do 5 nines system development with some system administration. This blog will focus on the technical side of things, with some philosophical strings attached.