GNU bug report logs - #41748
[PATCH 0/1] Fix JamVM to work with current gcc and glibc

Previous Next

Package: guix-patches;

Reported by: Simon South <simon <at> simonsouth.net>

Date: Sun, 7 Jun 2020 15:19:02 UTC

Severity: normal

Tags: patch

Done: Marius Bakke <marius <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 41748 in the body.
You can then email your comments to 41748 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#41748; Package guix-patches. (Sun, 07 Jun 2020 15:19:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Simon South <simon <at> simonsouth.net>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Sun, 07 Jun 2020 15:19:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Simon South <simon <at> simonsouth.net>
To: guix-patches <at> gnu.org
Cc: Simon South <simon <at> simonsouth.net>
Subject: [PATCH 0/1] Fix JamVM to work with current gcc and glibc
Date: Sun,  7 Jun 2020 11:17:09 -0400
This patch allows JamVM 2.0.0 to be built without using outdated versions of
gcc and glibc, by disabling the branch-patching optimization JamVM normally
applies to code it has inlined.

I've successfully built IcedTea 1.13.13 on x86_64 with this patch applied,
without encountering any "Invalid instruction" errors. It also seems to work
fine on aarch64.

Lengthy explanation, for anyone interested in the details:

JamVM's branch-patching optimization tries to improve the performance of
Java's branching opcodes by replacing the load-operand-and-jump portion of
their implementation with a single jump instruction directly to the handler
for the opcode to which the operand points. However, the current
implementation

- Doesn't attempt much of an optimization, since it only replaces the final
  jump instruction with another (the operand is still loaded in either case).

- Doesn't have any actual effect since the instruction it replaces is a
  duplicate synthesized by gcc that is never executed anyway.

- Is prone to breakage, since it doesn't ensure the new jump instruction is
  the same length as the original. (This is the specific reason for the
  failure on x86_64: The replacement jump instruction is longer and clobbers
  part of the following instruction, making it invalid.)

This patch simply disables the optimization within JamVM, leaving the other
optimizations intact. (gcc is smart enough to no longer generate duplicate
jump instructions in this case so it reduces the code size slightly, too.)

Alternate solutions I considered and rejected:

- Fixing the implementation. JamVM uses a label to mark within each opcode's
  handler where the jump instruction should be placed, and moving this label
  to the start of the load-and-jump sequence rather than the end appears (from
  stepping through the code with gdb) to fix all the issues above. However,
  JamVM then fails at startup, reporting an unhandle-able exception during
  initialization. So presumably some other part of the code relies on the
  current, broken implementation of this feature, and while it's probably
  possible to fix _that_ as well I doubt it would be worth the effort.

- Disabling the optimization at runtime. Invoking JamVM with "-Xnopatching"
  also solves the problem, and we could just update the bootstrap procedure to
  do this. However JamVM 1.5.1 doesn't recognize this option and fails if it's
  specified, so we'd need to change the ecj-javac-wrapper package to handle
  the two interpreters differently or to accept an argument specifying the
  flags to use, and in my opinion this would be a step backwards from what
  exists currently.

  Also, since JamVM would only ever work reliably when this option is
  specified, it's not really much of an "option" and making its effect
  permanent in the code seems like a more sensible approach.
  
--
Simon South
simon <at> simonsouth.net


Simon South (1):
  gnu: jamvm: Fix to work with current gcc and glibc.

 gnu/packages/java.scm                         |  7 ++---
 .../jamvm-2.0.0-disable-branch-patching.patch | 27 +++++++++++++++++++
 2 files changed, 29 insertions(+), 5 deletions(-)
 create mode 100644 gnu/packages/patches/jamvm-2.0.0-disable-branch-patching.patch

-- 
2.26.2




Information forwarded to guix-patches <at> gnu.org:
bug#41748; Package guix-patches. (Sun, 07 Jun 2020 15:21:01 GMT) Full text and rfc822 format available.

Message #8 received at 41748 <at> debbugs.gnu.org (full text, mbox):

From: Simon South <simon <at> simonsouth.net>
To: 41748 <at> debbugs.gnu.org
Cc: Simon South <simon <at> simonsouth.net>
Subject: [PATCH 1/1] gnu: jamvm: Fix to work with current gcc and glibc.
Date: Sun,  7 Jun 2020 11:18:33 -0400
* gnu/packages/patches/jamvm-2.0.0-disable-branch-patching.patch: New file.
* gnu/packages/java.scm (jamvm)[source]: Add patch.
(jamvm-1-bootstrap)[native-inputs]: Remove.
---
 gnu/packages/java.scm                         |  7 ++---
 .../jamvm-2.0.0-disable-branch-patching.patch | 27 +++++++++++++++++++
 2 files changed, 29 insertions(+), 5 deletions(-)
 create mode 100644 gnu/packages/patches/jamvm-2.0.0-disable-branch-patching.patch

diff --git a/gnu/packages/java.scm b/gnu/packages/java.scm
index 43f0f37b91..9a6f6fe0df 100644
--- a/gnu/packages/java.scm
+++ b/gnu/packages/java.scm
@@ -254,11 +254,6 @@ language.")
        ("libffi" ,libffi)
        ("zip" ,zip)
        ("zlib" ,zlib)))
-    ;; When built with a recent GCC and glibc the configure step of icedtea-6
-    ;; fails with an invalid instruction error.
-    (native-inputs
-     `(("gcc" ,gcc-5)
-       ("libc" ,glibc-2.28)))
     (home-page "http://jamvm.sourceforge.net/")
     (synopsis "Small Java Virtual Machine")
     (description "JamVM is a Java Virtual Machine conforming to the JVM
@@ -708,6 +703,8 @@ machine.")))
               (sha256
                (base32
                 "1nl0zxz8y5x8gwsrm7n32bry4dx8x70p8z3s9jbdvs8avyb8whkn"))
+              (patches
+               (search-patches "jamvm-2.0.0-disable-branch-patching.patch"))
               (snippet
                '(begin
                   ;; Remove precompiled software.
diff --git a/gnu/packages/patches/jamvm-2.0.0-disable-branch-patching.patch b/gnu/packages/patches/jamvm-2.0.0-disable-branch-patching.patch
new file mode 100644
index 0000000000..a99624280f
--- /dev/null
+++ b/gnu/packages/patches/jamvm-2.0.0-disable-branch-patching.patch
@@ -0,0 +1,27 @@
+From 8d10be7345d7fe139e619cc55a22dbc86f677543 Mon Sep 17 00:00:00 2001
+From: Simon South <simon <at> simonsouth.net>
+Date: Sat, 6 Jun 2020 18:56:56 -0400
+Subject: [PATCH] Disable branch-patching
+
+---
+ src/init.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/init.c b/src/init.c
+index 32539cf..38ad54b 100644
+--- a/src/init.c
++++ b/src/init.c
+@@ -72,8 +72,8 @@ void setDefaultInitArgs(InitArgs *args) {
+ #ifdef INLINING
+     args->replication_threshold = 10;
+     args->profile_threshold     = 10;
+-    args->branch_patching_dup   = TRUE;
+-    args->branch_patching       = TRUE;
++    args->branch_patching_dup   = FALSE;
++    args->branch_patching       = FALSE;
+     args->print_codestats       = FALSE;
+     args->join_blocks           = TRUE;
+     args->profiling             = TRUE;
+-- 
+2.25.2
+
-- 
2.26.2





Information forwarded to guix-patches <at> gnu.org:
bug#41748; Package guix-patches. (Wed, 10 Jun 2020 15:06:02 GMT) Full text and rfc822 format available.

Message #11 received at 41748 <at> debbugs.gnu.org (full text, mbox):

From: Simon South <simon <at> simonsouth.net>
To: 41748 <at> debbugs.gnu.org
Subject: Re: [PATCH 0/1] Fix JamVM to work with current gcc and glibc
Date: Wed, 10 Jun 2020 11:03:39 -0400
[Message part 1 (text/plain, inline)]
Attached is an updated version of this patch that

- Adds a brief description to the patch it contains, indicating why it
  is necessary; and

- Updates gnu/local.mk, as is apparently now required.

-- 
Simon South
simon <at> simonsouth.net

[0001-gnu-jamvm-Fix-to-work-with-current-gcc-and-glibc.patch (text/x-patch, attachment)]

Reply sent to Marius Bakke <marius <at> gnu.org>:
You have taken responsibility. (Mon, 22 Jun 2020 20:38:01 GMT) Full text and rfc822 format available.

Notification sent to Simon South <simon <at> simonsouth.net>:
bug acknowledged by developer. (Mon, 22 Jun 2020 20:38:02 GMT) Full text and rfc822 format available.

Message #16 received at 41748-done <at> debbugs.gnu.org (full text, mbox):

From: Marius Bakke <marius <at> gnu.org>
To: Simon South <simon <at> simonsouth.net>, 41748-done <at> debbugs.gnu.org
Cc: Simon South <simon <at> simonsouth.net>
Subject: Re: [bug#41748] [PATCH 0/1] Fix JamVM to work with current gcc and
 glibc
Date: Mon, 22 Jun 2020 22:37:03 +0200
[Message part 1 (text/plain, inline)]
Simon South <simon <at> simonsouth.net> writes:

> This patch allows JamVM 2.0.0 to be built without using outdated versions of
> gcc and glibc, by disabling the branch-patching optimization JamVM normally
> applies to code it has inlined.
>
> I've successfully built IcedTea 1.13.13 on x86_64 with this patch applied,
> without encountering any "Invalid instruction" errors. It also seems to work
> fine on aarch64.

Thanks a lot for this patch, and the brilliant analysis.  I have applied
the updated version and will push shortly.

I modified it to also remove the (gnu packages gcc) import from
java.scm.  \o/
[signature.asc (application/pgp-signature, inline)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 21 Jul 2020 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 274 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.