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

本文介绍了解决C++应用程序与JVM之间信号处理冲突的方法,通过使用信号链接库libjsig.so来确保两者信号处理的兼容性,并提供了具体的链接方式及环境变量设置。同时给出了Makefile修改示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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  

 

转载于:https://www.cnblogs.com/iamromi/p/3611426.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值