For example, the isub byte code instruction expects two integers to be stored on the top of the stack, which means that the operands must have been pushed there by the previous set of instructions. The operand stack follows the last-in first-out (LIFO) methodology, and expects the operands on the stack to be in a specific order. Like registers in the Virtual Machine, the operand stack is 32 bits wide. All byte code instructions take operands from the stack, operate on them, and return results to the stack. The Java Virtual Machine uses an operand stack to supply parameters to methods and operations, and to receive results back from them. This is possible because the compiler knows the size of the local variables and the operand stack, and because the interpreter knows the size of the execution environment. vars, the variable register, and contains a pointer to local variables.Īll these registers are 32 bits wide, and are allocated immediately.pc, the program counter, and contains the address of the next byte code to be executed.optop, the operand top, and contains a pointer to the top of the operand stack, and is used to evaluate arithmetic expressions.frame, the reference frame, and contains a pointer to the execution environment of the current method.The following four registers hold the state of the virtual machine: In Java, registers hold the machine's state, and are updated after each line of byte code is executed, to maintain that state. However, because the Virtual Machine is stack based, its registers are not used for passing or receiving arguments. The registers of the Java Virtual Machine are similar to the registers in our computer. These functions can be broken down into seven basic parts: (See figure below.)įigure 2 - JVM handles translations The Basic Parts of the Java Virtual MachineĬreating a Virtual Machine within our computer's memory requires building every major function of a real computer down to the very environment within which programs operate. It does this by acting as the intermediary between the Virtual Machine and our real machine. The Java interpreter must also make our computer and the byte code file believe they are running on a real machine. Fooling the Java compiler into creating byte code for a nonexistent machine is only one-half of the ingenious process that makes the Java architecture neutral. This machine is called the Java Virtual Machine, and it exists only in the memory of our computer. The difficult part of creating Java byte code is that the source code is compiled for a machine that does not exist. The runtime environment consists of a virtual machine and its supporting code. We can run the compiled byte code on any computer with the Java runtime environment installed on it. Using an interpreter, all Java programs are compiled to an intermediate level called byte code. In Java, this process of writing to executing a program is very similar, but with one important difference that allows us to write Java programs that are machine independent. The executable code depends upon the computer machine that we use to execute our program it is machine dependent. In high-level programming languages such as C and C++, we write a program in a human-readable format, and a program called a compiler translates it to a binary format called executable code that the computer can understand and execute.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |