JDK-4631373 : Integer division and modulo operations are very slow
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-01-31
  • Updated: 2002-04-12
  • Resolved: 2002-04-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.1 hopperFixed
Description

Name: rmT116609			Date: 01/31/2002


FULL PRODUCT VERSION :
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)

Operating System: Windows 2000

SYSTEM CONFIGURATION : 1.7Ghz Pentium 4, 1GB RAM

DESCRIPTION OF THE PROBLEM :
The division and modulo operations are significantly (about 10 times) slower under Hotspot than under the JIT included with the 1.1, 1.1.8 and 1.2releases.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test with 50,000,000 iterations with Hotspot and with the JIT included in either JDK1.1 or JDK1.1.8. You can see that the problem is with modulo and division because if you replace the modulo operation to multiplication for example you will get results close to the earlier JITs. If you replace the modulo with division however, the 10 fold decrease in performance remains.

EXPECTED VERSUS ACTUAL BEHAVIOR :
I would expect Hotspot not to be any slower than the earlier JITs.

This bug can be reproduced always.

---------- BEGIN SOURCE ----------

/**
 * This tests basic operations (multiplication, subtraction, modulo).
 */

public
class Test1{

  public static void main(String [] args){
    if (args.length==0){
      
System.err.println("You must specify the amount of iterations to perform");
      return;
    }


    int iterationsCount;
    try{
      iterationsCount = Integer.parseInt(args[0]);
    } catch(NumberFormatException e){
        System.err.println("Unparseable argument: "+args[0]+",must be an integer");
        return;
      }

    System.out.println("JVM vendor:"+System.getProperty("java.vendor"));
    System.out.println("JVM version:"+System.getProperty("java.version"));
    System.out.println();

    // Warm up loop
    
System.out.println("Warm up:");
    for (int i=0;i<5;i++){
      long startTime = System.currentTimeMillis();
      int result = method(iterationsCount);
      long endTime = System.currentTimeMillis();
      System.out.println((i+1)+") Result: "+result+" Took: "+(endTime-startTime)+"ms.");
    }

    // The real thing
    System.out.println();
    
System.out.println("The real thing:");
    for (int i=0;i<5;i++){
      long startTime =
System.currentTimeMillis();
      int result = method(iterationsCount);
      long endTime = System.currentTimeMillis();
      System.out.println((i+1)+") Result: "+result+" Took:
"+(endTime-startTime)+"ms.");
    }

  }



  public static int method(int iterationsCount){
     int sum = 0;
     for (int i=0;i<iterationsCount;i++){
       sum += (i*5-1)%4;
     
}
     return sum;
  }

}
---------- END SOURCE ----------

Test Results:

JVM vendor: Sun Microsystems Inc.
JVM version: 1.1.8

Warm up:
1) Result: 74999996 Took: 131ms.
2) Result: 74999996 Took: 120ms.
3) Result: 74999996 Took: 120ms.
4) Result: 74999996 Took: 120ms.
5) Result: 74999996 Took: 120ms.

The real thing:
1) Result: 74999996 Took: 120ms.
2) Result: 74999996 Took: 121ms.
3) Result: 74999996 Took: 120ms.
4) Result: 74999996 Took: 120ms.
5) Result: 74999996 Took: 120ms.



---- Sun 1.2 ----

[c:\java\tests]C:\java\JDK1.2\bin\java Test1 50000000
JVM vendor: Sun Microsystems Inc.
JVM version: 1.2.2

Warm up:
1) Result: 74999996 Took: 120ms.
2) Result: 74999996 Took: 130ms.
3) Result: 74999996 Took: 120ms.
4) Result: 74999996 Took: 121ms.
5) Result: 74999996 Took: 130ms.

The real thing:
1) Result: 74999996 Took: 120ms.
2) Result: 74999996 Took: 130ms.
3) Result: 74999996 Took: 120ms.
4) Result: 74999996 Took: 121ms.
5) Result: 74999996 Took: 120ms.


---- Sun 1.3 (Hotspot) ----

[c:\java\tests]java Test1 50000000
JVM vendor: Sun Microsystems Inc.
JVM version: 1.3.1_02

Warm up:
1) Result: 74999996 Took: 1813ms.
2) Result: 74999996 Took: 1772ms.
3) Result: 74999996 Took: 1823ms.
4) Result: 74999996 Took: 1782ms.
5) Result: 74999996 Took: 1813ms.

The real thing:
1) Result: 74999996 Took: 1772ms.
2) Result: 74999996 Took: 1833ms.
3) Result: 74999996 Took: 1773ms.
4) Result: 74999996 Took: 1832ms.
5) Result: 74999996 Took: 1773ms.



---- Sun 1.4 (Hotspot) ----

[c:\java\tests]C:\Java\JDK1.4\bin\java Test1 50000000
JVM vendor: Sun Microsystems Inc.
JVM version: 1.4.0-beta3

Warm up:
1) Result: 74999996 Took: 1783ms.
2) Result: 74999996 Took: 1792ms.
3) Result: 74999996 Took: 1743ms.
4) Result: 74999996 Took: 1742ms.
5) Result: 74999996 Took: 1793ms.

The real thing:
1) Result: 74999996 Took: 1742ms.
2) Result: 74999996 Took: 1793ms.
3) Result: 74999996 Took: 1743ms.
4) Result: 74999996 Took: 1782ms.
5) Result: 74999996 Took: 1753ms.


I used the latest releases of all the JVMs. I am sure that if you run my test under the same environment I did you will get the same results as I have been able to reproduce them on all computers I have tested on.
Also note that this is not a Pentium 4 specific problem -- I have reproduced it under Pentium 2 as well, although under P4 the performance decrease is x15 while only x10 on my P2.

(Review ID: 138520) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: hopper FIXED IN: hopper INTEGRATED IN: hopper
14-06-2004

EVALUATION We don't strength reduce integer div and mod by power of 2 on intel. I've got it working and can produce numbers about the same as symcjit. sparc already does this. ###@###.### 2002-02-20
20-02-2002