1.How Compiler is works?
Compiler consists the following phases: Lexical Analysis, Syntax Analysis, Semantic Analysis, IR Generation, IR Optimization, Code Generation, Optimization. //编译器主要包括下面几个阶段:词法分析,语法分析,语义分析,生成IR,IR优化,代码生成,优化。
2.Type Checking for Object Oriented Features
This post is about how object oriented features such as inheritance, overloading and overriding affect type checking. A type error occurs when an argument of an unexpected type is given to an operation. It can be signalled at compile time or at run time.
①.Inheritance:
|-- Need to consider shape of class hierarchies.
|-- When the least upper bound of A and B exists, we denote it A ∐ B.
②. Function overloading:
|-- At compile-time, determine which function is mean by inspecting the types of the arguments. Report an error if no one function is the best function.
③. Function overriding:
|-- Determine at run-time based on real object.
Note: static type systems are often incomplete. So the goal is to make the language as expressive as possible while still making the type-checker sound.
3. What do Java objects look like in memory during run-time?
Java methods are implemented as a stack(栈) of frames(帧) in JVM Stack and Java objects are allocated in Heap(堆). // stack of frames “栈帧由三部分组成:局部变量区、操作数栈和栈数据区。