Bug 172913 - [compiler][1.5] an extra checkcast bytecode instruction generated
Summary: [compiler][1.5] an extra checkcast bytecode instruction generated
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M6   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-05 15:32 EST by Sergey Bushkov CLA
Modified: 2007-03-20 09:47 EDT (History)
0 users

See Also:


Attachments
Proposed patch (5.57 KB, patch)
2007-02-22 13:08 EST, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Bushkov CLA 2007-02-05 15:32:59 EST
Build ID: 3.2.1.M20060921-0945

Steps To Reproduce:
The source code below is compiled differently by javac (1.5.0_08) and eclipse compiler. The eclipse compiler created two sequental checkcast instructions.

Source code:

package xyz;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

public class CheckCast {
  private void processLocks(HashMap locksMap, Object key) {
    for (Iterator iter = locksMap.keySet().iterator(); iter.hasNext();) {
      Object call = iter.next();
      List locks = externLocks((Collection) locksMap.get(call), call);
      // ...
    }
  }
  private List externLocks(Collection locks, Object call) {
    List result = new ArrayList();
    // ..
    return result;
  }
}

javac -p -private ... for class compiled with javac:
...
private void processLocks(java.util.HashMap, java.lang.Object);
  Code:
   0:	aload_1
...
   29:	aload	4
   31:	invokevirtual	#6; //Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
   34:	checkcast	#7; //class java/util/Collection
   37:	aload	4
...

javac -p -private ... for class compiled with the eclipse compiler:
...
private void processLocks(java.util.HashMap, java.lang.Object);
  Code:
   0:	aload_1
...
   25:	invokevirtual	#34; //Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
   28:	checkcast	#38; //class java/util/Collection
   31:	checkcast	#38; //class java/util/Collection
   34:	aload	4
   36:	invokespecial	#40; //Method externLocks:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
...

More information:
Default settings are used for project, compiler compliance level 5.0.
Comment 1 Olivier Thomann CLA 2007-02-05 15:39:48 EST
This is indeed suboptimal.
I'll investigate. Too late for 3.2.2.
Comment 2 Sergey Bushkov CLA 2007-02-05 16:55:18 EST
More information:

the extra checkcast does not appear if compiler compliance level is set to 1.4.
Comment 3 Philipe Mulet CLA 2007-02-07 06:40:24 EST
There seems to be an irrelevant generic cast inserted.
Comment 4 Philipe Mulet CLA 2007-02-22 13:06:19 EST
We were protecting against such a situation, but not perfectly. The postConversionType is an erased type, which doesn't compare identical to a raw/param type.
Comment 5 Philipe Mulet CLA 2007-02-22 13:08:50 EST
Created attachment 59593 [details]
Proposed patch
Comment 6 Philipe Mulet CLA 2007-02-22 13:09:07 EST
Fixed
Comment 7 Olivier Thomann CLA 2007-03-20 09:47:05 EDT
Verified for 3.3 M6 using build I20070320-0010