imagej-loader / dlopen args

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

imagej-loader / dlopen args

Lee Kamentsky
Hi dscho,
I'm programming "monkey see, monkey do" style. I have very little idea what I'm doing, trying to replicate the logic for mac loading dylibs in imagej-loader.

I've gotten pretty far, but at the end, I'm seeing the error, "JavaNativeFoundation: GetGlobalVM: JNI_GetCreatedJavaVMs() failed to get any VM" when I start an AWT app.

I am guessing that this is why you dlopened libjli here. I do the same, but (so far) with Python's ctypes.CDLL. That doesn't let you specify RTLD_LAZY as a dlopen mode. So, I think that's the big difference between how you do things and how I do them. My first question is whether RTLD_LAZY is needed as the mode. My second question is why you needed to load libjli.dylib in the first place and, if you might grant me a third wish, my third question is whether you've seen this error before.

Thanks in advance, Mr. Wizard.

--Lee

_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel
Reply | Threaded
Open this post in threaded view
|

Re: imagej-loader / dlopen args

dscho
Administrator
Hi Lee,

On 2015-03-18 14:47, Lee Kamentsky wrote:

> I'm programming "monkey see, monkey do" style. I have very little idea
> what
> I'm doing, trying to replicate the logic for mac loading dylibs in
> imagej-loader.
>
> I've gotten pretty far, but at the end, I'm seeing the error,
> "JavaNativeFoundation: GetGlobalVM: JNI_GetCreatedJavaVMs() failed to
> get
> any VM" when I start an AWT app.

Do you expect a JVM to be running already? If not, you should [create
one](https://github.com/imagej/imagej-launcher/blob/3e061521a/src/main/c/ImageJ.c#L307-L322).

> I am guessing that this is why you dlopened libjli here
> <https://github.com/imagej/imagej-launcher/blob/master/src/main/c/ImageJ.c#L264>.

Heh, I have to admit that I did not remember at all why I did that.
Happily, even I learned to write kick-ass commit messages, and I also
learned the awesomeness of the `Blame` button on GitHub:
https://github.com/imagej/imagej-launcher/blame/master/src/main/c/ImageJ.c#L264 
(I vaguely remember writing that commit message after spending something
between twenty and thirty super-focused hours on hunting down this bug,
that was not really fun, that one hunt).

> I do the same, but (so far) with Python's ctypes.CDLL. That doesn't let
> you
> specify RTLD_LAZY as a dlopen mode. So, I think that's the big
> difference
> between how you do things and how I do them. My first question is
> whether
> RTLD_LAZY is needed as the mode. My second question is why you needed
> to
> load libjli.dylib in the first place and, if you might grant me a third
> wish, my third question is whether you've seen this error before.

The JLI library is only needed for forward compatibility, so that MacOSX
does not annoy the user by a "Do you want to install Java 6?" popup.

And yes, I have seen an error like that before, but only when trying to
attach to a running JVM from within Matlab (Matlab's very own GUI is
written in Java... so there is already a JVM running in a Matlab
instance although it is a bit tricky to get at it under certain
circumstances, but it is impossible to run two Oracle JVMs in the same
process in any case).

> Thanks in advance, Mr. Wizard.

Sorry, oh ye mighty Python God, I fear my input was not really helpful
to your cause. But maybe you have a project for me to clone, with
instructions that might let this poor Python pilgrim reproduce the
issue?

Ciao,
Dscho

_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel
Reply | Threaded
Open this post in threaded view
|

Re: imagej-loader / dlopen args

Lee Kamentsky
Thanks,

On Wed, Mar 18, 2015 at 4:32 PM, Johannes Schindelin <[hidden email]> wrote:
Hi Lee,

On 2015-03-18 14:47, Lee Kamentsky wrote:

I'm programming "monkey see, monkey do" style. I have very little idea what
I'm doing, trying to replicate the logic for mac loading dylibs in
imagej-loader.

I've gotten pretty far, but at the end, I'm seeing the error,
"JavaNativeFoundation: GetGlobalVM: JNI_GetCreatedJavaVMs() failed to get
any VM" when I start an AWT app.

Do you expect a JVM to be running already? If not, you should [create one](https://github.com/imagej/imagej-launcher/blob/3e061521a/src/main/c/ImageJ.c#L307-L322).

I am guessing that this is why you dlopened libjli here
<https://github.com/imagej/imagej-launcher/blob/master/src/main/c/ImageJ.c#L264>.

Heh, I have to admit that I did not remember at all why I did that. Happily, even I learned to write kick-ass commit messages, and I also learned the awesomeness of the `Blame` button on GitHub: https://github.com/imagej/imagej-launcher/blame/master/src/main/c/ImageJ.c#L264 (I vaguely remember writing that commit message after spending something between twenty and thirty super-focused hours on hunting down this bug, that was not really fun, that one hunt).

I do the same, but (so far) with Python's ctypes.CDLL. That doesn't let you
specify RTLD_LAZY as a dlopen mode. So, I think that's the big difference
between how you do things and how I do them. My first question is whether
RTLD_LAZY is needed as the mode. My second question is why you needed to
load libjli.dylib in the first place and, if you might grant me a third
wish, my third question is whether you've seen this error before.

The JLI library is only needed for forward compatibility, so that MacOSX does not annoy the user by a "Do you want to install Java 6?" popup.

And yes, I have seen an error like that before, but only when trying to attach to a running JVM from within Matlab (Matlab's very own GUI is written in Java... so there is already a JVM running in a Matlab instance although it is a bit tricky to get at it under certain circumstances, but it is impossible to run two Oracle JVMs in the same process in any case).

Thanks in advance, Mr. Wizard.

Sorry, oh ye mighty Python God, I fear my input was not really helpful to your cause. But maybe you have a project for me to clone, with instructions that might let this poor Python pilgrim reproduce the issue?

Ciao,
Dscho


_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel
Reply | Threaded
Open this post in threaded view
|

Re: imagej-loader / dlopen args

Lee Kamentsky
In reply to this post by dscho
OOps hit send too fast. But thanks.,

On Wed, Mar 18, 2015 at 4:32 PM, Johannes Schindelin <[hidden email]> wrote:
Hi Lee,

On 2015-03-18 14:47, Lee Kamentsky wrote:

I'm programming "monkey see, monkey do" style. I have very little idea what
I'm doing, trying to replicate the logic for mac loading dylibs in
imagej-loader.

I've gotten pretty far, but at the end, I'm seeing the error,
"JavaNativeFoundation: GetGlobalVM: JNI_GetCreatedJavaVMs() failed to get
any VM" when I start an AWT app.

Do you expect a JVM to be running already? If not, you should [create one](https://github.com/imagej/imagej-launcher/blob/3e061521a/src/main/c/ImageJ.c#L307-L322).

Nope - this happens when I am shutting down the JVM after starting AWT. 
 But maybe you have a project for me to clone, with instructions that might let this poor Python pilgrim reproduce the issue?

The head of the master branch of http://github.com/CellProfiler/python-javabridge and running "python demo/demo_uicallback.py" should demostrate the problem when you quit. If it doesn't, I fixed it.

Ciao,
Dscho


_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel