8
이 코드가 있다고 가정 (정말 내가 생각하지만, 여기 경우에 그것이 중요하지 않습니다) : 여기java9 고유의 방법
public class AtomicJDK9 {
static AtomicInteger ai = new AtomicInteger(0);
public static void main(String[] args) {
int sum = 0;
for (int i = 0; i < 30_000; ++i) {
sum += atomicIncrement();
}
System.out.println(sum);
}
public static int atomicIncrement() {
ai.getAndAdd(12);
return ai.get();
}
}
그리고 내가 그것을 호출하고 어떻게 (사용 java9) :
내가 알아 내려고하는 것은 내장 된 코드로 대체 된 메서드입니다. (안전하지 않은 내부) 명중 첫 번째 :
@HotSpotIntrinsicCandidate
public final int getAndAddInt(Object o, long offset, int delta) {
int v;
do {
v = getIntVolatile(o, offset);
} while (!weakCompareAndSwapIntVolatile(o, offset, v, v + delta));
return v;
}
그리고이 방법은 위의 호출의 출력에 실제로 존재 :
@ 8 jdk.internal.misc.Unsafe::getAndAddInt (27 bytes) (intrinsic)
그러나, 전체 출력은 내게 그것을 위해 (이상한)이다
@ 8 jdk.internal.misc.Unsafe::getAndAddInt (27 bytes) (intrinsic)
@ 3 jdk.internal.misc.Unsafe::getIntVolatile (0 bytes) (intrinsic)
@ 18 jdk.internal.misc.Unsafe::weakCompareAndSwapIntVolatile (11 bytes) (intrinsic)
@ 7 jdk.internal.misc.Unsafe::compareAndSwapInt (0 bytes) (intrinsic)
@ 8 jdk.internal.misc.Unsafe::getAndAddInt (27 bytes) (intrinsic)
왜 출력에 두 번 존재하는 getAndAddInt입니까?
또한 getAndAddInt가 실제로 내장 호출로 대체 된 경우 다른 모든 내장 메소드를 호출 스택으로 바꾸어야하는 이유가 더 이상 사용되지 않습니다. 메서드 호출 스택이 바닥에서 가로 지르는 것처럼 간단하다고 가정합니다.
아마도 + PrintCompilation (또는 새로운 통합 로깅이 무엇이든지간에)을 추가하고 컨텍스트에서 빛을 비추십시오. – the8472