Java bytecode
From Wikipedia, the free encyclopedia
Java bytecode is the form of instructions that the Java virtual machine executes. Each bytecode instruction or opcode is one byte in length; however, not all of the possible 256 instructions are used. In fact, Sun Microsystems, the original creators of the Java programming language, the Java virtual machine and other components of the Java Runtime Environment (JRE), have set aside 3 values to be permanently unimplemented.[1]
Contents |
[edit] Relation to Java
A Java programmer does not need to be aware of or understand Java bytecode at all. However, as suggested in the IBM developerWorks journal, "Understanding bytecode and what bytecode is likely to be generated by a Java compiler helps the Java programmer in the same way that knowledge of assembler helps the C or C++ programmer."[2].
[edit] Generation
The most common language targeting Java Virtual Machine by producing Java bytecode is Java. Originally only one compiler existed, the javac compiler from Sun Microsystems, which compiles Java source code to Java bytecode; but because all the specifications for Java bytecode are now available, other parties have supplied compilers that produce Java bytecode. Examples of other compilers include:
- Jikes, compiles from Java to Java bytecode (developed by IBM, implemented in C++)
- Espresso, compiles from Java to Java bytecode (Java 1.0 only)
- GCJ, the Gnu Compiler for Java, compiles from Java to Java bytecode; it is also able to compile to native machine code and is available as part of the GNU Compiler Collection (GCC).
Some projects provide Java assemblers to enable writing Java bytecode by hand. Assembler code may be also generated by machine, for example by compiler targeting Java virtual machine. Notable Java assemblers include:
- Jasmin, takes textual descriptions for Java classes, written in a simple assembler-like syntax using Java Virtual Machine instruction set and generates a Java class file [3]
- Jamaica, a macro assembly language for the Java virtual machine. Java syntax is used for class or interface definition. Method bodies are specified using bytecode instructions. [4]
Others developed compilers for different programming languages targeting Java virtual machine, such as:
- JRuby and Jython, two scripting languages based on Ruby and Python
- Groovy, a scripting language based on Java
- Scala, a type-safe general-purpose programming language supporting object-oriented and functional programming
- JGNAT and AppletMagic, compile from the Ada programming language to Java bytecode
- C to Java byte-code compilers
- Clojure
[edit] Execution
Java bytecode is designed to be executed in a Java virtual machine. There are several virtual machines available today both free or commercial.
If executing Java bytecode in a Java virtual machine is not desirable, a developer can also compile Java source code or Java bytecode directly to native machine code with tools such as the GNU Compiler for Java. Some ARM processors have the ability to execute bytecode directly.
[edit] Support for dynamic languages
The Java Virtual Machine has currently no built-in support for dynamically typed languages, because the existing JVM instruction set is statically typed - in the sense that method calls have their signatures type-checked at compile time, without a mechanism to defer this decision to run time, or to choose the method dispatch by an alternative approach.[5]
JSR 292 (Supporting Dynamically Typed Languages on the JavaTM Platform) [6] propose to add a new invokedynamic
instruction at the JVM level, to allow method invocation relying on dynamic type checking (instead of the existing statically type-checked invokevirtual
instruction). The Da Vinci Machine is a prototype virtual machine implementation that hosts JVM extensions aimed at supporting dynamic languages.
[edit] See also
- Class (file format)
- List of JVM languages
- Java backporting tools
- C to Java Virtual Machine compilers
- ARM9E
- Common Intermediate Language
[edit] References
- ^ VM Spec - Reserved Opcodes
- ^ Understanding bytecode makes you a better programmer
- ^ Jasmin Home Page
- ^ Jamaica: The Java Virtual Machine (JVM) Macro Assembler
- ^ Nutter, Charles (2007-01-03). "InvokeDynamic: Actually Useful?". http://headius.blogspot.com/2007/01/invokedynamic-actually-useful.html. Retrieved on 2008-01-25.
- ^ see JSR 292
[edit] External links
The Wikibook Java Programming has a page on the topic of |
- Sun's Java Virtual Machine Specification
- Programming Languages for the Java Virtual Machine
- Bytecode Visualizer LT - shows bytecode instructions along with control flow graph (free Eclipse plugin)
|