I tried to add a native java method in Openjdk 7; I built the Openjdk 7 over windows XP using Microsoft VS2010.
Before adding the method in Openjdk I tried it in Microsoft VS2010 as follow:
The code of my method is:
void test (obj* from, int count){ __asm{ mov esi, from ; mov ecx, count ; lo: cmp ecx, 0; jl doni; add dword ptr [esi + ecx * 8], 10 sub ecx,1 jmp lo; doni: ; } }
Where obj* is an array of objects
obj.cpp
#include "stdafx.h" #include "obj.hpp" #include <iostream> using namespace std; obj:: obj(int x, int y) { this->x =x; this->y =y; } obj:: obj (){} int obj::getX(){return x;} int obj::getY(){return y;}
obj.hpp
#include <iostream> using namespace std; class obj { public: obj(); obj (int x, int y); int getX(); int getY(); private: int x,y; };
When I execute this procedure in Microsoft VS2010 it works very well.
For example: we have an array of object obj* T :
(1,1) (2,2) (3,3) after the call of test (T,2) the result will be:
(2,1) (3,2) (4,3)
The problem:
When I add this procedure in openJDK7 “openjdk\hotspot\src\os_cpu\windows_x86\vm\ copy_windows_x86.inline.hpp” with the following code: (oop is an ordinary object in JVM)
I call this procedure from:void test (oop* from, int count){ __asm{ mov esi, from ; mov ecx, count ; lo: cmp ecx, 0; jl doni; add dword ptr [esi + ecx * 8], 10 sub ecx,1 jmp lo; doni: ; } }
“openjdk\hotspot\src\share\vm\oops\objArrayKlass.c pp
void objArrayKlass::test1(arrayOop s,int src_pos int length, TRAPS) { oop* src = objArrayOop(s)->obj_at_addr<oop>(src_pos); Copy::test2(src,length); }
It does not work; the problem is the mode addressing of the object in the heap of JVM.
The size of object in C++ or Microsoft VS2010 is not the same as the size of Java object.
I want of change the ligne :
add dword ptr [esi + ecx * 8], 10
to be able to get the right address of object in memory and change it
I note that when a use an array of primitive type it works very well in openJdk.
For example, an array of integer in
“openjdk\hotspot\src\share\vm\oops\typeArrayKlass. cpp”
void typeArrayKlass::test1(arrayOop s, int src_pos, int length, TRAPS) { int l2es = log2_element_size(); int ihs = array_header_in_bytes() / wordSize; char* src = (char*) ((oop*)s + ihs) + ((size_t)src_pos << l2es); Copy::test2((jint*)src,(size_t)length << l2es); }