Examine individual changes
This page allows you to examine the variables generated by the Edit Filter for an individual change.
Variables generated for this change
Variable | Value |
---|---|
Name of the user account (user_name ) | '58.187.103.237' |
Page ID (page_id ) | 1934680 |
Page namespace (page_namespace ) | 0 |
Page title without namespace (page_title ) | 'Java bytecode' |
Full page title (page_prefixedtitle ) | 'Java bytecode' |
Action (action ) | 'edit' |
Edit summary/reason (summary ) | '' |
Whether or not the edit is marked as minor (no longer in use) (minor_edit ) | false |
Old page wikitext, before the edit (old_wikitext ) | ''''Java bytecode''' is the form of instructions that the [[Java virtual machine]] executes. Each [[bytecode]] [[opcode]] is one byte in length, although some require parameters, resulting in some multi-byte instructions. Not all of the possible 256 opcodes are used. In fact, [[Sun Microsystems]], the original creators of the [[Java (programming language)|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.<ref name="reserved_opcodes">[http://java.sun.com/docs/books/jvms/second_edition/html/Instructions.doc.html#60105 VM Spec - Reserved Opcodes]</ref>
== Relation to Java ==
A [[Java (programming language)|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 [[assembly Language|assembler]] helps the [[C (programming language)|C]] or [[C++]] programmer."<ref>[http://www-128.ibm.com/developerworks/ibm/library/it-haggar_bytecode/ Understanding bytecode makes you a better programmer]</ref>.
== Instructions ==
As each byte has 256 potential values, there are 256 possible opcodes. Of these, 0x00 through 0xca, 0xfe, and 0xff are assigned values. 0xba is unused for historical reasons. 0xca is reserved as a breakpoint instruction for debuggers and is not used by the language. Similarly, 0xfe and 0xff are not used by the language, and are reserved for internal use by the virtual machine.
Instructions fall into a number of broad groups:
* Load and store (e.g. aload_0, istore)
* Arithmetic and logic (e.g. ladd, fcmpl)
* Type conversion (e.g. i2b, d2i)
* Object creation and manipulation (new, putfield)
* Operand stack management (e.g. swap, dup2)
* Control transfer (e.g. ifeq, goto)
* Method invocation and return (e.g. invokespecial, areturn)
There are also a few instructions for a number of more specialized tasks such as exception throwing, synchronization, etc.
Many instructions have prefixes and/or suffixes referring to the types of operands they operate on. These are "i", "l", "s", "b", "c", "f", "d", and "a", standing for, respectively, "integer", "long", "short", "byte", "character", "float", "double", and "reference". For example, "iadd" will add two integers, while "dadd" will add two doubles. The "const", "load", and "store" instructions may also take a suffix of the form "_''n''", where ''n'' is a number from 0-3 for "load" and "store". The maximum ''n'' for "const" differs by type.
The "const" instructions push a value of the specified type onto the stack. For example "iconst_5" will push an integer 5, while "dconst_1" will push a double 1. There is also an "aconst_null", which pushes "null". The ''n'' for the "load" and "store" instructions specifies the ___location in the variable table to load from or store to. The "aload_0" instruction pushes the object in variable 0 onto the stack (this is usually the "this" object). "istore_1" stores the integer on the top of the stack into variable 1. For variables with higher numbers the suffix is dropped and operators must be used.
== Computational model ==
The computational model of Java bytecode is that of a [[stack-oriented programming language]]. For example, [[Assembly language|assembly code]] for an [[x86|x86 processor]] might look like this:
<code>
add eax, edx
mov ecx, eax</code>
This code would add two values and move the result to a different ___location. Similar disassembled bytecode might look like this:
<code>
0 iload_1
1 iload_2
2 iadd
3 istore_3</code>
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:
<code>
Method java.lang.String getName()
0 aload_0 // The "this" object is stored in ___location 0 of the variable table
1 getfield #5 <Field java.lang.String name>
// This instructon 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 is the fifth field of the class.
4 areturn // Returns the object on top of the stack from the method.</code>
== Example ==
Consider the following Java code:
<source lang="java">
outer:
for (int i = 2; i < 1000; i++) {
for (int j = 2; j < i; j++) {
if (i % j == 0)
continue outer;
}
System.out.println (i);
}
</source>
A Java compiler might translate the Java code above into byte code as follows, assuming the above was put in a method:
<code>
0: iconst_2
1: istore_1
2: iload_1
3: sipush 1000
6: if_icmpge 44
9: iconst_2
10: istore_2
11: iload_2
12: iload_1
13: if_icmpge 31
16: iload_1
17: iload_2
18: irem
19: ifne 25
22: goto 38
25: iinc 2, 1
28: goto 11
31: getstatic #84; //Field java/lang/System.out:Ljava/io/PrintStream;
34: iload_1
35: invokevirtual #85; //Method java/io/PrintStream.println:(I)V
38: iinc 1, 1
41: goto 2
44: return</code>
== Generation ==
{{main|List of JVM languages}}
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|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 (Java assembler)|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 <ref>[http://jasmin.sourceforge.net Jasmin Home Page<!-- Bot generated title -->]</ref>
* [[Jamaica (Java assembler)|Jamaica]], a [[Macro (computer science)|macro]] [[assembly language]] for the [[Java virtual machine]]. Java syntax is used for class or interface definition. Method bodies are specified using bytecode instructions. <ref>[http://www.judoscript.org/jamaica.html Jamaica: The Java Virtual Machine (JVM) Macro Assembler<!-- Bot generated title -->]</ref>
Others have developed compilers, for different programming languages, in order to target the Java virtual machine, such as:
* [[JRuby]] and [[Jython]], two [[scripting language]]s based on [[Ruby (programming language)|Ruby]] and [[Python (programming language)|Python]]
* [[Groovy (programming language)|Groovy]], a [[scripting language]] based on Java
* [[Scala (programming language)|Scala]], a type-safe general-purpose programming language supporting object-oriented and functional programming
* [[JGNAT]] and [[AdaMagic|AppletMagic]], compile from the [[Ada programming language]] to Java bytecode
* [[C to Java byte-code compiler#C to bytecode compilers|C to Java byte-code compiler]]s
* [[Clojure]]
== Execution ==
Java bytecode is designed to be executed in a [[Java virtual machine]]. There are several virtual machines available today, both free and commercial products.
{{See|Java virtual machine}}
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 [[GCJ|GNU Compiler for Java]]. Some ARM processors have the ability to execute bytecode directly (see [[Jazelle]]).
==Support for dynamic languages==
{{main|list of JVM languages}}
The [[Java Virtual Machine]] has currently no built-in support for [[Type system#Dynamic_typing|dynamically typed languages]], because the existing JVM instruction set is [[Type system#Static typing|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.<ref>{{cite web
| url=http://headius.blogspot.com/2007/01/invokedynamic-actually-useful.html
| title=InvokeDynamic: Actually Useful?
| date=2007-01-03
|last=Nutter|first=Charles
| accessdate=2008-01-25}}</ref>
[[Java Community Process|JSR 292]] (''Supporting Dynamically Typed Languages on the JavaTM Platform'') <ref>[http://www.jcp.org/en/jsr/detail?id=292 see JSR 292]</ref> propose to add a new <code>invokedynamic</code> instruction at the JVM level, to allow method invocation relying on dynamic [[Type system#Type checking|type checking]] (instead of the existing statically type-checked <code>invokevirtual</code> instruction). The [[Da Vinci Machine]] is a prototype virtual machine implementation that hosts JVM extensions aimed at supporting dynamic languages.
== See also ==
* [[Java bytecode instruction listings]]
* [[Class (file format)]]
* [[List of JVM languages]]
* [[Java backporting tools]]
* [[C to Java Virtual Machine compilers]]
* [[ARM9E]]
* [[JStik]]
* [[Common Intermediate Language]]
== References ==
{{reflist|2}}
== External links ==
{{wikibooks|Java Programming|Byte Code|Java bytecode}}
* [http://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.html Sun's Java Virtual Machine Specification]
* [http://www.is-research.de/info/vmlanguages/ Programming Languages for the Java Virtual Machine]
* [http://www.drgarbage.com/bytecode-visualizer-lt.html Bytecode Visualizer LT - bytecode viewer and debugger (free Eclipse plugin)]
* [http://www.adaptj.com/main/stacktrace AdaptJ StackTrace - bytecode level debugging with a full control of the stack, the local variables, and the execution flow]
* [http://lulachronicles.blogspot.com Java Class Unpacker - plugin for Total Commander, it lets open class files as compressed archives and see fields and methods as files. The bytecode can be viewed as text using F3]
{{Java (Sun)}}
[[Category:Java platform|Bytecodes]]
[[Category:Assembly languages]]
[[bs:Java bytecode]]
[[ca:Bytecode (Java)]]
[[es:Java bytecode]]
[[fr:Bytecode Java]]
[[pt:Bytecode Java]]' |
New page wikitext, after the edit (new_wikitext ) | ''''Java bytecode''' is the form of instructions that the [[Java virtual machine]] executes. Each [[bytecode]] [[opcode]] is one byte in length, although some require parameters, resulting in some multi-byte instructions. Not all of the possible 256 opcodes are used. In fact, [[Sun Microsystems]], the original creators of the [[Java (programming language)|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.<ref name="reserved_opcodes">[http://java.sun.com/docs/books/jvms/second_edition/html/Instructions.doc.html#60105 VM Spec - Reserved Opcodes]</ref>
== Relation to Java ==
A [[Java (programming language)|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 [[assembly Language|assembler]] helps the [[C (programming language)|C]] or [[C++]] programmer."<ref>[http://www-128.ibm.com/developerworks/ibm/library/it-haggar_bytecode/ Understanding bytecode makes you a better programmer]</ref>.
== Instructions ==
As each byte has 256 potential values, there are 256 possible opcodes. Of these, 0x00 through 0xca, 0xfe, and 0xff are assigned values. 0xba is unused for historical reasons. 0xca is reserved as a breakpoint instruction for debuggers and is not used by the language. Similarly, 0xfe and 0xff are not used by the language, and are reserved for internal use by the virtual machine.
Instructions fall into a number of broad groups:
* Load and store (e.g. aload_0, istore)
* Arithmetic and logic (e.g. ladd, fcmpl)
* Type conversion (e.g. i2b, d2i)
* Object creation and manipulation (new, putfield)
* Operand stack management (e.g. swap, dup2)
* Control transfer (e.g. ifeq, goto)
* Method invocation and return (e.g. invokespecial, areturn)
There are also a few instructions for a number of more specialized tasks such as exception throwing, synchronization, etc.
Many instructions have prefixes and/or suffixes referring to the types of operands they operate on. These are "i", "l", "s", "b", "c", "f", "d", and "a", standing for, respectively, "integer", "long", "short", "byte", "character", "float", "double", and "reference". For example, "iadd" will add two integers, while "dadd" will add two doubles. The "const", "load", and "store" instructions may also take a suffix of the form "_''n''", where ''n'' is a number from 0-3 for "load" and "store". The maximum ''n'' for "const" differs by type.
The "const" instructions push a value of the specified type onto the stack. For example "iconst_5" will push an integer 5, while "dconst_1" will push a double 1. There is also an "aconst_null", which pushes "null". The ''n'' for the "load" and "store" instructions specifies the ___location in the variable table to load from or store to. The "aload_0" instruction pushes the object in variable 0 onto the stack (this is usually the "this" object). "istore_1" stores the integer on the top of the stack into variable 1. For variables with higher numbers the suffix is dropped and operators must be used.
== Computational model ==
The computational model of Java bytecode is that of a [[stack-oriented programming language]]. For example, [[Assembly language|assembly code]] for an [[x86|x86 processor]] might look like this:
<code>
add eax, edx
mov ecx, eax</code>
This code would add two values and move the result to a different ___location. Similar disassembled bytecode might look like this:
<code>
0 iload_1
1 iload_2
2 iadd
3 istore_3</code>
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:
<code>
Method java.lang.String getName()
0 aload_0 // The "this" object is stored in ___location 0 of the variable table
1 getfield #5 <Field java.lang.String name>
// This instructon 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 is the fifth field of the class.
4 areturn // Returns the object on top of the stack from the method.</code>
== Example ==
Consider the following Java code:
<source lang="java">
outer:
for (int i = 2; i < 1000; i++) {
for (int j = 2; j < i; j++) {
if (i % j == 0)
continue outer;
}
System.out.println (i);
}
</source>
A Java compiler might translate the Java code above into byte code as follows, assuming the above was put in a method:
<code>
0: iconst_2
1: istore_1
2: iload_1
3: sipush 1000
6: if_icmpge 44
9: iconst_2
10: istore_2
11: iload_2
12: iload_1
13: if_icmpge 31
16: iload_1
17: iload_2
18: irem
19: ifne 25
22: goto 38
25: iinc 2, 1
28: goto 11
31: getstatic #84; //Field java/lang/System.out:Ljava/io/PrintStream;
34: iload_1
35: invokevirtual #85; //Method java/io/PrintStream.println:(I)V
38: iinc 1, 1
41: goto 2
44: return</code>
== Generation ==
{{main|List of JVM languages}}
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|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 (Java assembler)|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 <ref>[http://jasmin.sourceforge.net Jasmin Home Page<!-- Bot generated title -->]</ref>
* [[Jamaica (Java assembler)|Jamaica]], a [[Macro (computer science)|macro]] [[assembly language]] for the [[Java virtual machine]]. Java syntax is used for class or interface definition. Method bodies are specified using bytecode instructions. <ref>[http://www.judoscript.org/jamaica.html Jamaica: The Java Virtual Machine (JVM) Macro Assembler<!-- Bot generated title -->]</ref>
Others have developed compilers, for different programming languages, in order to target the Java virtual machine, such as:
* [[JRuby]] and [[Jython]], two [[scripting language]]s based on [[Ruby (programming language)|Ruby]] and [[Python (programming language)|Python]]
* [[Groovy (programming language)|Groovy]], a [[scripting language]] based on Java
* [[Scala (programming language)|Scala]], a type-safe general-purpose programming language supporting object-oriented and functional programming
* [[JGNAT]] and [[AdaMagic|AppletMagic]], compile from the [[Ada programming language]] to Java bytecode
* [[C to Java byte-code compiler#C to bytecode compilers|C to Java byte-code compiler]]s
* [[Clojure]]
== Execution ==
Java bytecode is designed to be executed in a [[Java virtual machine]]. There are several virtual machines available today, both free and commercial products.
{{See|Java virtual machine}}
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 [[GCJ|GNU Compiler for Java]]. Some ARM processors have the ability to execute bytecode directly (see [[Jazelle]]).
==Support for dynamic languages==
{{main|list of JVM languages}}
The [[Java Virtual Machine]] has currently no built-in support for [[Type system#Dynamic_typing|dynamically typed languages]], because the existing JVM instruction set is [[Type system#Static typing|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.<ref>{{cite web
| url=http://headius.blogspot.com/2007/01/invokedynamic-actually-useful.html
| title=InvokeDynamic: Actually Useful?
| date=2007-01-03
|last=Nutter|first=Charles
| accessdate=2008-01-25}}</ref>
[[Java Community Process|JSR 292]] (''Supporting Dynamically Typed Languages on the JavaTM Platform'') <ref>[http://www.jcp.org/en/jsr/detail?id=292 see JSR 292]</ref> propose to add a new <code>invokedynamic</code> instruction at the JVM level, to allow method invocation relying on dynamic [[Type system#Type checking|type checking]] (instead of the existing statically type-checked <code>invokevirtual</code> instruction). The [[Da Vinci Machine]] is a prototype virtual machine implementation that hosts JVM extensions aimed at supporting dynamic languages.
== See also ==
* [[Java bytecode instruction listings]]
* [[Class (file format)]]
* [[List of JVM languages]]
* [[Java backporting tools]]
* [[C to Java Virtual Machine compilers]]
* [[ARM9E]]
* [[JStik]]
* [[Common Intermediate Language]]
== References ==
{{reflist|2}}
== External links ==
{{wikibooks|Java Programming|Byte Code|Java bytecode}}
* [http://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.html Sun's Java Virtual Machine Specification]
* [http://www.is-research.de/info/vmlanguages/ Programming Languages for the Java Virtual Machine]
* [http://www.drgarbage.com/bytecode-visualizer-lt.html Bytecode Visualizer LT - bytecode viewer and debugger (free Eclipse plugin)]
* [http://www.adaptj.com/main/stacktrace AdaptJ StackTrace - bytecode level debugging with a full control of the stack, the local variables, and the execution flow]
* [http://lulachronicles.blogspot.com Java Class Unpacker - plugin for Total Commander, it lets open class files as compressed archives and see fields and methods as files. The bytecode can be viewed as text using F3]
{{Java (Sun)}}
[[Category:Java platform|Bytecodes]]
[[Category:Assembly languages]]
[[bs:Java bytecode]]
[[ca:Bytecode (Java)]]
[[es:Java bytecode]]
[[fr:Bytecode Java]]
[[pt:Bytecode Java]]
‡†††††††' |
Whether or not the change was made through a Tor exit node (tor_exit_node ) | 0 |
Unix timestamp of change (timestamp ) | 1261329218 |