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
47
votes
4 answers

How are Scala traits compiled into Java bytecode?

I have played around with Scala for a while now, and I know that traits can act as the Scala equivalent of both interfaces and abstract classes. How exactly are traits compiled into Java bytecode? I found some short explanations that stated traits…
Justin Ardini
  • 9,768
  • 2
  • 39
  • 46
44
votes
2 answers

Why doesn't Python evaluate constant number arithmetic before compiling to bytecode?

In the following code, why doesn't Python compile f2 to the same bytecode as f1? Is there a reason not to? >>> def f1(x): x*100 >>> dis.dis(f1) 2 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (100) …
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
44
votes
1 answer

Best way to fix "No manual entry for byte\;type\=a" when try to seek kotlin bytecode in intellij

Step to reproduce on *.kt press command+shift+a for view bytecode btw, Show Kotlin Bytecode is working properly but broken on Show Bytecode (which I guess it will show java or java bytecode) select Show Bytecode then got this error But…
UmAnusorn
  • 10,420
  • 10
  • 72
  • 100
41
votes
8 answers

What are advantages of bytecode over native code?

It seems like anything you can do with bytecode you can do just as easily and much faster in native code. In theory, you could even retain platform and language independence by distributing programs and libraries in bytecode then compiling to native…
Jay Conrod
  • 28,943
  • 19
  • 98
  • 110
40
votes
7 answers

What is the difference between assembly code and bytecode?

While in the search for the various differences in the meanings of source code, bytecode, assembly code, machine code, compilers, linkers, interpreters, assemblers and all the rest, I only got confused on the difference between bytcode and assembly…
Aaron Gusman
  • 401
  • 1
  • 4
  • 3
40
votes
6 answers

Learning about Java bytecode and the JVM

In a recent question asked recently my simple minded answer highlighted many of my misconceptions about Java, the JVM, and how the code gets compiled and run. This has created a desire in me to take my understanding to a lower level. I have no…
faceless1_14
  • 7,382
  • 9
  • 31
  • 33
39
votes
1 answer

Compile lua code, store bytecode then load and execute it

I'm trying to compile a lua script that calls some exported functions, save the resulting bytecode to a file and then load this bytecode and execute it, but I haven't found any example on how to do this. Is there any example available on how to do…
WoLfulus
  • 1,948
  • 1
  • 14
  • 21
37
votes
1 answer

In Java Lambda's why is getClass() called on a captured variable

If you look at the byte code for Consumer println = System.out::println; the byte code generates by Java 8 update 121 is GETSTATIC java/lang/System.out : Ljava/io/PrintStream; DUP INVOKEVIRTUAL java/lang/Object.getClass…
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
36
votes
9 answers

Java bytecode specification

Is there a nice place for learning the JVM bytecode instruction set. The specification perhaps and maybe some tutorials? I ask because I would like to design a toy language and a compiler for it that generates JVM bytecode. Thanks for your knowledge…
Gnarlydog
36
votes
4 answers

Is there a java classfile / bytecode editor to edit instructions?

Is there a utility (or eclipse plugin) for editing java class files? I'd like to manipulate the bytecode of a java class file without recompiling it nor having a complete buildpath. E.g. to rename methods, add/delete instructions, change constants…
MRalwasser
  • 15,605
  • 15
  • 101
  • 147
34
votes
4 answers

Javassist. What is the main idea and where real use?

I know that Javassist is a Java library providing a means to manipulate the Java bytecode of an application. Ok, but why we need manipulate bytecode? Any real example? Any real app, where javassist used?
user471011
  • 7,104
  • 17
  • 69
  • 97
34
votes
6 answers

Java - Is binary code the same as ByteCode?

In Java, does "binary code" means the same as "Java bytecode?" Is this the flow in Java ? Java File (.java) -> [javac] -> ByteCode File (.class) -> [JVM/Java Interpreter] -> Running it(by first converting it into binary code specific to…
user327663
33
votes
4 answers

How do I get the byte values of a string in PHP?

Say I have a string in php, that prints out to a text file like this: nÖ§9q1Fª£ How do I get the byte codes of this to my text file rather than the funky ascii characters?
lynn
  • 2,868
  • 5
  • 31
  • 34
33
votes
1 answer

Advantages of Scala emitting bytecode for the JVM 1.7

As per Scala 2.10, what are the advantages (if any) of emitting bytecode for the JVM 1.7, when compared to the default of emitting for the 1.6?
Hugo Sereno Ferreira
  • 8,600
  • 7
  • 46
  • 92
32
votes
3 answers

How to emit and execute Java bytecode at runtime?

I am writing an interpreter in Java for a domain-specific language with some scripting capabilities. I have already implemented a parser and now need to do a back end. To this end I am considering either to write my own interpreter (either working…
vitaut
  • 49,672
  • 25
  • 199
  • 336