Skip to main content
406 votes

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

Why is JavaScript not compiled to bytecode before sending over the network? Background: I was on the ECMAScript technical committee in the late 1990s and one of the implementers of Microsoft's ...
Eric Lippert's user avatar
  • 46.2k
123 votes
Accepted

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

View Source "View Source" was in the beginning, and still is to some extent, considered to be an important feature of the web. It is how generations of web developers learned web development,...
Jörg W Mittag's user avatar
79 votes
Accepted

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

The logic is that JVM bytecode is a lot simpler than Java source code. Compilers can be thought of, at a highly abstract level, as having three basic parts: parsing, semantic analysis, and code ...
Mason Wheeler's user avatar
27 votes

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

Intermediate representations of various sorts are increasingly common in compiler / runtime design, for a few reasons. In Java's case, the number one reason initially was probably portability: Java ...
IMSoP's user avatar
  • 5,877
19 votes

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

JavaScript was invented by Netscape in 1995 and was initially positioned as an easy-to-use embedded scripting language which could integrate with HTML and control more complex components written in ...
JacquesB's user avatar
  • 59.8k
11 votes
Accepted

How exactly is bytecode "parsed"?

I think your confusion comes from thinking of bytecodes as a language that is being interpreted by the virtual machine. While this is technically a correct way to describe it, it's leading you to ...
JimmyJames's user avatar
  • 27.6k
10 votes

Do bytecode compilers compile syntax directly or intermediate assembly language?

If I do compiler -> intermediate language -> bytecode - it should be simpler, but will take much more time because I have to write three programs. You don't need to write three programs, you just ...
Basile Starynkevitch's user avatar
10 votes
Accepted

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

It's not random, but it may not be immediately apparent. And it may have evolved over time: the x86, architecture, for example, has been with us for nearly 40 years (1977), and has evolved from 16-...
kdgregory's user avatar
  • 5,250
8 votes

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

There seem to be at least two different possible questions here. One is really about compilers in general, with Java basically just an example of the genre. The other is more specific to Java the ...
Jerry Coffin's user avatar
  • 44.5k
8 votes

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

It sounds like you're wondering why we don't just distribute source code. Let me turn that question around: why don't we just distribute machine code? Clearly the answer here is that Java, by design, ...
Joel Coehoorn's user avatar
7 votes
Accepted

How do JIT interpreters handle variable names?

Have a look at this example from Wikipedia: for (int i = 2; i < 1000; i++) { for (int j = 2; j < i; j++) { if (i % j == 0) continue outer; } System.out.println (...
Robert Harvey's user avatar
7 votes

Is there a way to see how many operations a function, block of code or a statement costs?

You can kind-of put a bound on the number of CPU cycles a certain instruction takes by looking at the manual for the specific CPU you are interested in. E.g. Intel publishes instruction manuals for ...
Jörg W Mittag's user avatar
7 votes
Accepted

How are literal values encoded into bytecode?

Your question applies more broadly than byte code systems, to general instruction set architecture, hardware or byte code. What is the common practice when encoding literal values, whose byte ...
Erik Eidt's user avatar
  • 34.2k
5 votes
Accepted

How should a bytecode VM call external C functions?

Exactly, you can obtain function pointers via dlsym() and then call them – but how to perform the call depends on the function's calling convention. In theory you could write some assembly to bridge ...
amon's user avatar
  • 135k
5 votes

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

It is certainly possible that the JPEG and PNG people might have used XML-based headers if file size were not an issue. Using text would make it more obvious what all the fields mean and so forth. ...
Nicol Bolas's user avatar
  • 11.9k
5 votes
Accepted

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

Not all virtual machines use a linear byte code. If the byte code forms a graph data structure, the conditional operation can directly reference all branches, and no explicit jump targets have to be ...
amon's user avatar
  • 135k
4 votes

Is there a way to see how many operations a function, block of code or a statement costs?

Typically, we ignore the specifics of "how many ops" and such- why? Because it doesn't matter. Different operations likely take different amounts of time, and that time is implementation-specific. ...
Delioth's user avatar
  • 433
4 votes

How are literal values encoded into bytecode?

the arguments to PUSH are a variable number of bytes, so the virtual machine does not know how many bytes it needs to read for each argument. Usually, the architecture dictates that all arguments are ...
8bittree's user avatar
  • 5,656
4 votes

How do JIT interpreters handle variable names?

Variables are mostly known at parsing time and their binding and scope is relevant for parsing. JIT compiling libraries don't really handle variables (and don't care much about their name, type and ...
Basile Starynkevitch's user avatar
4 votes

How exactly is bytecode "parsed"?

Byte codes are decoded. They are designed like a processor instruction set. Because the byte codes are variable length, even though we know where they are, in order to decode them, you have to ...
Erik Eidt's user avatar
  • 34.2k
3 votes

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

Byte arrays are human readable. I've been reading them since I was 10 and I've been human for longer than that. This was before I even had a fancy hex editor. Peek and Poke commands are old friends....
candied_orange's user avatar
3 votes

How exactly is bytecode "parsed"?

The file will have a small header with information about the version, where the executable bytecode is located (plus maybe information about the functions contained in it) and where the constant data (...
ratchet freak's user avatar
3 votes

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

I have never designed a bytecode, but here are some things I would consider if I did: I think that it does not matter much. If people will want to work with your bytecode, they will do that using ...
svick's user avatar
  • 10.1k
2 votes

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

You example XML isn't even a good example, as you're still using a byte array. A 'true' XML for an image, to contrast with byte arrays, would be something like: <s:Image xmlns="www.w3c.org" width="...
whatsisname's user avatar
  • 27.6k
2 votes

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

Two things: The benefits of your scheme are small and questionable: yes I can parse and extract metadata a bit more easily. But you only really need one C library to parse an image format and then it'...
walpen's user avatar
  • 3,241
2 votes

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

I use a routine that evaluates a given AST for branching to a desired label (with a boolean indicating normal or reversal of the jump condition). In pseudo code, (I'm trying to convey the algorithm, ...
Erik Eidt's user avatar
  • 34.2k
1 vote
Accepted

Bytecode format and loading in language VMs

You are on the right track. What you call a "chunk" is often called a "compilation unit" - the amount of source code that is compiled together. It seems you have already solved how ...
JacquesB's user avatar
  • 59.8k
1 vote

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

Data use is probably not actually a problem. To respond to the assumption in the body (since the wonderful response by Eric Lippert seems to have the actual questions quite well covered): Whether ...
sp88's user avatar
  • 35
1 vote

How are literal values encoded into bytecode?

Literal objects are stored in an array outside of the bytecode. And then the put bytecode just indexes into that array. A Ruby example, $ ruby --dump insns -e '[nil,0,1,2,"str",/regexp/]' == disasm:...
akuhn's user avatar
  • 717

Only top scored, non community-wiki answers of a minimum length are eligible