What is the exact meaning / purpose of the J and R flags in jshell?

后端 未结 2 1324
南笙
南笙 2021-01-05 08:19

From the help information:

-J              Pass  directly to the runtime system.
                      Use one -J for each runtime fl         


        
2条回答
  •  太阳男子
    2021-01-05 08:31

    As I understand it, JShell has 3 main 'places' to execute code:

    • In the current process (see DirectExecutionControl)

    • In the same JVM as the JShell client (see LocalExecutionControl)

    • On the remote agent (see JdiDefaultExecutionControl)

    Using jshell tool, we have no current process before launch, so we have only two options - use one JVM (locally), or use two JVMs - one for JShell client (locally) and another for the execution engine (possibly remotely).

    The interesting thing is, JShell always launch two JVMs by default, as the hard-coded --execution key is "failover:0(jdi:hostname(" + loopback + ")),1(jdi:launch(true)), 2(jdi)" (see JShell class source code).

    Closer to the point. I've made a couple of experiments with -verbose option and checked JVM options in runtime with ManagementFactory.getRuntimeMXBean().getInputArguments().

    • jshell -J-verbose command

      Printed -verbose output in the console.

      No -verbose option in the input arguments: [-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:63305]

    • jshell -R-verbose command

      No -verbose output in the console.

      Printed -verbose option in the input arguments: [-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:63339, -verbose]

    • jshell --execution="local" -J-verbose command

      Printed -verbose output in the console.

      Printed -verbose option in the input arguments: [-Dapplication.home=C:\Program Files\Java\jdk-9, -Xms8m, -verbose, -Djdk.module.main=jdk.jshell]

    • jshell --execution="local" -R-verbose

      No -verbose output in the console.

      No -verbose option in the input arguments: [-Dapplication.home=C:\Program Files\Java\jdk-9, -Xms8m, -Djdk.module.main=jdk.jshell]

    TL;DR

    Remote execution (default case, execution over JDI)

    -J passes option to the JShell client JVM

    -R passes option to the execution engine JVM

    Local execution (--execution="local")

    -J passes option to the only present JVM

    -R does nothing

提交回复
热议问题