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

 
 

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

Submitter:  Carnë Draug <carandraug>
Submitted:  Wed 09 Jan 2019 06:16:52 PM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  3 - Low Item Group:  Matlab Compatibility
Status:  Wont Fix Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sun 11 Aug 2019 11:17:31 PM UTC, comment #7: 


> IMHO the current behavior is right, we can just fix the function description to make that clear if it's not clear now.


The current description in Octave matches what Octave does. The issue was only that it differs from what Matlab does and from what Matlab says it does. But if we are not changing behaviour, then we don't need to change the documentation.

Carnë Draug <carandraug>
Group Member
Sun 11 Aug 2019 09:56:19 PM UTC, comment #6: 

No movement on this in a few months, I'm going to recategorize this as documentation.

The fact that Octave does lazy initialization of the JVM only when it is needed is an implementation detail that the user doesn't really need to know. The 'usejava("jvm")' flag is meant to tell the user that the JVM is available for them to use. IMHO the current behavior is right, we can just fix the function description to make that clear if it's not clear now.

Mike Miller <mtmiller>
Group Member
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>
Group 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>
Group Member
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>
Group 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>
Group Member
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>
Group 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>
Group 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 rik5 (Updated the item)
  • -email is unavailable- added by carandraug (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-09-20 rik5 Item GroupDocumentation Matlab Compatibility
        StatusNone Wont Fix
        Open/ClosedOpen Closed
    2019-08-11 mtmiller Severity3 - Normal 2 - Minor
        Priority5 - Normal 3 - Low
        Item GroupMatlab Compatibility Documentation

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code