JDK-5074608 : Counted loop in the test is not recognized by C2
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_9
  • CPU: sparc
  • Submitted: 2004-07-15
  • Updated: 2005-09-22
  • Resolved: 2005-09-22
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.
JDK 6
6 b53Fixed
Description
C2 generates Safepoint polling in the counted loop in the next example.

% cat Test.java
class Test {
    static int val = 0;

    public static int foo(int val) {
       return val + 1000;
    }

    public static void test() {
       for (int i = 0; i < 100; i++) {
          val = i;
          if (val == 50) {
             val = foo(val);      
          }         
       }
    }

    public static void main(String argv[]) {
       for (int i=0; i < 15000; i++) 
         test();
       System.out.println("value = "  + val);
    }
 
 }
% java_g -server -version
java version "1.5.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b58)
Java HotSpot(TM) Server VM (build 1.5.0-beta3-b58-debug, mixed mode)
% javac Test.java
% java_g -server -XX:+PrintCompilation -XX:CompileOnly=Test.test -XX:+PrintOptoAssembly -Xbatch -XX:-Inline -XX:CICompilerCount=1 Test
VM option '+PrintCompilation'
VM option 'CompileOnly=Test.test'
VM option '+PrintOptoAssembly'
VM option '-Inline'
VM option 'CICompilerCount=1'
  1   b   Test::test (36 bytes)
{method} 
 - klass: {other class}
 - method holder:     'Test'
 - constants:         0xfec62020{constant pool}
 - access:            0xc1000009  public static 
 - name:              'test'
 - signature:         '()V'
...
020   B2: #     B4 B3 <- B1 B7  Loop: B2-B7 inner  Freq: 4.44445
# Lrgs use/def'd in loop: {1,3-9}
020 +   CMP    R_O0,#50
024     BPeq   ccr,B4  P=0.009950 C=4.422000
024     STW    R_O0,[R_L0 + #296]
024
02c   B3: #     B6 <- B2        Loop: B2-B7 inner  Freq: 4.378
02c +   BA     B6
02c     ADD    R_O0,#1,R_O0
02c
034   B4: #     B9 B5 <- B2     Loop: B2-B7 inner  Freq: 0.0439999
034     CALL,static  ; NOP ==>  Test::foo
        # Test::test @ bci:23  L0=#50
        # R_L0=Oop 
03c
03c   B5: #     B6 <- B4        Loop: B2-B7 inner  Freq: 0.043999
03c +   STW    R_O0,[R_L0 + #296]
040     MOV    #51,R_O0
040
044   B6: #     B8 B7 <- B5 B3  Loop: B2-B7 inner  Freq: 4.422
044 +   LDUW   [R_L2],R_G0      ! Safepoint: poll for GC        # Test::test @ bci:32  L0=R_O0
        # R_L0=Oop 
048 +   CMP    R_O0,#100
04c     BPge   ccr,B8  P=0.010000 C=4.422000
04c
054   B7: #     B2 <- B6        Loop: B2-B7 inner  Freq: 4.37778
054 +   BA     B2
054
05c   B8: #     N1 <- B6  Freq: 0.04422
05c     SETHI  #PollAddr,L0     ! Load Polling address
        LDUW   [L0],G0  !Poll for Safepointing
        RET
        RESTORE
06c +   RET
        NOP

Comments
SUGGESTED FIX http://analemma.sfbay.sun.com/net/prt-archiver.sfbay/data/archived_workspaces/main/c2_baseline/2005/20050915095202.nips.ifeq/workspace/webrevs/webrev-2005.09.15/index.html
15-09-2005

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
02-09-2004

EVALUATION ###@###.### 2004-07-15 The loop is not recognized as counted and the call do not dominate the loop's end. So the safepoint polling is generated at the end of the loop. We need to fix it for performance.
02-09-2004