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/

2113 questions
874
votes
10 answers

Why is 2 * (i * i) faster than 2 * i * i in Java?

The following Java program takes on average between 0.50 secs and 0.55 secs to run: public static void main(String[] args) { long startTime = System.nanoTime(); int n = 0; for (int i = 0; i < 1000000000; i++) { n += 2 * (i * i); …
Stefan
  • 4,691
  • 3
  • 5
  • 12
231
votes
13 answers

Can you "compile" PHP code and upload a binary-ish file, which will just be run by the byte code interpreter?

I know that PHP is compiled to byte code before it is run on the server, and then that byte code can be cached so that the whole script doesn't have to be re-interpreted with every web access. But can you "compile" PHP code and upload a binary-ish…
Carson Myers
  • 34,352
  • 35
  • 118
  • 164
209
votes
4 answers

Why does a Java class compile differently with a blank line?

I have the following Java class public class HelloWorld { public static void main(String []args) { } } When I compile this file and run a sha256 on the resulting class file I get 9c8d09e27ea78319ddb85fcf4f8085aa7762b0ab36dc5ba5fd000dccb63960ff…
KNejad
  • 2,011
  • 2
  • 10
  • 21
188
votes
8 answers

Java 7 language features with Android

Just wondering if anyone has tried using new Java 7 language features with Android? I know that Android reads the bytecode that Java spits out and turns it to dex. So I guess my question is can it understand the bytecode of Java 7?
Daniel Ryan
  • 6,566
  • 4
  • 40
  • 60
150
votes
9 answers

Bytecode features not available in the Java language

Are there currently (Java 6) things you can do in Java bytecode that you can't do from within the Java language? I know both are Turing complete, so read "can do" as "can do significantly faster/better, or just in a different way". I'm thinking of…
Bart van Heukelom
  • 40,403
  • 57
  • 174
  • 291
143
votes
5 answers

Java's Virtual Machine and CLR

As a sort of follow up to the question called Differences between MSIL and Java bytecode?, what is the (major) differences or similarity in how the Java Virtual Machine works versus how the .NET Framework Common Language Runtime (CLR) works? Also,…
Frank V
  • 23,732
  • 32
  • 98
  • 142
142
votes
6 answers

How do I byte-compile everything in my .emacs.d directory?

I have decided to check out Emacs, and I liked it very much. Now, I'm using the Emacs Starter Kit, which sort of provides better defaults and some nice customizations to default install of Emacs. I have customized it a little, added some stuff like…
Mikka
  • 2,073
  • 2
  • 16
  • 11
127
votes
4 answers

How is pattern matching in Scala implemented at the bytecode level?

How is pattern matching in Scala implemented at the bytecode level? Is it like a series of if (x instanceof Foo) constructs, or something else? What are its performance implications? For example, given the following code (from Scala By Example pages…
Esko Luontola
  • 71,072
  • 15
  • 108
  • 126
119
votes
31 answers

C++ performance vs. Java/C#

My understanding is that C/C++ produces native code to run on a particular machine architecture. Conversely, languages like Java and C# run on top of a virtual machine which abstracts away the native architecture. Logically it would seem…
user23126
  • 2,001
  • 5
  • 18
  • 15
112
votes
4 answers

What is the difference between native code, machine code and assembly code?

I'm confused about machine code and native code in the context of .NET languages. What is the difference between them? Are they the same?
samaladeepak
  • 1,121
  • 2
  • 8
  • 3
110
votes
5 answers

Is it possible to view bytecode of Class file?

Possible Duplicate: Is there a java classfile / bytecode editor to edit instructions? Java source code is compiled into bytecode, which is actually in the class file. Is it possible to view bytecode of a compiled class? If it is possible, can it…
Abhishek Jain
  • 5,940
  • 7
  • 23
  • 34
89
votes
6 answers

Why the Global Interpreter Lock?

What is exactly the function of Python's Global Interpreter Lock? Do other languages that are compiled to bytecode employ a similar mechanism?
Federico A. Ramponi
  • 43,319
  • 29
  • 102
  • 130
82
votes
8 answers

Differences between MSIL and Java bytecode?

I'm new to .Net and I'm trying to understand the basics first. What is the difference between MSIL and Java bytecode?
user18055
  • 821
  • 1
  • 7
  • 4
82
votes
18 answers

What's the purpose of the CIL nop opcode?

I'm going through MSIL and noticing there are a lot of nop instructions in the MSIL. The MSDN article says they take no action and are used to fill space if the opcode is patched. They're used a lot more in debug builds than release builds. I know…
Dan Goldstein
  • 22,493
  • 10
  • 44
  • 51
79
votes
5 answers

Does unused import and objects have a performance impact

I have a doubt, whether the unused imports and unused objects in Java code create any performance impact? Suppose an object is initialized and never used, what happens? And what is the cost of unused imports?
Dheeraj Joshi
  • 2,647
  • 5
  • 35
  • 49
1
2 3
99 100