Click here to Skip to main content
15,914,016 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: VB haters, look away Pin
Kirk 103898213-Aug-17 3:10
Kirk 103898213-Aug-17 3:10 
GeneralRe: VB haters, look away Pin
User 101325463-Aug-17 3:15
User 101325463-Aug-17 3:15 
GeneralRe: VB haters, look away Pin
kalberts2-Aug-17 22:23
kalberts2-Aug-17 22:23 
GeneralRe: VB haters, look away Pin
Michael Martin2-Aug-17 19:37
professionalMichael Martin2-Aug-17 19:37 
GeneralRe: VB haters, look away Pin
kalberts2-Aug-17 22:28
kalberts2-Aug-17 22:28 
GeneralRe: VB haters, look away Pin
User 101325462-Aug-17 23:09
User 101325462-Aug-17 23:09 
QuestionRe: VB haters, look away Pin
Kenworth713-Aug-17 0:27
professionalKenworth713-Aug-17 0:27 
AnswerRe: VB haters, look away Pin
kalberts3-Aug-17 1:41
kalberts3-Aug-17 1:41 
I haven't been working with compilers for a number of years, so maybe there are younger species out there that do things in a different way - I know the "classical" way of doing it, believing that today's compilers are roughly the same:

First, you break the source text into tokens. Then you try to identify structures in the sequence of tokens so that you can form a tree of hiearchical groups representing e.g. functions at some intermediate level, statements at a lower level, terms of a mathematical expression even further down. The term DAG - Directed Acyclic Graph - is commonly used for the parse tree. Nodes in the DAG commonly consist of 3-tuples or 4-tuples in a more or less common format for all nodes: Some semantic / operation code, two or three operands, or whatever else the compiler writer finds necessary.

Many kinds of optimisation is done by restructuring the DAG: Recognizing identical sub-trees (e.g. common subexpressions) that need to be done only once, identifying statements that within a loop will have identical effect in every iteration so that sub-tree can be moved out of the loop, etc. etc. Unreachable code is pruned off the DAG. All such operations are done on an abstract level - a variable X is treated as X without regard to its location in memory, number of bits (unless the language makes special requirements) etc. etc. The DAG is completely independent of the word length, byte ordering, 1- or 2-complement arithmetic, register ID or field structure of the instruction code of any specific machine architecture. You may think of variables and locations as sort of still in a "symbolic" form (lots of symbolic labels where never visible in the source code, so this certainly is "sort of").

Once you have done all the restructuring of the DAG that you care for, you may traverse the tree's leaf node to generate the actual machine instructions. (This part of the compiler is commonly called the "back end".) Now you assign memory addresses, use of registers, choose the fastest sequence of machine instructions for that specific machine. You can still do some optimization, e.g. keeping values in registers (now that you know which registers you've got), but it is essentially very local. The DAG indicates which sub-trees are semantically independent of each other, so that you may reorder them, run them in parallell, or e.g. assemble six independent multiplication operations into one vector multiply if your CPU allows. All internal symbolic rerferences can be peeled off; the only symbols retained are external entry points and references to external modules.

The back end may produce machine instructions for a hypthetical CPU that does not exist in silicon. Yet it has (or may have) its registers, word length, binary address space etc. There could be a machine having this instruction set as its native one. Many years ago, someone wrote an alternative microcode for a PDP-11 architecture so that it could execute the P4 bytecodes directly - but it was dead slow! Usually, you make a software virtual machine that pretends to be a "real" CPU for those instructions, interpreting the bytecodes one by one. JVM is such a virtual machine. For many years, this was The Way to run Java.

Compilers for dotNET essentially has no backend - they do not generate anything ready for execution. Essentially, their output is a linearization of the DAG, i.e. the abstract 4-tuple DAG nodes. The compiler backend is in the dotNET implementation: When a module is requested for the first time, the dotNET backend will do the last stages of compilation, creating machine specific binary code in the native instruction set of that specific machine, assigning specific locations to the named variables etc. The compiled result is stored in a cache, so that next time the same code is requested, no new compilation is required.

So, while Java bytecode is meant to be complete, ready to run, code (symbolic linking to other modules may still be required, but that is not code generation), dotNET assemblies are only half baked, requiring a final compilation step. This takes a little bit of time (it is surprisingly little!), but the generated code is native, requiring no interpretation.

Java compilers can generate binary code, rather than bytecode, but then it is for a specific machine. Or, the JVM may look at a (sequence of) bytecode(s) at run time, translate it to native instructions, but that is like interpreting Motorola 68000 instructions on a 386 (Apple did that when they switced to 386, to run old binary software!), but you will always be bound by the limitiations of the bytecode instruction set.

To a plain user with limited computer knowledge, there is little "visible" difference between the way JVM and dotNET works, but at the internal level, the architectures are signifiantly different.
GeneralRe: VB haters, look away Pin
Member 98620823-Aug-17 3:45
Member 98620823-Aug-17 3:45 
GeneralRe: VB haters, look away Pin
Kenworth713-Aug-17 12:54
professionalKenworth713-Aug-17 12:54 
GeneralRe: VB haters, look away Pin
kalberts3-Aug-17 22:35
kalberts3-Aug-17 22:35 
GeneralRe: VB haters, look away Pin
Kenworth713-Aug-17 22:47
professionalKenworth713-Aug-17 22:47 
GeneralRe: VB haters, look away Pin
kalberts4-Aug-17 0:17
kalberts4-Aug-17 0:17 
GeneralRe: VB haters, look away Pin
Kenworth714-Aug-17 11:00
professionalKenworth714-Aug-17 11:00 
GeneralRe: VB haters, look away Pin
kalberts6-Aug-17 20:32
kalberts6-Aug-17 20:32 
GeneralRe: VB haters, look away Pin
Kenworth716-Aug-17 21:08
professionalKenworth716-Aug-17 21:08 
GeneralRe: VB haters, look away Pin
kalberts6-Aug-17 22:05
kalberts6-Aug-17 22:05 
GeneralRe: VB haters, look away Pin
Kenworth717-Aug-17 0:21
professionalKenworth717-Aug-17 0:21 
GeneralRe: VB haters, look away Pin
kalberts7-Aug-17 1:30
kalberts7-Aug-17 1:30 
GeneralRe: VB haters, look away Pin
jschell3-Aug-17 5:59
jschell3-Aug-17 5:59 
GeneralRe: VB haters, look away Pin
kalberts3-Aug-17 21:49
kalberts3-Aug-17 21:49 
GeneralRe: VB haters, look away Pin
jschell8-Aug-17 13:20
jschell8-Aug-17 13:20 
GeneralRe: VB haters, look away Pin
Member 108155734-Aug-17 2:55
Member 108155734-Aug-17 2:55 
GeneralRe: VB haters, look away Pin
User 101325464-Aug-17 4:21
User 101325464-Aug-17 4:21 
GeneralRe: VB haters, look away Pin
PIEBALDconsult2-Aug-17 4:55
mvePIEBALDconsult2-Aug-17 4:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.