[Native:JNI] Stability, usage and maintenance of shared memory and mutex code

2011-08-27 Thread Ashwin Jayaprakash
Hi, I was browsing through the Tomcat Native source code and noticed the
Shared memory and Mutex Java classes.

So, I tried creating a quick prototype and to my pleasant surprise it worked
off the bat on 64 bit Windows 7 . I tried the jni/Shm.java and
jni/Global.java classes to share memory between 2 processes coordinated by a
mutex.

I'm writing to understand:

   1. Why the jni/Shm.java and jni/Global.java are not used in the Tomcat
   codebase
   2. Have they been superseded by something else like NIO Mmap files or
   something?
   3. Is this code going to be deprecated or go out of maintenance since it
   is not used? I do not even see test cases for these except for
   jni/Address.java and jni/Socket.java
   4. Does this work well on Linux too?
   5. Are there any performance considerations, gotchas etc - considering
   that this is an internal module with "light" documentation?


For the curious, here is the test code I wrote (CC BY-SA)
https://gist.github.com/2c3acac03cf954f68001. I would be overjoyed if this
was incorporated into the unit tests for Tomcat Native.

Thanks,
Ashwin Jayaprakash (http://www.ashwinjayaprakash.com)


[Native:JNI] jni.Global vs jni.Lock and fatal error at childInit(..) on Linux

2011-08-30 Thread Ashwin Jayaprakash
Hi,
I tried using the jni.Global class to do interprocess locking between 2
processes. I wasn't sure whether to use Global or the Lock class. Both seem
to have identical APIs.

It worked alright on Windows 7. The 2 communicating processes weren't even
parent-child and it still worked.

However, on Linux (Ubuntu 64bit Intel) the child process crashes at
Global.childInit(..) method. Even when the second process was started by
hand (not as a child process of the first using ProcessBuilder) it crashed.
The first few lines of the dump shown below.

The code and a related question I asked a few days ago on the same
forum: [Native:JNI]
Stability, usage and maintenance of shared memory and mutex
code

Questions:

   1. What is the difference between Global and Lock?
   2. How do you use either one of them for inter-process locking - esp. on
   Linux?


JVM dump:

---  T H R E A D  ---

Current thread (0x08492000):  JavaThread "main" [_thread_in_native, id=9706,
stack(0xb6d1,0xb6d61000)]

siginfo:si_signo=SIGSEGV: si_errno=0, si_code=1 (SEGV_MAPERR),
si_addr=0x

Registers:
EAX=0x8ee065fc, EBX=0xb4428ff4, ECX=0x, EDX=0x
ESP=0xb6d5fedc, EBP=0xb6d5fef8, ESI=0x0855b4a8, EDI=0x08492118
EIP=0x, CR2=0x, EFLAGS=0x00010282

Top of Stack: (sp=0xb6d5fedc)
0xb6d5fedc:   b4415a76 8ee065fc 08559450 0855b4a8
0xb6d5feec:   b4415a4f 0855b4a8 08551f60 b6d5ff28
0xb6d5fefc:   b4415d90 8ee065fc 0855b4a8 08559450
0xb6d5ff0c:   08492118 b6d5ff78 b780b230 08559450
0xb6d5ff1c:   b4415d60 b6d5ff5c b45f3ff4 b6d5ff78
0xb6d5ff2c:   b45ee1fe b6d5ff5c 0855b4a8 08559450
0xb6d5ff3c:   b6d5ffc4 b6fa4b8d 08492000 084928b0
0xb6d5ff4c:   08559450 084928b4 084928b4 fffe

Instructions: (pc=0x)
0xfff0:

Stack: [0xb6d1,0xb6d61000],  sp=0xb6d5fedc,  free space=13fb6d5f860k
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.apache.tomcat.jni.Global.childInit(Ljava/lang/String;J)J+0
j  shm.ShmReader.test()V+48
j  shm.ShmReader.main([Ljava/lang/String;)V+7
v  ~StubRoutines::call_stub


Thanks,
Ashwin.