Hey folks,
I was helping a colleague last week who is working on a project that involves calling user-provided Java functions from a native program. The Java functions themselves are typically quite short (on the order of 10s or 100s of cycles), so the JNI overhead actually represents a significant amount of time relative to the execution itself.
We were able to get about a 2.5x speedup from where we started by using CallNonVirtualObjectMethodA rather than CallObjectMethod(), and by using Unsafe on a pre-allocated buffer to pass data back and forth (instead of having call arguments). But, we still see a fair amount of time spent in the JNI code according to the gperftools CPU profiler.
Any further tips and tricks to minimize the overhead as much as possible? Would creating a new class on the fly with a static function be appreciably faster compared to non-virtual dispatch on an instance method?
-Todd