언어/Java

jit optimization - 흥미로운 사실1

nanon 2021. 1. 17. 10:05

1. naming

위가 아래보다 느리다.

 

compiler는 log 파일을 이용하는데, this.size와 this.elementData.length는 동일하지 않기 때문이다.(값은 동일하지만.)

 

this.size = this.elementData.length

for (int i = 0; i < this.size; i++) {
	
    if ( i >= this.elementData.length) throw new AIOBE();

}
// this.size = this.elementData.length

for (int i = 0; i < this.elementData.length; i++) {
	
    if ( i >= this.elementData.length) throw new AIOBE();

}

youtu.be/oH4_unx8eJQ?t=2178

 

2. implicit null check

if ( this.elementData == null ) throw new NPE();

this.elementData.length

 

C언어를 생각해보면 

this.element가 null일 때, this.element.length에 접근하면 segmentation fault가 발생한다.

java는 segmentation fault를 NPE로 wrap한다.

이 과정이 쉽고 빠르다고 한다.

 

 

3. Garbage Collection(Stop The World)

Garbage collection을 하기 위해서는 모든 thread를 정지시켜야한다.

thread를 정지시키는 방식이 꽤 재미있다.

 

poison page라는 개념을 이용한다.

JIT은 주기적으로 각 thread에 poison page를 읽으라는 명령어를 집어넣는다.

Garbage Collection이 필요하면 page를 unmap해서,

모든 thread에서 segmentation fault가 발생하도록 한다.

 

youtu.be/oH4_unx8eJQ?t=2868

 

4. loop peeling

youtu.be/oH4_unx8eJQ?t=3161youtu.be/oH4_unx8eJQ?t=3161

 

5. inlining & iterator is not a synthetic sugar

- inlining: youtu.be/oH4_unx8eJQ?t=3512

- iterator is not a synthetic sugar: youtu.be/oH4_unx8eJQ?t=4075