Open lngex opened 4 months ago
Can you please give some more details, or even better, some code to reproduce this?
I personally have applications running for days and did not see any issue.
The program mainly calls "segmenter json" for word segmentation,after the word segmentation is completed, call "free memory" to release the memory.The program crash occurs when calling "segmenter json"
pub extern "C" fn segmenter_json(text: *const c_char) -> *mut c_char { { check_init(); } let c_str = unsafe { CStr::from_ptr(text) }; let text = c_str.to_str().unwrap(); let json_str: String; let jvm = Jvm::attach_thread().unwrap(); // 创建分词对象 let result = jvm.invoke_static("com.farseer.utils.IKUtil", "segmenterJson", &[InvocationArg::try_from(text).unwrap()]) .unwrap(); // 获取分词结果 json_str = jvm.to_rust(result).unwrap(); let c_string = CString::new(json_str); let x = c_string.unwrap().into_raw(); x }
pub extern "C" fn free_memory(text: *mut cchar) { unsafe { let = CString::from_raw(text); } }
Also attached is the jvm complete log and code.
Sorry, the system-generated stack snapshot was deleted and cannot be provided here.
[code link](http://124.221.251.108:9080/code)
[log link](http://124.221.251.108:9080/log)
The calling programs are written in php and they create a lot of jvm's. I'm not sure if it's for this reason
Creating many Jvm
s should not be a problem.
My guess is that you fall into some race condition while manipulating the *const c_char
input. Could it maybe freed while generating the InvocationArg
? InvocationArg
generation for &str
internally implies the creation of a CString
using cesu8
, so, I would propose to make sure for such issues.
In order to verify if the error happens indeed during the InvocationArg
generation, you could create it before calling the Jvm
:
let ia = InvocationArg::try_from(text).unwrap();
let result = jvm.invoke_static("com.farseer.utils.IKUtil",
"segmenterJson",
&[ia])
.unwrap();
Creating many
Jvm
s should not be a problem.My guess is that you fall into some race condition while manipulating the
*const c_char
input. Could it maybe freed while generating theInvocationArg
?InvocationArg
generation for&str
internally implies the creation of aCString
usingcesu8
, so, I would propose to make sure for such issues.In order to verify if the error happens indeed during the
InvocationArg
generation, you could create it before calling theJvm
:let ia = InvocationArg::try_from(text).unwrap(); let result = jvm.invoke_static("com.farseer.utils.IKUtil", "segmenterJson", &[ia]) .unwrap();
I'll give it a try.
@lngex, do you have anything new to share regarding this?