Questions tagged [bytecode]

22 questions
172
votes
4 answers

Why is JavaScript not compiled to bytecode before sending over the network?

You'd often see that JavaScript is actually being transported over the web with all the useless stuff that doesn't need to be there -- Comments, particularly those containing licenses, indentations ('\t', '\n'), etc. Given enough time, it could end…
zombiesauce
  • 1,429
  • 2
  • 6
  • 8
65
votes
4 answers

Why do VMs need to be "stack machines" or "register machines" etc.?

(This is an extremely newbie-ish question). I've been studying a little about Virtual Machines. Turns out a lot of them are designed very similarly to physical or theoretical computers. I read that the JVM for example, is a 'stack machine'. What…
Aviv Cohn
  • 21,190
  • 31
  • 118
  • 178
37
votes
8 answers

What is the use of converting source code to Java bytecode?

If one needs different JVMs for different architectures I can't figure out what is the logic behind introducing this concept. In other languages we need different compilers for different machines, but in Java we require different JVMs so what is the…
Pranjal Kumar
  • 603
  • 1
  • 5
  • 9
15
votes
5 answers

Compilation to bytecode vs machine code

Does compilation that produces an interim bytecode (like with Java), rather than going "all the way" to machine code, generally involve less complexity (and thus likely take less time)?
Julian A.
  • 253
  • 1
  • 2
  • 7
11
votes
3 answers

Why does Python need both a compiler and an interpreter?

I can understand the fact that Java needs both a compiler and an interpreter. It compiles source code to bytecode and then a virtual machine (on Windows, on Linux, on Android, etc.) translates that bytecode to machine code for the current…
aris
  • 119
  • 1
  • 3
7
votes
2 answers

What is the common procedure when producing jump targets in bytecode?

Over the course of the past few days, I've been trying many different methods for correctly calculating jump targets in bytecode, but none have been practical or reliable. Furthermore, the methods I've tried did not allow nested if-statements and/or…
6
votes
3 answers

How are literal values encoded into bytecode?

Note: This question is somewhat related to How exactly is bytecode "parsed"?, but it is not a duplicate of it. In this question, I'm asking about a specific part of how bytecode is generated, not how bytecode is "parsed". As stated in the title,…
6
votes
3 answers

What is the procedure(if any) to select bytes to represent opcodes?

TL;DR What procedure is followed when selecting bytes to represent opcodes? Are byte(s) for opcodes just randomly chosen, and them mapped to mnemonics? I recently learned from this answer that bytecode usually consists of instructions which have…
6
votes
2 answers

How do JIT interpreters handle variable names?

Let's say I am to design a JIT interpreter that translates IL or bytecode to executable instructions at runtime. Every time a variable name is encountered in the code, the JIT interpreter has to translate that into the respective memory address,…
MathuSum Mut
  • 219
  • 1
  • 7
6
votes
6 answers

Is Java Bytecode interpreted?

The definition of interpretation (correct me if I'm wrong) is parsing code like so: 1- Translate currently parsed line to some intermediate language. 2- Run the translated line. 3- Move to the next line. 4- Translate it. 5- Run it. And so on. If so,…
NPElover
  • 181
  • 1
  • 2
  • 11
4
votes
3 answers

How exactly is bytecode "parsed"?

How is Bytecode "parsed"? It is my understand that Bytecode is a binary, intermediate representation of the syntax of a given programming language. Certain programming languages convert their source text into Bytecode which is then written to a…
Christian Dean
  • 2,790
  • 1
  • 22
  • 38
4
votes
1 answer

Why is the Java bytecode instruction set not orthogonal?

Section 2.11.1 of the JVM 8 Specification includes the words: In other words, the instruction set is intentionally not orthogonal. From my perspective, that implies that the Java bytecode instruction set is full of dirty hacks. I understand that…
kd8azz
  • 143
  • 4
3
votes
4 answers

Would you use Byte Arrays or XML if size was not an issue?

In my basic understanding of ByteArrays the benefit is that it is smaller in file size. The down size of a ByteArray is that for any given format you have to know the about the file format to get information out of it. You need a specification and…
1.21 gigawatts
  • 1,209
  • 1
  • 10
  • 22
2
votes
1 answer

How should a bytecode VM call external C functions?

I am trying to implement a basic bytecode VM, which I plan to target with a compiler. How can I implement the ability to call external C functions using the bytecode, i.e., call arbitrary functions in runtime. For example, my future compiler should…
Greatcode
  • 67
  • 6
2
votes
1 answer

Do bytecode compilers compile syntax directly or intermediate assembly language?

I am going to write a very simple VM and bytecode compiler. Is it typical for a bytecode compiler to read the syntax and attempt to create the bytecode directly or is there an intermediate stage to make the process easier to understand? If I do…
Synaps3
  • 147
  • 3
1
2