native进程中调用jni接口中的信号处理问题(JVM in native process)

For XXX print stack issue, it is because the signal handling conflict between C++ process and JVM thread as below:

 

I provide solution base on the reference

 

http://publib.boulder.ibm.com/infocenter/realtime/v1r0/index.jsp?topic=%2Fcom.ibm.rt.doc.10%2Fuser%2Fnative_signals.html

 

I have copy the solution as following:

 

Linking a native code driver to the signal-chaining library

The Runtime Environment contains signal-chaining. Signal-chaining enables the JVM to interoperate more efficiently with native code that installs its own signal handlers.

Signal-chaining enables an application to link and load the shared library libjsig.so before the system libraries. The libjsig.so library ensures that calls such assignal(), sigset(), and sigaction() are intercepted so that their handlers do not replace the JVM's signal handlers. Instead, these calls save the new signal handlers, or "chain" them behind the handlers that are installed by the JVM. Later, when any of these signals are raised and found not to be targeted at the JVM, the preinstalled handlers are invoked.

If you install signal handlers that use sigaction() , some sa_flags are not observed when the JVM uses the signal. These are:

  • SA_NOCLDSTOP - This is always unset.
  • SA_NOCLDWAIT - This is always unset.
  • SA_RESTART - This is always set.

The libjsig.so library also hides JVM signal handlers from the application. Therefore, calls such as signal(), sigset(), and sigaction() that are made after the JVM has started no longer return a reference to the JVM's signal handler, but instead return any handler that was installed before JVM startup.

To use libjsig.so:

  • Link it with the application that creates or embeds a JVM:

gcc -L$JAVA_HOME/bin -ljsig -L$JAVA_HOME/bin/j9vm -ljvm java_application.c

or

  • Use the LD_PRELOAD environment variable:
  • export LD_PRELOAD=$JAVA_HOME/bin/libjsig.so; java_application (bash and ksh)
  •  

setenv LD_PRELOAD=$JAVA_HOME/bin/libjsig.so; java_application (csh)

The environment variable JAVA_HOME should be set to the location of the SDK, for example,/opt/ibm/java2-i386-50/.

To use libjsig.a:

  • Link it with the application that creates or embeds a JVM:
  • cc_r  <other compile/link parameter> -L/opt/ibm/java2-i386-50/jre/bin -ljsig

-L/opt/ibm/java2-i386-50/jre/bin/j9vm -ljvm java_application.c

Note: Use xlc_r or xlC_r in place of cc_r if that is how you normally invoke the compiler or linker.

 The solution works as following:

 

 So then it will solve the conflict.

 

Only change Makefile:

  

 1 eccf : $(TTDBCONN) $(TTLOCALCONN) $(POOLTTCLASS) $(RCRECORD) $(ECCF_OBJS)
 2 
 3                 $(CC) -o $(ECCF_SPA_FULL) $(ECCF_OBJS) $(TTDBCONN) $(TTLOCALCONN) $(POOLTTCLASS) $(RCRECORD) oss/$(OSS_VERSION)/lib/libosscag.a oss/$(OSS_VERSION)/lib/libasn1code.a $(LDFLAGS) $(FLAG64) -Bdynamic \
 4 
 5                                 -L$(AHE_HOME)/cc/lib/$(LIB_BITS) \
 6 
 7                                 -L$(AHE_HOME)/cc/lib \
 8 
 9                 -L$(AHE_HOME)/postgres/odbc64/lib/ -lodbc \
10 
11                                 -L$(CSLEE_HOME)/lib/$(LIB_BITS)/$(LIB_TYPE) \
12 
13                                 -L$(THIRD_PARTY_HOME)/Apache/lib$(LIB_BITS)/$(LIB_TYPE) \
14 
15                                 -L$(TT_HOME)/lib$(LIB_BITS) \
16 
17                                 -Lexpat/$(LIB_TYPE)/lib \
18 
19                                 -Lipdr/libs/$(LIB_TYPE) \
20 
21                                 -Lgnome/$(LIB_TYPE)/lib \
22 
23                                 $(LIB_DIR) \
24 
25                                 -ljsig \
26 
27                                 -ljvm \
28 
29                                 -lPINslee \
30 
31                                 -l$(LIB_TYPE)PINasnbill$(LIB_BITS) \
32 
33                                 -l$(LIB_TYPE)aspin \
34 
35                                 -l$(LIB_TYPE)spm2 \
36 
37                                -l$(LIB_TYPE)plat \
38 
39                                 -l$(LIB_TYPE)aspinplat \
40 
41                                 -l$(LIB_TYPE)ddmappmi$(LIB_BITS) \
42 
43                                 -l$(LIB_TYPE)ddmparser$(LIB_BITS)\
44 
45                                 -l$(LIB_TYPE)cdrsch$(LIB_BITS) \
46 
47                                 -ltten \
48 
49                                 -lttclasses \
50 
51                                 -lxerces-c \
52 
53                 -lthread \
54 
55                                 -lldap \
56 
57                                 -lIPDR \
58 
59                                 -lexpat \
60 
61                                 -lXDR \
62 
63                                 -lXML \
64 
65                                 -lUTILS \
66 
67                                 -lxml2 \
68 
69                                 -lxslt \
70 
71                                 -lpthread \
72 
73                                 -lm \
74 
75                                 $(LIBS)
76 
77  

 

posted @ 2014-03-19 14:52  IamRomi  阅读(675)  评论(1编辑  收藏  举报