Week 3. Compilation, Interpretation and JVM

¡Supera tus tareas y exámenes ahora con Quizwiz!

What are the two ways a high level rogram can be executed on a machine?

- Compiled into a program in the native machine language and then run on the target machine - Directly interpreted and the execution is simulated within an interpreter.

Provide the summary for JVM Instruction set characteristics.

- Different from most CPUs - Closer to high- level programming languages, rather than von Neumann architecture. - No accumulator/registers — just stacks! - Variable length instructions. - Typed instructions, meaning each instruction will depend on a data type used. LOADing integer, and LOADing pointer is not the same! (this is to help verify security constraints).

What are advantages of interpretation?

- Facilitates interactive debugging and testing - User can modify the values of variables; can invoke procedures from the command line. - Code is portable unlike compiled programs

What are disadvantages of interpretation? (NEEDS REVIEW)

- Slower execution compared to compilation. - You have to give the source code to the end user to execute the program - you have to interpret each instruction every time the instruction is executed.

Describe the features of JVM architecture

- Stack machine! Closer to modern high-level languages than the von Neumann machines , or registers machines. Hence, JVM becomes independent of the underlying architecture. - Memory: 32 bit words (=4 bytes). Whenever I need to read something from memory, I will read it in 32-bit words . - Instructions: 226 in total, variable length, 1-5 bytes. - Program: byte stream. JVM processes the program as a stream of bytes, rather than blocks of bytes. (Treat everything as a single byte unit). - Data: stored in words (we always use 4 bytes for storing the data). If you need to store a byte, you will still store it in a 4-byte word. - Program Counter (PC) contains byte addresses.

What are stacks good for?

1. Expression evaluation - can handle bracketed expressions (a1 + a2)*a3 without temporary variables. 2. Direct support for recursive method calls - can store return address. 3. Direct support for local variables (stored at the base of stack, deleted when method exits).

What are the rules of Shunting Yard Algorithm?

1. If you see a number/value, you directly put it into the output 2. If you see an operator, you will move it to the stack. 3. If you see an opening racket, you will push it on the stack. 4. If you see a closing bracket, you will pop all the operators from the stack, until you reach the opening bracket. 5. Whenever you see an operator, and you want to push it onto the stack, if the operator on the stack is already EQUAL OR HIGHER in precedence, you will pop it to the output, and put the other operator on the stack.

what is the meaning of these JVM instructions? 1. iadd 2. dadd

1. iadd - add int 2. dadd - add double

What is absolute code?

Absolute code is code with hardware addresses fixed into instructions (e.g. JUMP 1000)

What are advantages of compilation?

Advantages: - Compilation is done once for each program - Source code won't be needed after compilation - We can optimize object code (by exploiting hardware features) so that it will run fast - In general, speed of execution is higher compared to interpreted languages, as the executable has already been compiled and no other additional steps needed to run the program.

How can we combine compilation and interpretation?

Compile to an intermediate level (between high and low) language that can be efficiently interpreted. o Slower than pure compilation o Faster than pure interpretation o A single compiler, independent of the target CPU into the intermediate language o Separate task for each CPU is to interpret the intermediate language.

What are disadvantages of compilation?

Disadvantages of compilation: - Hardware dependent (cannot be run on different platforms) => poor portabilty - Harder to debug (after changes to source code, the program needs to be recompiled) - Though done once, compilation is a compute intensice process! Compilation time can take a while.

Is it true that a compiler must generate binary machine code that can be loaded and run directly?

False. A compiler can generate code in any language. It might be another high level language, assembly language or raw binary. It is unusual that even binary code be directly executed because we usually need to 'relocate' the code because of multiple modules and libraries.

Is it true that an interpreter is a software implementation of an existing Instruction Set Architecture?

False. An interpreter is usually an implementation of a virtual machine. It could be an existing concrete machine (this is usually referred to as an emulator) but not usually.

Is it true that the JVM is only capable of executing programs written in Java?

False. JVM has been used as the target of compilers for many languages, not just Java. Moreover, JVM executes bytecode, which is an intermediate representation and is different from Java.

Is it true that an assembler just maps instruction mnemonics written in assembler code into the corresponding bit pattern?

False. Whilst there is a much closer relationship between assembler and the binary machine code, the process of assembly involves more than just mapping 1:1. For instance, symbolic addresses (e.g. labels) need to be resolved. Some instructions in assembler are 'pseudo-instructions' which need to be mapped to 1 or more actual instructions.

What is an alternative name of a stack?

LIFO — Last in, First Out (aka FILO) data structure

In JVM architrecture what is Methid area?

Method area — segment of memory for storing methods.

What is relocatable code?

Relocatable code is code that is independent of any memory addresses. We use the base address: JUMP B+100, so we tell the system to compute base address + 100 to find an actual address.

What is a Stack Pointer in a stack?

Stack Pointer (SP) — top of stack (the most recently added element).

Is it true that just in time compiler generates executable code at runtime?

True.

What is the purpose of heap?

dynamic memory allocation (meaning without any order). This happens when one creates an object using the new operator.


Conjuntos de estudio relacionados

REAL Estate U part 3 (LAW OF CONTRACTS) ch 4,5,6

View Set

Project Management WGU - Pre Assessment

View Set

Unit 0, Nature of Science Study Guide

View Set

психологія словник

View Set

Artificial Intelligence Searching Algorithms

View Set

AP Computer Science A - Using Objects (Unit 2) Test Review

View Set