Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

extreme slowdown calling Java from native



I've been experimenting with calling native code from Java without JNI (and providing java callbacks to native code). Currently this system is working on a number of platforms, including OSX (see jna.dev.java.net).

I haven't tested on OSX/x86, but the ppc version exhibits severe delays when native code calls back to java code. Likely this is due to my extreme ignorance with PPC assembly and memory modes, but I was wondering if someone with some PPC experience might point out some avenues for further investigation.

For the callbacks, I have an asm template that gets copied into some malloc'd memory, with some data addresses filled in on the fly, something like this:

  asm("li r3,0");
  asm("\n.set VM_OFFSET,.-_callback_asm_template");
  asm("ori r3,r3,0");
  asm("oris r3,r3,0");
  asm("li r4,0");
  asm("\n.set CB_OFFSET,.-_callback_asm_template");

The labels are used to figure out the appropriate offset into the malloc'd memory to set data addresses that get customized for each callback stub. PPC asm loads 16 bits at a time, so a 32-bit address is split across two insns.

The data written is the address of a structure with a callback dispatch function address, callback configuration data, and a pointer to the VM from which a JNIEnv* can be obtained. The callback stub sets up the stack, then calls the callback dispatch function, which is C code that sets things up to call back into java.

What I see when running my callback tests on PPC is that the callbacks take a really long time, on the order of seconds. My first guess is that the difference in memory space from the malloc'd memory from normal code space is causing some sort of major context switch as the CPU context has to go from code->data->code and back after the call; if that's the case, I'm not sure how I could avoid it.

Thanks in advance for any feedback,

Timothy Wall
http://abbot.sf.net


_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.