Java/JNI calls from fibers/stackful coroutine fails.

61 views
Skip to first unread message

Guus Waals

unread,
Mar 20, 2023, 11:25:51 AM3/20/23
to android-ndk
Hey, I tried posting this about 2 weeks ago but my post never showed up.

My application uses fibers/stackful coroutines through boost context but whenever any Java code is called from C++ within a different stack/fiber the ART will abort the application with an error about invalid references.

I've tried the same with a different library (marl) but it gives the same result.

Looking at various solutions I've tried various AttachCurrentThread solutions but none of them made any difference, and also technically I'm still on the main thread, just that the stack is in a different location.

Does anyone have any ideas on how to make this work, maybe some details about what kind of stack layout JNI expects & how I can make it "see" the java stack.

Thanks.

enh

unread,
Mar 20, 2023, 11:28:27 AM3/20/23
to andro...@googlegroups.com
On Mon, Mar 20, 2023 at 8:25 AM Guus Waals <gu...@fragcolor.xyz> wrote:
Hey, I tried posting this about 2 weeks ago but my post never showed up.

My application uses fibers/stackful coroutines through boost context but whenever any Java code is called from C++ within a different stack/fiber the ART will abort the application with an error about invalid references.

I've tried the same with a different library (marl) but it gives the same result.

Looking at various solutions I've tried various AttachCurrentThread solutions but none of them made any difference, and also technically I'm still on the main thread, just that the stack is in a different location.

i haven't worked on ART for a decade, but i suspect that won't work because you'll end up on the "this thread is already attached" fast path, making AttachCurrentThread a no-op.

i suspect you'd have to _detach_ the previous fiber first, but that's going to be a nightmare and unlikely to be something you can get to work. you're probably going to have a real thread designated as the JNI thread and not make calls from fibers directly.
 
Does anyone have any ideas on how to make this work, maybe some details about what kind of stack layout JNI expects & how I can make it "see" the java stack.

Thanks.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/571b28b9-1373-48d7-a736-8a4f7f058ef2n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages