Java Bytecode - Model of Computation

Model of Computation

The model of computation of Java bytecode is that of a stack-oriented programming language. For example, assembly code for an x86 processor might look like this:

mov eax, byte mov edx, byte add eax, edx mov ecx, eax

This code would add two values and move the result to a different location. Similar disassembled bytecode might look like this:

0 iload_1 1 iload_2 2 iadd 3 istore_3

Here, the two values to be added are pushed onto the stack, where they are retrieved by the addition instruction, summed, and the result placed back on the stack. The storage instruction then moves the top value of the stack into a variable location. The numbers in front of the instructions simply represent the offset of each instruction from the beginning of the method. This stack-oriented model extends to the object oriented aspects of the language as well. A method call called "getName", for example, may look like the following:

Method java.lang.String getName 0 aload_0 // The "this" object is stored in location 0 of the variable table 1 getfield #5 // This instruction pops an object from the top of the stack, retrieves the specified // field from it, and pushes the field onto the stack. // In this example, the "name" field corresponds to the fifth constant in the // constant pool of the class. 4 areturn // Returns the object on top of the stack from the method.

Read more about this topic:  Java Bytecode

Famous quotes containing the words model and/or computation:

    The Battle of Waterloo is a work of art with tension and drama with its unceasing change from hope to fear and back again, change which suddenly dissolves into a moment of extreme catastrophe, a model tragedy because the fate of Europe was determined within this individual fate.
    Stefan Zweig (18811942)

    I suppose that Paderewski can play superbly, if not quite at his best, while his thoughts wander to the other end of the world, or possibly busy themselves with a computation of the receipts as he gazes out across the auditorium. I know a great actor, a master technician, can let his thoughts play truant from the scene ...
    Minnie Maddern Fiske (1865–1932)