Reputation: 1032
I was reading the internals of JVM from here and came across the term "native pointer", what does it mean, does it has something to do with JNI?
In the text above it talks about Program Counters and says:
Each thread of a running program has its own pc register, or program counter, which is created when the thread is started. The pc register is one word in size, so it can hold both a native pointer and a returnAddress. As a thread executes a Java method, the pc register contains the address of the current instruction being executed by the thread. An "address" can be a native pointer or an offset from the beginning of a method's bytecodes. If a thread is executing a native method, the value of the pc register is undefined.
From what I understand returnAddress would be any reference address. Like:
Object o = new Object();
here o
would return the address of the Object created in the heap. Is my understanding correct?
Any example explaining both would be great.
Upvotes: 1
Views: 1848
Reputation: 533530
here o would return the address of the Object created in the heap.
The variable o
stores a reference. It is a look up value which is unique to that object. It might be the address but it might be a value which can be translated to the address. e.g. 64-bit JVMs can use 32-bit references up to a 64 GB heap, using a translated value.
what does it mean, does it has something to do with JNI?
The CPU uses pointers to address memory. To distinguish it from references, it is called a "native" pointer in Java.
JNI is the interface to C code which uses pointers.
The JVM's Program Counter is notional in a virtual machine and not accessible to the Java program.
The actual machine code uses a Program Counter managed by the CPU. Even this is some what abstract as a CPU can execute multiple instructions per clock cycle, speculatively so at any instant the Program Counter is just the point to which you can't roll back beyond, or it depends on the instruction being executed.
Upvotes: 2