Runtime Systems: Conventional vs. VEE
Lecture 5
- Conventional Vs VEE runtime systems
- Conventional system separates hardware from software, so in that sense it behaves like operating system.
- Java is combination of OOP and VEE. Java systems work over conventional execution model.
- Some questions that need to be answered are:
- What is virtualisation ?
- If virtual system decreases the performance of java programs then why do we use them?
- How does link-load work ?
- Issue 3: Conventional compiler Vs Java Compiler
- First let us understand the difference between preprocessor,compiler and interpreter
- It only does text substitution like #define Pi 3.14 will substitute every occurrence of Pi in the code with value 3.14.
- It will not perform any checks and balances i.e. no syntax,semantic analyses, no type checking.
- It will output preprocessed high level code
- It converts the high level code to low level code or machine code.
- It has different phases like syntax analysis,semantic analysis, translation to intermediate representation, optimisation and retarget to machine code
- It will output equivalent machine code for given high level code
- It reads the high level code line by line and converts to low level code, takes the input and gives the output.
- No executable is generated.
- In both compiler and interpreter the process is same. Interpreter may be slow because it reads and translates the code line by line and hence there is no optimisation.
- High level code is preprocessed by preprocessor to give preprocessed high level code. (using command gcc -E)
- Using compiler high level code is converted to assembly code.(using command gcc -S)
- Assembler the converts it to object code.(using command gas)
- Then linker links all the object file together and loader loads them to form a executable code.
- Finally executable code will take the input and give its corresponding output.
- So it has 2 phases, analysis and synthesis.
- In analysis, high level code is converted to intermediate machine independent representation.
- In synthesis, intermediate code is converted to machine dependent low level code.
- Due to this we can conveniently add a new language or a new processor with less efforts. Hence gcc is now known as GNU compiler collection instead of GNU C compiler.
- javac compiler converts the java code to intermediate machine independent byte code. It uses P code format.
- Then the JIT (Just In Time compiler) converts the byte code to machine dependent low level code. This is done in virtual execution environment called JVM (java virtual machine).
- Microsoft does the same thing, it converts any language like C# to machine independent MSIL(microsoft intermediate language) that uses P code format instead of byte code and CLR (common language runtime ) converts it to machine dependent low level code.
- Therefore we conclude that
- We should not have preprocessor.
- Compiler or Interpreter does not matter as both have same process.
- Machine independent code is not a relevant factor.
- So question arises that why virtualization is needed if all this can be done on conventional system ?
- Issue 4: VEE :: Conventional Vs JVM/CLR
- In Conventional: High level lang, => Byte code => differect OS => Machine lang
- In JVM : Java => Byte code => JVM (runtime services )=> different OS => Machine lang.
- runtime service include garbage collection, security etc
- In CLR: C# (managed lang) => MSIL => CLR(runtime services) => Windows => Machine lang.
- Managed means it requires least care in virtual system.
- VEE: Virtual means something that does not exist, in that sense VEE is not virtual. It is middle layer between intermediate language(IL) and operating system (OS). As it adds value to the system and gives more than intended, we call it as value added execution environment or managed execution environment.
- In conventional execution environment, the intermediate language is in one of the following formats:
- AST (Abstract syntax tree)
- TA code (Three address code)
- SAS (Single assignment statement)
- Question to think on : Why does JVM/CLR use P-code format (Bytecode/MSIL) for representing intermediate language instead of above 3 formats ?
- VEE helps in developing secure, type safe and trusted systems
- CLI & CLR : Common Language Infrastructure and Common Language Runtime. It is called common language because there is no restriction to have only one language (like JVM allows only java), we can use any managed language (like managed C/C++).
- Managed languages must follow following conditions:
- CLS : Common language specification, it includes the specification of the language like the syntax and semantics, how it is dealt during runtime, input parameters etc..
- CTS : Common type system, it means the types defined in all managed languages should be same.
- Basic necessity to have CLI/CLR is that programing language and libraries should be APIs and CLS compliant.