Bytecode
lastmod 2019-01-10created 2017-11-202 edits
Bytecode is a binary representation for executable programs that run on a virtual machine rather than on specific hardware. Because it is processed by software rather than hardware, it is usually more abstract than machine code. Historically, bytecode got its name because most instruction sets were one-byte operation codes (opcodes) with zero or more parameters. Bytecode is used as a form of output code by programming languages that want to reduce dependency on specific hardware and produce output that is easy to interpret. Compiled bytecode is either used as input to a compiler that generates machine code for specific hardware, or executed directly on a virtual machine.
Compared to source code written to be easy for humans to read, bytecode is less abstract, more compact, and more computer-oriented. For example, bytecode encodes the results of the semantic analysis phase, such as the scope of a variable (whether it is a local or global variable). As a result, it generally performs better than analyzing/executing source code directly.
A bytecode program is usually executed by reading one instruction at a time. This type of bytecode interpreter is highly portable. Another form, a system called a dynamic translator or just-in-time (JIT) compiler, translates bytecode into machine code as needed during execution. This approach removes the portability of the virtual machine, but does not lose the portability of the bytecode itself. For example, Java and C# code is usually compiled and stored in bytecode form and translated into machine code by a JIT compiler before execution. This translation introduces a delay before the program runs, but it usually performs much better than an interpreter.
Examples
- Java bytecode, which is executed by the Java Virtual Machine.
- Managed code such as Microsoft .NET Common Intermediate Language, executed by the .NET Common Language Runtime (CLR).
- Adobe Flash objects.