All Projects → cinquin → attaching_jshell

cinquin / attaching_jshell

Licence: other
Attach Java 9's JShell to already-running virtual machine

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to attaching jshell

django-admin-shell
Django/Python shell for django admin site.
Stars: ✭ 62 (+129.63%)
Mutual labels:  console
manakin
🐦 Prime colors for your Node.js console — quick & safe.
Stars: ✭ 29 (+7.41%)
Mutual labels:  console
functional-reactive-lib
A core java lib for the functional reactive coding ... JDK only
Stars: ✭ 25 (-7.41%)
Mutual labels:  java-9
java-sheets
☕ Run Java Snippets in your Browser
Stars: ✭ 19 (-29.63%)
Mutual labels:  jshell
paper-terminal
Print Markdown to a paper in your terminal
Stars: ✭ 33 (+22.22%)
Mutual labels:  console
tinydownloader
a tiny downloader with console panel.
Stars: ✭ 80 (+196.3%)
Mutual labels:  console
console-subscriber
Subscribe to the browser's console output.
Stars: ✭ 14 (-48.15%)
Mutual labels:  console
snax86
A snake game written in x86 Assembly language for windows console
Stars: ✭ 21 (-22.22%)
Mutual labels:  console
concolor
Colouring template strings using tags with annotations 🎨
Stars: ✭ 35 (+29.63%)
Mutual labels:  console
xontrib-prompt-bar
The bar prompt for xonsh shell with customizable sections and Starship support.
Stars: ✭ 27 (+0%)
Mutual labels:  console
shiba
Display a random Shiba from your terminal whenever you feel the need to. Because why not?
Stars: ✭ 16 (-40.74%)
Mutual labels:  console
webpack-log
A logger for the Webpack ecosystem
Stars: ✭ 18 (-33.33%)
Mutual labels:  console
portera
Remote logs
Stars: ✭ 22 (-18.52%)
Mutual labels:  console
spinnies
Node.js module to create and manage multiple spinners in command-line interface programs
Stars: ✭ 111 (+311.11%)
Mutual labels:  console
ansiart2utf8
Processes legacy BBS-style ANSI art (ACiDDraw, PabloDraw, etc.) to UTF-8. Escape codes and line endings are processed for terminal friendliness.
Stars: ✭ 32 (+18.52%)
Mutual labels:  console
tinker-zero
Bridge laravel/tinker for your laravel-zero applications
Stars: ✭ 39 (+44.44%)
Mutual labels:  console
qbittorrentui
text user interface for qbittorrent
Stars: ✭ 19 (-29.63%)
Mutual labels:  console
console.history
📜 Store all javascript console logs in console.history
Stars: ✭ 30 (+11.11%)
Mutual labels:  console
console-logging
Better, prettier commandline logging for Python--with colors! 👻
Stars: ✭ 111 (+311.11%)
Mutual labels:  console
nim-dashing
Terminal dashboards for Nim
Stars: ✭ 105 (+288.89%)
Mutual labels:  console

Attaching jshell

JShell is a very useful new tool in JDK 9 that allows for interactive use of Java in a "read-eval-print loop". It is obvious that JShell would be particularly well suited for interactions with live JVMs, to examine their behavior in real time or to leverage their resources (e.g. if they have expensive objects already loaded, or if they run on powerful remote machines on which it is not practical to launch a JShell instance). Attaching to live JVMs would also provide an indirect way of populating objects in the JShell environment (a feature that has been requested). Unfortunately the current implementation of JShell does not give the option to connect to an already-running JVM (it starts a new JVM on the local host), although that may change in the future.

This project provides a JShell execution engine that can attach to any already-running JVM, as long as that JVM has been started appropriately.

Example usage

  • Start the target JVM with -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=XXXhostname:XXXport (update XXXhostname and XXXport as appropriate) and call new uk.org.cinquin.attaching_jshell.ExistingVMRemoteExecutionControl() from that JVM prior to using JShell

  • call JShell as follows: java -cp lib/attaching_jshell.jar jdk.internal.jshell.tool.JShellToolProvider --execution "attachToExistingVM:hostname(XXXhostname),port(XXXport)" using the same values of XXXhostname and XXXport as above

A simple way of making objects accessible to JShell is to have static fields point at them (see example in ExistingVMRemoteExecutionControl class).

The example commands above are provided in the test scripts run_test_target (to be executed first) and run_jshell. From the JShell instance, run for example

 import uk.org.cinquin.attaching_jshell.ExistingVMRemoteExecutionControl;
 String s = ExistingVMRemoteExecutionControl.theGoodsForTesting

Implementation notes

The need to use the ExistingVMRemoteExecutionControl class from the target JVM stems from limitations in the Java Debug Interface (JDI). An alternative would be to use the JVM Tool Interface, which would require compiling platform-specific native binaries, or to use JDI in a more hackish way to get the JShell connection established.

Note on security

Make sure that the debugging port created with the -agentlib:jdwp option shown above is not publicly exposed, as it can be exploited rather trivially for arbitrary code execution.

Limitations

  • Only one JShell instance can be connected to a target VM at any given time. This limitation could probably be lifted with some work.
  • The standard error stream of the target JVM is captured by JShell and is currently not restored when JShell exits.
  • The versions of JShell on the target JVM and the one running JShell probably need to match. Note that this project has been tested with Oracle JDK early access build 161, which hopefully will be close to the final release of JDK 9.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].