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 of, model and/or computation:

    The best way to teach a child restraint and generosity is to be a model of those qualities yourself. If your child sees that you want a particular item but refrain from buying it, either because it isn’t practical or because you can’t afford it, he will begin to understand restraint. Likewise, if you donate books or clothing to charity, take him with you to distribute the items to teach him about generosity.
    Lawrence Balter (20th century)

    The striking point about our model family is not simply the compete-compete, consume-consume style of life it urges us to follow.... The striking point, in the face of all the propaganda, is how few Americans actually live this way.
    Louise Kapp Howe (b. 1934)

    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)