title: JNI field id for static fields
body: <p>I am currently trying to get the offset of a field in memory using JNI to be able to copy field values to off heap memory. I was able to get the offset for instance fields using the jFieldID for a field. The most significant 30 bits of a jFieldID represent the offset of a field for instance fields. The problem is with static fields. The 30 bits represent a JNIid*. A JNIid is a struct which contains an int offset field which is probably the offset of the field. Now my problem is how do I get this value. I used following code snippet (assuming id is the jFieldID of a field and address_shift is 2)</p>
  
  <pre><code> uintptr_t result = (uintptr_t) id &gt;&gt; address_shift;
   // offset field in JNIid struc is in offset 16
   jlong staticFieldoffsetAddress = result + 16;
   jint* staticFieldValuePointer = (jint*) staticFieldoffsetAddress;
  </code></pre>
  
  <p>This however is not giving me any value. I get 0 which is not correct since I am comparing it with what I get from Unsafe.staticFieldOffset(Field) in java. I know I can call this method from JNI and use the result. But I want it for a performance critical application.</p>