코드는 compile, link, execute의 3가지를 거쳐 프로그램으로 실행된다.
대부분의 컴퓨터 언어는
- compiler가 object file을 생성하고, linker가 object file을 연결하여 executable file을 만든다.
- compiler는 platform dependent하기 때문에(target machine, OS의 영향을 받기 때문에)
언어 개발자들은 platform마다 알맞은 compiler를 새로 만들어야 했다. - 일반 프로그래머들(high-level languge로 프로그래밍을 하는 사람)은 코드를 조금만 수정해도
실행하기 위해서는 처음부터 compile을 해야했다.더보기(프로그램 사이즈가 큰 경우엔 compile에만 상당한 시간이 걸리기도 한다.)
compile이 끝나고 실행하는데, 오타 때문에 수정된 부분을 제대로 확인도 못하고
다시 긴 compile을 기다려본 적이 있다면 얼마나 귀찮은지 공감할 것이다.
interpreter로 동작하는 언어는
- compile, link, execute의 단계가 존재한다기보다는
- 코드 statement를 읽을 때마다 high-level statement를 low-level로 conversion하여 수행한다.
- interpreter는 3가지 유형으로 나뉜다.
java는 compiler와 interpreter가 혼합된 형태이다.
- java compiler(javac)가 high-level code로부터 bytecode(.class file)를 생성한다.
(bytecode는 object file이 아니다.) - jvm이 bytecode를 이용하여 interpreter처럼 statement를 읽을 때마다 동적으로 link-execute를 수행한다.
(bytecode가 jvm interpreter의 object file처럼 동작한다.
linker가 존재하지 않고 동적으로 link를 수행한다는 것이 다르다)
장점
- platform independent하다. jvm이 os에 dependent 하지만 java compiler는 platform independent 하다.
windows에서 코드를 작성하고 compile한 뒤 linux에서 실행할 수 있다.
참고한 자료
www.cs.cmu.edu/~jcarroll/15-100-s05/supps/basics/history.html
How Java Works
Most computer languages use the "compile-link-execute" format. You start with source code and the compiler converts this program into a low-level program. In most compiled languages, the file containing the resulting low-level code is called an object
www.cs.cmu.edu
'언어 > Java' 카테고리의 다른 글
jvm internal - 1. Runtime Data Area (0) | 2021.01.30 |
---|---|
JVM internal - 0.Overview (0) | 2021.01.30 |
what jit likes and dislikes (0) | 2021.01.17 |
jit optimization - 흥미로운 사실1 (0) | 2021.01.17 |
Java ME vs SE vs EE, JRE (0) | 2021.01.12 |