Questions tagged [bytecode]

"bytecode" is a blanket term for opcodes that are consumed by a virtual machine. For example, the JVM runs bytecode stored in .class files and the CPython interpreter runs bytecode stored in .pyc files.

Bytecode, also known as p-code (portable code), is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (normally numeric addresses) which encode the result of parsing and semantic analysis of things like type, scope, and nesting depths of program objects. They therefore allow much better performance than direct interpretation of source code.

The name bytecode stems from instruction sets which have one-byte opcodes followed by optional parameters. Intermediate representations such as bytecode may be output by programming language implementations to ease interpretation, or it may be used to reduce hardware and operating system dependence by allowing the same code to run on different platforms. Bytecode may often be either directly executed on a virtual machine (i.e. interpreter), or it may be further compiled into machine code for better performance.

Since bytecode instructions are processed by software, they may be arbitrarily complex, but are nonetheless often akin to traditional hardware instructions; virtual stack machines are the most common, but virtual register machines have also been built. Different parts may often be stored in separate files, similar to object modules, but dynamically loaded during execution.

Source: Wikipedia (Bytecode)

Understanding bytecode makes you a better programmer https://www.ibm.com/developerworks/ibm/library/it-haggar_bytecode/

2276 questions
75
votes
4 answers

Difference between JVM's LookupSwitch and TableSwitch?

I have some difficulty to understand LookUpSwitch and TableSwitch in Java bytecode. If I understand well, both LookUpSwitch and TableSwitch correspond to the switch statement of Java source? Why one JAVA statement generates 2 different bytecodes?…
zell
  • 9,830
  • 10
  • 62
  • 115
74
votes
3 answers

Why are Java 8 lambdas invoked using invokedynamic?

The invokedynamic instruction is used to help the VM determine the method reference at runtime instead hardwiring it at compile time. This is useful with dynamic languages where the exact method and argument types aren't known until runtime. But…
Kshitiz Sharma
  • 17,947
  • 26
  • 98
  • 169
69
votes
4 answers

Gradle sourceCompatibility has no effect to subprojects

I have Java 6 and 7 installed on my machine. Gradle uses 1.7 (checked using gradle -v). But I need to compile my code to be compatible with Java 1.6. As far as I understand the documentation I can use the sourceCompatibility property to do so (and…
Joachim Kurz
  • 2,875
  • 6
  • 23
  • 43
68
votes
2 answers

Why does one long string take MORE space than lots of small strings?

Here is some code for a DFA, implemented as an array of strings: public class StringArray { private static final String[] stringArray = { …
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
66
votes
4 answers

Is there a llvm java front end that converts java source to llvm's intermediate form?

From what I've read, there is a llvm program that converts java bytecode to llvm's intermediate form called class2llvm. My question is, how do I access this. What front end do I have to install in order to access this. VMkit is their implementation…
FeelTheBurns
  • 1,065
  • 2
  • 8
  • 14
64
votes
1 answer

What is a stack map frame

I've recently been looking at The Java Virtual Machine Specifications (JVMS) to try to better understand the what makes my programs work, but I've found a section that I'm not quite getting... Section 4.7.4 describes the StackMapTable Attribute, and…
Steven
  • 1,709
  • 3
  • 17
  • 27
63
votes
6 answers

8 branches for try with resources - jacoco coverage possible?

I've got some code that uses try with resources and in jacoco it's coming up as only half covered. All the source code lines are green, but I get a little yellow symbol telling me that only 4 of 8 branches are covered. I'm having trouble figuring…
Gus
  • 6,719
  • 6
  • 37
  • 58
62
votes
3 answers

Why invokeSpecial is needed when invokeVirtual exists

There are three opcodes to invoke Java methods. It is clear that invokeStatic is just for static method invocation. As far as I know invokespecial is used when invoking constructor and private methods. So, do we need to differenticate private and…
Ahmet Karakaya
  • 9,899
  • 23
  • 86
  • 141
59
votes
9 answers

is it possible to disable javac's inlining of static final variables?

The Java static compiler (javac) inlines some static final variables and brings the values directly to the constant pool. Consider the following example. Class A defines some constants (public static final variables): public class A { public…
sjlee
  • 7,726
  • 2
  • 29
  • 37
56
votes
3 answers

Strange exception table entry produced by Sun's javac

Given this program: class Test { public static void main(String[] args) { try { throw new NullPointerException(); } catch (NullPointerException npe) { System.out.println("In catch"); } finally { …
aioobe
  • 413,195
  • 112
  • 811
  • 826
56
votes
0 answers

Method invocation instruction (invokevirtual/invokestatic) is substituted by some unexpected instructions

I have been investigating this error for a whole three days, but still no progress. I hope I can get some tips from here. What I am trying to do is to inline a MethodNode into a MethodHandle Call Site (#5, #17, and #30) with ASM library. For…
shijie xu
  • 1,975
  • 21
  • 52
53
votes
7 answers

What is the use of Python's basic optimizations mode? (python -O)

Python has a flag -O that you can execute the interpreter with. The option will generate "optimized" bytecode (written to .pyo files), and given twice, it will discard docstrings. From Python's man page: -O Turn on basic optimizations. This…
u0b34a0f6ae
  • 48,117
  • 14
  • 92
  • 101
52
votes
4 answers

Understanding STG

The design of GHC is based on something called STG, which stands for "spineless, tagless G-machine". Now G-machine is apparently short for "graph reduction machine", which defines how laziness is implemented. Unevaluated thunks are stored as an…
MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220
49
votes
14 answers

Are there any specific examples of backward incompatibilities between Java versions?

Have there been incompatibilities between Java releases where Java source code/Java class files targeting Java version X won't compile/run under version Y (where Y > X) ? By "Java release" I mean versions such as: JDK 1.0 (January, 1996) JDK 1.1…
knorv
  • 49,059
  • 74
  • 210
  • 294
47
votes
3 answers

Programming in Java bytecode

I'm looking to write a short program (maybe a Hello World) in Java bytecode. I just want to write the bytecode using my text editor and run it. How would I do this? Got an example? Thanks!
Corey Stevens
  • 481
  • 1
  • 4
  • 5