United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6795362 32bit server compiler leads to wrong results on solaris-x86
JDK-6795362 : 32bit server compiler leads to wrong results on solaris-x86

Details
Type:
Bug
Submit Date:
2009-01-19
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
hotspot
OS:
solaris
Sub-Component:
compiler
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
hs13
Fixed Versions:
hs15 (b02)

Related Reports
Backport:
Backport:
Backport:
Backport:

Sub Tasks

Description
The following test case produces wrong results (var_bad) when
running jvm with 32bit server compiler on solaris-x86.

> JDK7b43/bin/java -server -Xcomp -XX:CompileOnly=TesterSmall_Class_0 TesterSmall
var_bad = -602947331
var_ok  = 0

============ TesterSmall.java ==============
class TesterSmall_Class_0 {
    static long var_bad = -1L;

    public TesterSmall_Class_0()
    {
      var_bad >>= 65;
      var_bad /= 65;
    }
}

public class TesterSmall {
    public static void main(String[] args)
    {
        TesterSmall_Class_0 t =  new TesterSmall_Class_0();

        long var_ok = -1L;
        var_ok >>= 65;
        var_ok /= 65;

        System.out.println("var_bad = " + TesterSmall_Class_0.var_bad);
        System.out.println("var_ok  = " + var_ok);
    }
}

=======================================

The test works fine on other platforms with bot 32bit and 64bit jvms.

                                    

Comments
EVALUATION

The bug was introduced with 6603011 and 6732154 already fixed a problem in the new code.  I suspect this bug is similar to 6732154.
                                     
2009-01-29
EVALUATION

6732154 has been fixed in hs14-b04, but the test still fails with latest hs14-b10
as well as hs14-b04:

/java/re/jdk/7/promoted/all/b44/binaries/solaris-i586/bin/java -server -Xcomp -XX:CompileOnly=TesterSmall_Class_0 -showversion TesterSmall
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b44)
Java HotSpot(TM) Server VM (build 14.0-b10, compiled mode)

var_bad = -602947331
var_ok  = 0

/java/re/jdk/7/promoted/all/b35/binaries/solaris-i586/bin/java -server -Xcomp -XX:CompileOnly=TesterSmall_Class_0 -showversion TesterSmall
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b35)
Java HotSpot(TM) Server VM (build 14.0-b04, compiled mode)

var_bad = -602947331
var_ok  = 0
                                     
2009-01-29
EVALUATION

Obviously, because 6732154 fixes a similar but different problem.  Still investigating.
                                     
2009-01-29
EVALUATION

When the:

  // Masking off sign bits?  Dont make them!
  if( rop == Op_RShiftL ) {

special case in AndLNode::Ideal is commented, the generated code is correct.
                                     
2009-01-29
EVALUATION

As Tom suspected the bug is in the Op_URShiftL special case in AndLNode::Identity.  The constant shift value gets not masked before calculations are done.  Adding the line:

        shift &= (BitsPerJavaInteger * 2) - 1;  // semantics of Java shifts

fixes the bug.

It seems the same bug is in AndINode::Identity, but I couldn't create a testcase yet.  If I find one I will open a new CR.
                                     
2009-01-30
SUGGESTED FIX

diff -Nupr 6795362.3b5ac9e7e6ea/src/share/vm/opto/mulnode.cpp 6795362/src/share/vm/opto/mulnode.cpp
--- 6795362.3b5ac9e7e6ea/src/share/vm/opto/mulnode.cpp	2009-01-30 11:24:39.694445872 +0100
+++ 6795362/src/share/vm/opto/mulnode.cpp	2009-01-30 11:24:39.695265016 +0100
@@ -581,6 +581,7 @@ Node *AndLNode::Identity( PhaseTransform
       const TypeInt *t12 = phase->type( usr->in(2) )->isa_int();
       if( t12 && t12->is_con() ) {
         int shift_con = t12->get_con();
+        shift_con &= (BitsPerJavaInteger * 2) - 1;  // semantics of Java shifts
         jlong mask = max_julong >> shift_con;
         if( (mask&con) == mask )  // If AND is useless, skip it
           return usr;
                                     
2009-01-30
EVALUATION

http://hg.openjdk.java.net/jdk7/hotspot-comp/hotspot/rev/7628781568e1
                                     
2009-02-03
EVALUATION

The fix has been verified as part of hs15-b02 pit.
                                     
2009-02-24



Hardware and Software, Engineered to Work Together