Specify JDK as openjdk-bin-11 upon entering chroot

BUG=chromium:1105515
BUG=b:160661271
TEST=// This test should be done when multiple version of JDK exist.
// Currently, there is only JDK 11 in chroot.
// Please refer to crrev.com/c/2336338 to set up the environment to perform
// the tests below.
// This CL should be merged first because default selection of JDK 11
// should be established before having multiple versions of JDK.
// Also tested on current environment where only JDK 11 exist.

sudo eselect java-vm set system icedtea-bin-8
// Initially set default JDK as JDK8
// Make sure /etc/cros_chroot_version is 179.

sudo eselect java-vm list
// Confirm that the system-vm is currently icedtea-bin-8.

run_chroot_version_hooks
// Make sure run_chroot_version_hooks is now 180.

sudo eselect java-vm list
// Confirm that the system-vm is now openjdk-bin-11.

Change-Id: Ib21cb70672e48eaf519c99f7d74951a17dd94adb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosutils/+/2335921
Tested-by: Jiyoun Ha <jiyounha@chromium.org>
Commit-Queue: Jiyoun Ha <jiyounha@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Auto-Submit: Jiyoun Ha <jiyounha@chromium.org>
diff --git a/chroot_version_hooks.d/180_select_jvm b/chroot_version_hooks.d/180_select_jvm
new file mode 100644
index 0000000..e76d71c
--- /dev/null
+++ b/chroot_version_hooks.d/180_select_jvm
@@ -0,0 +1,15 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Specify JDK as openjdk-bin-11 upon entering chroot.
+# See crrev.com/c/2335921 for more details.
+
+# Make sure dependencies are installed for older SDKs.
+sudo emerge -qug '>=virtual/jdk-9'
+
+sudo eselect java-vm set system openjdk-bin-11
+
+# Log current state for debugging issues.
+eselect java-vm list
+whereis java
diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh
index 037b190..3af93b3 100755
--- a/sdk_lib/make_chroot.sh
+++ b/sdk_lib/make_chroot.sh
@@ -626,7 +626,7 @@
 
 # The java-config package atm does not support $ROOT.  Select a default
 # VM ourselves until that gets fixed upstream.
-enter_chroot sudo java-config --set-system-vm 1
+enter_chroot sudo eselect java-vm set system openjdk-bin-11
 
 CHROOT_EXAMPLE_OPT=""
 if [[ "$FLAGS_chroot" != "$DEFAULT_CHROOT_DIR" ]]; then