Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JNI MMX and Java long arithmetic

843829Nov 1 2006 — edited Nov 6 2006
I am having trouble with a JNI call to a C program which contains assembler which uses an MMX operation as follows:

static inline int diffPixels(int rgb1, int rgb2) {
register int temp;

__asm__ __volatile__ (
"movd %1, %%mm1\n\t"
"movd %2, %%mm2\n\t"
"psadbw %%mm1, %%mm2\n\t"
"movd %%mm2, %0\n\t"
: "=r" (temp)
: "r" (rgb1), "r" (rgb2)
: "mm1", "mm2", "cc"
);
return temp;
}

After the JNI call returns, the first Java long arithmetic fails. I believe the failure is that when a method on a Java object returns a long the result is 0x8000000000000000 rather than the correct value.

To use pure Java means my response to a user action is 9 seconds rather than 3 seconds with the JNI call which is why I want to persist with it. At present I am doing an arbitrary long multiply after the JNI call to "fix" long arithmetic but I am afraid this won't work if there is a context switch to another java thread in the middle of the JNI call.

The test environment is a 3 Gigahertz Pentium 4 running Linux kernel 2.6.9 and Java version 1.4.2_06-b03.

Can anyone explain this behaviour ? It took me days to isolate the problem.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 4 2006
Added on Nov 1 2006
2 comments
174 views