I'm trying to add a new procedure to Java native methods. To do this, I download the OpenJDK 7 source code to build a new JVM that contains my procedure in Windows XP (32 bits).
My problem is how to calculate the address of an element of array object Java in the heap?
Suppose that I create an array T
of 5 elements, each element is composed of 2 integer element (int x, int y) [8 bytes (4 byte for x and 4 bytes for y)].
To get T[0]
, we need to get the address containing in T[0]
and load it content from memory.
I've implemented this method in Microsoft VS2010 and it works very well:
Elmt
: is an object of 2 integer Elmt(int x,int y)
static void test(Elmt* from, Elmt* to, size_t count) {
from += count - 1;
to += count - 1;
while (count-- > 0) {
update(from);
*to-- = *from--;
}
}
static void update (Elmt* p){
__asm{
mov ecx, p
mov [ecx], 7
}
}
The procedure update change the element as follow: x=7
For example: T[0] = (1, 1)
after update will be T[0] = (7, 1)
.
Now, when I add this method to OpenJDK 7, I have a problem with the address of elements in JVM.
I could not calculate the correct address of the elements from the addresses in array T
.
The code in OpenJDK is as follows, with OOP the ordinary object used by the JVM
static void test(oop* from, oop * to, size_t count) {
from += count - 1;
to += count - 1;
while (count-- > 0) {
update(from);
*to-- = *from--;
}
}
static void update (oop * p){
__asm{
mov ecx, p
mov [ecx], 7
}
}
My question is: How to calculate in Assembly the correct address of element of the array T
in JVM.
In C++ it works very well but in Java? I know that the addressing memory mode of object in C++ is different from Java: http://www.javamex.com/tutorials/memory/object_memory_usage.shtml
Note: I did not used a CompressedOops
https://wikis.oracle.com/display/HotSpotInternals/CompressedOops