본문 바로가기

Programming (IT)

JNI Spec #2

반응형
이 chapter는 JNI 설계의 주요 이슈에 대해서 다룬다. 가장 큰 설계 이슈는 native methods와의 관계이다. API 호출에 관한 설계는 Chapter 5에서 설명한다.

JNI Interface Functions and Pointers

Native code는 Java VM에 JNI function을 호출함으로서 접근한다. JNI function은 interface pointer를 통하여 사용된다.
이 pointer는 사전에 정의된 pointer array를 가르킨다. Interface pointer는 pointer의 pointer이며, 이 pointer는 배열로 이루어져 있다. 모든 Interface function은 사전에 정의된 offset에 때라 배열에 위치한다.
그림 생략 --> 중요한 그림임

JNI inteface는 C++ 가상 함수 테이블이나 COM interface에서 유래된다. Interface table을 쓰면 native code로 부터 JNI name space를 분리할 수 있어 hard-wired function 진입을 사용하는 것보다 낫다. A VM 다양한 버젼의 JNI funtion tatble을 제공한다.
 - one performs thorough illegal argument checks, and is suitable for debugging
 - the other performs the minimal amount of checking required by the JNI specificationk, and is therefore more efficient

jNI interface pointer는 오직 현재 thread에서만 유효하다. 따라서, 한개의 thread에서 다른 thread로 interface pointer는 전달 될 수 없다. A VM의 JNI 구현은 JNI interface Pointer가 가르키는 지역에 thread data를 할당되고  저장된다.

Native method는 argument형태로 JNI interface pointer를 전달 받는다.