Performance / JShell lightweight

Robert Scholte rfscholte at apache.org
Tue Aug 15 18:34:13 UTC 2017


So yes, I end my script with /exit

When I run "jshell --execution local myscript.jsh" the script is just a  
startup script, the shell is still initialized, even though I end my  
script with /exit

Only because of the relatively long time to execute this script I am  
looking for a faster solution.
One thing that comes to my mind is something like "jshell --execution  
batch myscript.jsh", which will never enter the shell, but simply executes  
the script and stops.
This assumes that the initialization of the shell itself is also part of  
the time penalty.

I still like it that JShell gives me quite a nice way to execute Java 9  
code while I'm actually running on an older JRE.

thanks,
Robert

On Mon, 14 Aug 2017 23:27:05 +0200, Robert Field <robert.field at oracle.com>  
wrote:

> Yes, most of the time is spent in launching/setting-up the remote VM.
>
> You can get local execution with:
>
>      jshell --execution local
>
> This has downsides, for example if the executed code crashes/exits, so  
> does the shell.
>
> This is kinda documented in:
>
>      jshell -X
>
> and the SPI/API:
>
> http://download.java.net/java/jdk9/docs/api/jdk/jshell/spi/package-summary.html
> http://download.java.net/java/jdk9/docs/api/jdk/jshell/execution/package-summary.html
>
> As to exiting a script, in general, simply use the "exit" command.
>
> -Robert
>
> On 08/14/17 13:33, Remi Forax wrote:
>> Hi Robert,
>>
>> It's due to the fact that by default JShell starts a new VM (the remote  
>> VM) that will execute the code,
>> if you just want to run the code, i think there is a way to run the  
>> script inside the same VM.
>>
>> I will let the other Robert (Field) or anyone on this list explain how  
>> to do this,
>> i'm also interested by the answer (and the auto-exit at the end).
>>
>> cheers,
>> Rémi
>>
>> ----- Mail original -----
>>> De: "Robert Scholte" <rfscholte at apache.org>
>>> À: kulla-dev at openjdk.java.net
>>> Envoyé: Lundi 14 Août 2017 22:24:25
>>> Objet: Performance / JShell lightweight
>>> Hi,
>>>
>>> I've started a library which has the ability to divide a set of jars  
>>> and
>>> output directories over the classpath and modulepath. In order to get  
>>> the
>>> modulename it calls the Java 9 code for retrieving that name, i.e. via
>>> ModuleFinder.
>>> In case the library runs on Java 9, it can call the ModuleFinder  
>>> directly.
>>> But in case the library runs on Java 7 or Java 8, it requires a  
>>> reference
>>> to the Java 9 home.
>>> With JShell it has become very easy to execute this code, otherwise I  
>>> need
>>> to have an executable-jar at runtime, put is somewhere where I can  
>>> call it.
>>>
>>> However, this call to JShell takes several seconds to resolve, which  
>>> feels
>>> quite long. I'm looking for a way to reduce this time.
>>>
>>> I'm not interested in interaction with JShell, only interested in the
>>> output. (in the end it is almost as simple as a main method with
>>> System.out.println("Hello World"); )
>>>
>>> If the startup overhead is caused by building up the shell, can there  
>>> be
>>> an option introduced to just execute code without interactive shell  
>>> (and
>>> auto-exit at the end)?
>>>
>>> thanks,
>>> Robert


More information about the kulla-dev mailing list