This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Java interpreter miscompiled due to -fnon-call-exceptions bug


Hello,

after fixing the various libffi and glibc problems, it turns out that the
Java interpreter *still* doesn't work properly on s390x.

This time, the reason turned out to be that the main routine of the
interpreter, _Jv_InterpMethod::run, was actually miscompiled.

This is because delete_trivially_dead_insns deleted a insn sequence
only partially, leaving an incorrect insn remaining.

In interpret.cc.02.eh, we have:

(insn 49 42 9295 0 0x10000b42e70 (set (reg:HI 49)
        (mem/s:HI (plus:DI (reg/v/u/f:DI 40)
                (const_int 18 [0x12])) [16 <variable>.max_stack+0 S2 A16])) -1 (nil)
    (expr_list:REG_EH_REGION (const_int 1 [0x1])
        (nil)))

(note 9295 49 50 1 [bb 1] NOTE_INSN_BASIC_BLOCK)

(insn 50 9295 51 1 0x10000b42e70 (set (reg:DI 48)
        (ashift:DI (subreg:DI (reg:HI 49) 0)
            (const_int 48 [0x30]))) -1 (nil)
    (nil))

(insn 51 50 52 1 0x10000b42e70 (set (reg:DI 48)
        (lshiftrt:DI (reg:DI 48)
            (const_int 48 [0x30]))) -1 (nil)
    (expr_list:REG_EQUAL (zero_extend:DI (reg:HI 49))
        (nil)))

(insn 52 51 53 1 0x10000b42e70 (parallel [
            (set (reg:DI 47)
                (plus:DI (reg:DI 48)
                    (const_int -1 [0xffffffffffffffff])))
            (clobber (reg:CC 33 %cc))
        ]) -1 (nil)
    (nil))

which gets partially deleted to (in interpret.cc.03.jump):

(insn 49 42 9295 0 0x10000b42e70 (set (reg:HI 49)
        (mem/s:HI (plus:DI (reg/v/u/f:DI 40)
                (const_int 18 [0x12])) [16 <variable>.max_stack+0 S2 A16])) -1 (nil)
    (expr_list:REG_EH_REGION (const_int 1 [0x1])
        (nil)))

(note 9295 49 51 1 [bb 1] NOTE_INSN_BASIC_BLOCK)

(insn 51 9295 53 1 0x10000b42e70 (set (reg:DI 48)
        (lshiftrt:DI (reg:DI 48)
            (const_int 48 [0x30]))) -1 (nil)
    (expr_list:REG_EQUAL (zero_extend:DI (reg:HI 49))
        (nil)))


Insns 50 and 52 are deleted, insn 49 isn't (because it may trap),
and insn 51 also isn't.  The latter is the problem, because it
now accesses an uninitialized reg 48, and the REG_EQUAL note is
now no longer valid (this caused the later miscompile).

The reason why insn 51 wasn't deleted is because of this code
in insn_live_p (cse.c):

  if (flag_non_call_exceptions && may_trap_p (insn))
    return true;

Note that insn at this point is a full insn.  However,
may_trap_p expects an insn *pattern* as far as I can tell;
when passing a full insn to may_trap_p, it will interpret
the expr_list holding the REG_EQUAL note as something that
may trap ...

When passing PATTERN (insn) instead, the Java interpreter works.

OK to apply the following patch?   Bootstrapped/regtested on
s390-ibm-linux and s390x-ibm-linux.

      * cse.c (insn_live_p): Pass insn pattern, not full insn
      to may_trap_p.

Index: gcc/cse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cse.c,v
retrieving revision 1.238
diff -c -p -r1.238 cse.c
*** gcc/cse.c     1 Oct 2002 12:19:36 -0000     1.238
--- gcc/cse.c     7 Oct 2002 20:46:24 -0000
*************** insn_live_p (insn, counts)
*** 7582,7588 ****
       int *counts;
  {
    int i;
!   if (flag_non_call_exceptions && may_trap_p (insn))
      return true;
    else if (GET_CODE (PATTERN (insn)) == SET)
      return set_live_p (PATTERN (insn), insn, counts);
--- 7582,7588 ----
       int *counts;
  {
    int i;
!   if (flag_non_call_exceptions && may_trap_p (PATTERN (insn)))
      return true;
    else if (GET_CODE (PATTERN (insn)) == SET)
      return set_live_p (PATTERN (insn), insn, counts);



Mit freundlichen Gruessen / Best Regards

Ulrich Weigand

--
  Dr. Ulrich Weigand
  Linux for S/390 Design & Development
  IBM Deutschland Entwicklung GmbH, Schoenaicher Str. 220, 71032 Boeblingen
  Phone: +49-7031/16-3727   ---   Email: Ulrich.Weigand@de.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]