메모리의 대부분이 off-heap 인 경우 "unsafe.allocateMemory"함수를 호출하고있었습니다. 그러나 반환 된 값은 이상합니다.unsafe.allocateMemory가 Java로 반환됩니다.
런타임 환경은 여기 보여줍니다 여기
내 코드입니다 :
import java.lang.reflect.Field;
import sun.misc.Unsafe;
public class UnsafeTest{
public static void main(String[] args){
try{
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
Unsafe unsafe = (Unsafe) theUnsafe.get(null);
long addr = unsafe.allocateMemory(16);
System.out.println("the address is :"+addr);
unsafe.freeMemory(addr);
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
결과 :
나는 결과 값이 너무 많이 있기 때문에 뭔가가 잘못 생각 총 메모리 크기 (약 6G)보다 큽니다. 값이 메모리 주소인지 궁금합니다. 그렇다면 어떻게 실제로 메모리가 그렇게 많지 않으므로 할당 할 수 있습니까? 그렇지 않은 경우 운영 체제의 메모리/힙의 기본 주소는 무엇입니까?
http://hg.openjdk.java .net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/sun/misc/Unsafe.java # l466 –
Unsafe의 사용은 고급, 저수준 프로그래밍에만 해당됩니다. 나는 당신이 그 자격이 없다고 제안합니다. – DwB
https://en.wikipedia.org/wiki/X86-64#Virtual_address_space_details –