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:

    ...that absolutely everything beloved and cherished of the bourgeoisie, the conservative, the cowardly, and the impotent—the State, family life, secular art and science—was consciously or unconsciously hostile to the religious idea, to the Church, whose innate tendency and permanent aim was the dissolution of all existing worldly orders, and the reconstitution of society after the model of the ideal, the communistic City of God.
    Thomas Mann (1875–1955)

    The playing adult steps sideward into another reality; the playing child advances forward to new stages of mastery....Child’s play is the infantile form of the human ability to deal with experience by creating model situations and to master reality by experiment and planning.
    Erik H. Erikson (20th century)

    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)