RFR: 8352693: Use a simpler console reader instead of JLine for System.console()

Magnus Ihse Bursie ihse at openjdk.org
Mon Mar 31 12:51:37 UTC 2025


On Wed, 26 Mar 2025 07:54:48 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> The `java.io.Console` has several backends: a simple on in `java.base`, a more convenient one in `jdk.internal.le` (with line-reading based on JLine) and one for JShell.
> 
> The backend based on JLine is proving to be a somewhat problematic - JLine is very powerful, possibly too powerful and complex for the simple task of editing a line with no completion, no history, no variables, no commands, etc. As a consequence, there are inevitable sharp edges in this backend.
> 
> The idea in this PR is to replace the use of JLine in the `jdk.internal.le` backend with a simple escape code interpreter, that only handles a handful of keys/codes (left/right arrow, home, end, delete, backspace, enter), and ignores the rest. The goal is to have something simple with less surprising behavior.

make/modules/jdk.internal.le/Lib.gmk line 30:

> 28: ################################################################################
> 29: 
> 30: ifeq ($(call isTargetOs, linux macosx windows), true)

You might want to sync with the AIX guys to see if this should be enabled there as well. The unix version seems quite portable, so I assume it will work with very few adjustments, if any. @MBaesken 

Otherwise, what will happen if you try to run this on a platform without the corresponding native library?

make/modules/jdk.internal.le/Lib.gmk line 35:

> 33:       NAME := le, \
> 34:       TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
> 35:       OPTIMIZATION := LOW, \

We are trying to move away from using `LOW` as a default optimization level. If you believe this library is not performance critical, please use `SIZE` as the new default. Or, use `HIGHEST` if that gives performance benefits with no significant impact on library size.

make/modules/jdk.internal.le/Lib.gmk line 36:

> 34:       TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
> 35:       OPTIMIZATION := LOW, \
> 36:       JDK_LIBS := java.base:libjava, \

A quick glance through the native code revealed no obvious calls to libjava functions. Are you sure this dependency is needed?

make/modules/jdk.internal.le/Lib.gmk line 37:

> 35:       OPTIMIZATION := LOW, \
> 36:       JDK_LIBS := java.base:libjava, \
> 37:       LIBS_unix := $(JDKLIB_LIBS) $(LIBCXX), \

LIBCXX is added automatically nowadays, so you can remove this entire line.

make/modules/jdk.internal.le/Lib.gmk line 38:

> 36:       JDK_LIBS := java.base:libjava, \
> 37:       LIBS_unix := $(JDKLIB_LIBS) $(LIBCXX), \
> 38:       LIBS_windows := $(JDKLIB_LIBS) user32.lib, \

JDKLIB_LIBS is not used anymore.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/24242#discussion_r2020982841
PR Review Comment: https://git.openjdk.org/jdk/pull/24242#discussion_r2020979597
PR Review Comment: https://git.openjdk.org/jdk/pull/24242#discussion_r2020976254
PR Review Comment: https://git.openjdk.org/jdk/pull/24242#discussion_r2020977176
PR Review Comment: https://git.openjdk.org/jdk/pull/24242#discussion_r2020976750


More information about the build-dev mailing list