bugGNU Octave - Bugs: bug #55430, usejava starts the JVM if it...

 
 

bug #55430: usejava starts the JVM if it hadn't been initialized yet

Submitted by:  Carnë Draug <carandraug>
Submitted on:  Wed 09 Jan 2019 06:16:52 PM UTC  
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Thu 10 Jan 2019 10:28:33 AM UTC, comment #5:

On my (Windows) box:

GNU Octave, version 6.0.0
:
Octave was configured for "x86_64-w64-mingw32".
:

>> usejava ('jvm')
ans = 1
>>

... so at least that matches Matlab's user-visible behavior (comment #1).

I completely agree with Mike's observation about user expectation:
"it is safe to call a Java class if this returns true"
In that respect I cannot follow whay it would matter if the JVM is running, or not running but can be started, apart from linguistic details ("running" vs. "available"). Is there a use case example about when that matters?

But Carnë has a valid point in that Matlab can be called with "-nojvm", obviously in that case usejava('jvm') should return false.
Does Octave has a similar option? E.g., given some older bug report(s) that the JVM affects CPU flags this might be a useful option.

FTR, from the Matlab docs about the '-nojvm' flag:
... With nojvm, you cannot use the desktop, figures, or any tools that require Java® software.

Philip Nienhuis <philipnienhuis>
Project Member
Wed 09 Jan 2019 10:19:29 PM UTC, comment #4:

I think it's clear that if user code is calling usejava('jvm'), they expect that to mean the equivalent of "it is safe to call a Java class if this returns true".

If Octave's usejava('jvm') possibly returns false only because no other Java functions have been called yet, and might return true later, that seems needlessly incompatible with how a user would expect it to work. So I don't think the current behavior should be changed, only maybe the documentation.

Mike Miller <mtmiller>
Project Administrator
Wed 09 Jan 2019 07:57:45 PM UTC, comment #3:

Here's me trying to be more clear:

In Matlab, if the JVM is available then the JVM is running. So in Matlab, there's no difference between the JVM being available or running. This is only configured with the '-nojvm' flag.

In Octave, initialization of the JVM is delayed until needed. So in Octave, having the JVM feature available is different from having the JVM running. This is configured during build.

Matlab documentation for usejava says that it returns whether the JVM is running. But in Octave, usejava tries to returns whether the JVM is available which in Octave is a different thing.

In addition, usejava initialises the JVM. If the JVM was not running before, and one only wants to know whether the JVM was running, they can't. They can't because usejava will return whether the jvm was running after usejava tries to initialise and not if it was running before the call to usejava.

Carnë Draug <carandraug>
Project Member
Wed 09 Jan 2019 07:52:06 PM UTC, comment #2:

Yeah I think we should just update the documentation so that usejava('jvm') means the Java Virtual Machine is capable of being loaded.

Matlab's help contradicts themselves, where they say

> Use the following code snippet to terminate a script if MATLAB does not have access to JVM™ software.


Which means that usejava('jvm') really means that Matlab has access to the JVM, not whether it's running yet or not. I think in Matlab "JVM is running" and "JVM is available" are interchangeable.

Mike Miller <mtmiller>
Project Administrator
Wed 09 Jan 2019 07:41:58 PM UTC, comment #1:

Sorry Carnë, what you write is a bit ambiguous to me.
Do you mean to say that in Matlab usejava('jvm') does NOT start the JVM? or doe that apply to Octave?
Look here then:

Matlab r2019a prerelease, immediately after start:

>> usejava ('jvm')
ans =
  logical
   1

so Matlab has a JVM running right from the start. AFAIK Matlab's GUI is heavily based on Java so little wonder there.

Philip Nienhuis <philipnienhuis>
Project Member
Wed 09 Jan 2019 06:16:52 PM UTC, original submission:

The function usejava is meant to return whether a specific java feature is available. But in the specific case of 'usejava ("jvm")' the Matlab documentation says:

> Java Virtual Machine software (JVM) is running.


This is quite different. In the case of Octave, initialization of the JVM is delayed until required so I usejava should return false until that happens. And usejava should not initialise the JVM either.

Alternatively, we can say that Matlab documentation should not be interpreted literally in this case. We can say that in Matlab, having the JVM running is the same as having the JVM available because it's initialization happens either at startup or never and that "fixing" this would actually make things more complicated.

Anyway, here's a bug for discussion on whatever gets decided, for future reference.

Carnë Draug <carandraug>
Project Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by carandraug (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    No changes have been made to this item

    Back to the top


    Powered by Savane 3.4