This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: very slow jni code callbacks


Herman ten Brugge wrote:
> I have a problem with jni code callbacks.
> I have attached some code that shows the problem.
> The result of this code is:
> 
> # results on fedora 11
> #  gcc/gcj 4.4.1
> #  kernel 2.6.30.5-43.fc11.x86_64
> #  openjdk fedora-29.b16.fc11-x86_64
> #
> #                       open jdk        gcj
> # no_jni                 1.48               7.46        (  5 times slower)
> # jni                   66.70           17140.00        (257 times slower)
> 
> So when not using jni in this case gcj is 5 times slower.
> I suspect the jit compiler does a good for this small sample.
> 
> The code with jni calls is however 257 timer slower. I really
> did not expect that. I also tried other java vm and they all
> have much better performance. So I expect a problem in the
> gcj library.
> 
> When I use oprofile I see at lot of calls to execute_cfa_program
> and _Unwind_IteratePhdrCallback.

I think this is a bug.  I've had a look at the code, and it's in
jni.cc: _Jv_JNI_CallAnyVoidMethodV

This calls _Jv_GetTypesFromSignature, which in turn iterates though
all the class loaders looking up the types of all the arguments.
But as far as I can see this is a pointless waste of time: the only
use of the type of each argument is to determine whether it's a
primitive type or not, and we could certainly have done that when
we created the jmethodID.  There is a field in the method struct called
ffi_arg_types, but I think it isn't used when calling C to Java via JNI.

Note that JNI calls to Java code will always be somewhat slower than
CNI since it goes though a libffi call, but this seems to me to be
crazy extreme.

I'm Cc:ing this to Tom Tromey, who wrote this code originally.

Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]