* Segfault JvCreateJavaVM when doing dlopen, dlclose, dlopen
@ 2009-03-12 10:31 Matthijs van de Water
2009-03-12 10:46 ` Andrew Haley
0 siblings, 1 reply; 3+ messages in thread
From: Matthijs van de Water @ 2009-03-12 10:31 UTC (permalink / raw)
To: java
Hello,
I'm having a problem with a Java .so (compiled with gcj-4.3 for ARM)
that I use in a C++ program as a dynamically loadable plugin.
The plugin works fine as long as I keep it loaded into memory. Because
I'm working on an embedded system, I'd like to be able to unload the
plugin when it's not in use to save memory.
I'm trying the following:
1. dlopen() the .so, we call an init function in this .so plugin which
uses JvCreateJaveVM() and JvAttatchCurrentThread()
2. Call some functions in the .so plugin. These functions use Java objects.
3. Unref all Java objects and call unload function in the .so that
calls JvDetachCurrentThread()
4. dlclose() the .so
5. dlopen() the .so again (as step 1)
6. The code crashes with a SEGV when making calls into Java code (as step 2)
I've not been able to properly pinpoint the crash yet, but it seems to
crash outside my own code (in libgcj somewhere).
Before I spend hours of debugging, could one of you at least tell me
if what I'm trying to do should be working?
The one 'strange' thing I'm doing is that I've statically compiled a
PIC version of libgcj.a into the .so plugin to avoid the huge
libgcj.so on my embedded system. This has been working without
problems so-far, however.
--
Regards,
Matthijs van de Water
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Segfault JvCreateJavaVM when doing dlopen, dlclose, dlopen
2009-03-12 10:31 Segfault JvCreateJavaVM when doing dlopen, dlclose, dlopen Matthijs van de Water
@ 2009-03-12 10:46 ` Andrew Haley
2009-03-12 18:03 ` Boehm, Hans
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Haley @ 2009-03-12 10:46 UTC (permalink / raw)
To: Matthijs van de Water; +Cc: java
Matthijs van de Water wrote:
> I'm having a problem with a Java .so (compiled with gcj-4.3 for ARM)
> that I use in a C++ program as a dynamically loadable plugin.
> The plugin works fine as long as I keep it loaded into memory. Because
> I'm working on an embedded system, I'd like to be able to unload the
> plugin when it's not in use to save memory.
>
> I'm trying the following:
>
> 1. dlopen() the .so, we call an init function in this .so plugin which
> uses JvCreateJaveVM() and JvAttatchCurrentThread()
> 2. Call some functions in the .so plugin. These functions use Java objects.
> 3. Unref all Java objects and call unload function in the .so that
> calls JvDetachCurrentThread()
> 4. dlclose() the .so
> 5. dlopen() the .so again (as step 1)
> 6. The code crashes with a SEGV when making calls into Java code (as step 2)
>
> I've not been able to properly pinpoint the crash yet, but it seems to
> crash outside my own code (in libgcj somewhere).
> Before I spend hours of debugging, could one of you at least tell me
> if what I'm trying to do should be working?
>
> The one 'strange' thing I'm doing is that I've statically compiled a
> PIC version of libgcj.a into the .so plugin to avoid the huge
> libgcj.so on my embedded system. This has been working without
> problems so-far, however.
You're in unknown territory here. What you're trying to do is pretty
hairy, and I have no way to know what the problem you're experiencing is
without debugging.
It would help if you could produce a test case that duplicates your problem.
Andrew.
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: Segfault JvCreateJavaVM when doing dlopen, dlclose, dlopen
2009-03-12 10:46 ` Andrew Haley
@ 2009-03-12 18:03 ` Boehm, Hans
0 siblings, 0 replies; 3+ messages in thread
From: Boehm, Hans @ 2009-03-12 18:03 UTC (permalink / raw)
To: Andrew Haley, Matthijs van de Water; +Cc: java
> From: Andrew Haley
>
> Matthijs van de Water wrote:
>
> > I'm having a problem with a Java .so (compiled with gcj-4.3
> for ARM)
> > that I use in a C++ program as a dynamically loadable plugin.
> > The plugin works fine as long as I keep it loaded into
> memory. Because
> > I'm working on an embedded system, I'd like to be able to
> unload the
> > plugin when it's not in use to save memory.
> >
> > I'm trying the following:
> >
> > 1. dlopen() the .so, we call an init function in this .so
> plugin which
> > uses JvCreateJaveVM() and JvAttatchCurrentThread() 2. Call some
> > functions in the .so plugin. These functions use Java objects.
> > 3. Unref all Java objects and call unload function in the .so that
> > calls JvDetachCurrentThread() 4. dlclose() the .so 5.
> dlopen() the .so
> > again (as step 1) 6. The code crashes with a SEGV when making calls
> > into Java code (as step 2)
> >
> > I've not been able to properly pinpoint the crash yet, but
> it seems to
> > crash outside my own code (in libgcj somewhere).
> > Before I spend hours of debugging, could one of you at
> least tell me
> > if what I'm trying to do should be working?
> >
> > The one 'strange' thing I'm doing is that I've statically
> compiled a
> > PIC version of libgcj.a into the .so plugin to avoid the huge
> > libgcj.so on my embedded system. This has been working without
> > problems so-far, however.
>
> You're in unknown territory here. What you're trying to do
> is pretty hairy, and I have no way to know what the problem
> you're experiencing is without debugging.
>
> It would help if you could produce a test case that
> duplicates your problem.
>
> Andrew.
>
I'd immediately worry about several possible problems:
- The runtime presumably creates additional threads that are at least in danger of touching memory that will go away with dlclose. The thread performing finalization immediately comes to mind. If you enable parallel GC, the other GC threads will have the same issue.
- The garbage collector is, in general, not prepared to deal with dlclose(). But I can't immediately think of anything that should go wrong in your scenario, so long as you make sure that no pieces of the collector are still running when you unload the collector. If you're performing a dlclose() but keeping the collector running, there's a problem that a garbage collection may be in progress and tracing static data associated with the library you're about to close. But if you're unloading the collector itself, and parallel GC is disabled, I'm not sure there should be an issue.
Hans
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-03-12 18:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-12 10:31 Segfault JvCreateJavaVM when doing dlopen, dlclose, dlopen Matthijs van de Water
2009-03-12 10:46 ` Andrew Haley
2009-03-12 18:03 ` Boehm, Hans
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).