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:

    AIDS occupies such a large part in our awareness because of what it has been taken to represent. It seems the very model of all the catastrophes privileged populations feel await them.
    Susan Sontag (b. 1933)

    It has to be acknowledged that in capitalist society, with its herds of hippies, originality has become a sort of fringe benefit, a mere convention, accepted obsolescence, the Beatnik model being turned in for the Hippie model, as though strangely obedient to capitalist laws of marketing.
    Mary McCarthy (1912–1989)

    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)