Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 326354 - [3.6][compiler][regression] Compiler in 3.6 and 3.6.1 generates bad code
Summary: [3.6][compiler][regression] Compiler in 3.6 and 3.6.1 generates bad code
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6.1   Edit
Hardware: PC All
: P3 major (vote)
Target Milestone: 3.6.2   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-27 16:56 EDT by Claudiu Soroiu CLA
Modified: 2011-01-20 03:51 EST (History)
7 users (show)

See Also:
daniel_megert: pmc_approved+
Olivier_Thomann: review+


Attachments
test case to reproduce the problem (3.36 KB, application/octet-stream)
2010-09-27 16:58 EDT, Claudiu Soroiu CLA
no flags Details
Patch under test (2.59 KB, patch)
2010-10-21 06:16 EDT, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Claudiu Soroiu CLA 2010-09-27 16:56:51 EDT
Build Identifier: 20100917-0705

Compiler in Eclipse 3.6 and 3.6.1 (tested also with ecj apckage separately) generates bad bytecode for the attached sources.

As a side note, the offered source code can be incorporated inside a regression test suite for the compiler.

Reproducible: Always

Steps to Reproduce:
1. Compile the sources in the attached jar using either ecj 3.6 or ecj 3.6.1
2. run ro.derbederos.eclipse36xfailure.Main
3. you will see that sun jvm 6 b21 (haven't tested with other jvm version) throws the exception:

Exception in thread "main" java.lang.NoSuchMethodError: ro.derbederos.ecj36xfailure.AbstractFilterChain.addFirst(Ljava/lang/String;Lro/derbederos/ecj36xfailure/IMessageFilter;)V
	at ro.derbederos.ecj36xfailure.FilterChainImpl.addFirst(FilterChainImpl.java:1)
	at ro.derbederos.ecj36xfailure.Main.main(Main.java:7)

by running same code compiled with ecj 3.5.1 and 3.5.2 everything is fine (I haven't tested with older versions, but i was using ecj 3.5.1 and 3.5.2 before upgrading to 3.6)
Comment 1 Claudiu Soroiu CLA 2010-09-27 16:58:46 EDT
Created attachment 179689 [details]
test case to reproduce the problem
Comment 2 Claudiu Soroiu CLA 2010-09-27 17:05:51 EDT
i was able to reproduce the bug on windows and linux.
Comment 3 Olivier Thomann CLA 2010-09-27 18:48:58 EDT
I'll investigate.
Comment 4 Olivier Thomann CLA 2010-09-29 16:06:59 EDT
The difference with javac is that the addFirst bridge method in FilterChainImpl is not calling the right method:
  // Method descriptor #96 (Ljava/lang/String;Lp/IMessageFilter;)V
  // Stack: 3, Locals: 3
  public bridge synthetic void addFirst(String arg0, IMessageFilter arg1);
    0  aload_0 [this]
    1  aload_1 [arg0]
    2  aload_2 [arg1]
    3  invokespecial AbstractFilterChain.addFirst(String, IMessageFilter) : void [111]
    6  return
      Line numbers:
        [pc: 0, line: 1]


where javac is generating:
  // Method descriptor #62 (Ljava/lang/String;Lp/IMessageFilter;)V
  // Stack: 3, Locals: 3
  public bridge synthetic void addFirst(String arg0, IMessageFilter arg1);
    0  aload_0 [this]
    1  aload_1 [arg0]
    2  aload_2 [arg1]
    3  invokespecial AbstractFilterChain.addFirst(String, Object) : void [25]
    6  return
      Line numbers:
        [pc: 0, line: 5]

AbstractFilterChain is only defining:
`  // Method descriptor #75 (Ljava/lang/String;Ljava/lang/Object;)V
  // Signature: (Ljava/lang/String;TT;)V
  // Stack: 4, Locals: 3
  public void addFirst(String arg0, Object arg1);
     0  aload_0 [this]
     1  aload_1 [arg0]
     2  invokespecial AbstractFilterChain.checkFilter(String) : void [26]
     5  aload_0 [this]
     6  aload_0 [this]
     7  getfield AbstractFilterChain.head : AbstractFilterChain.Node [5]
    10  aload_1 [arg0]
    11  aload_2 [arg1]
    12  invokespecial AbstractFilterChain.registerFilter(AbstractFilterChain$Node, String, Object) : void [28]
    15  return
      Line numbers:
        [pc: 0, line: 96]
        [pc: 5, line: 97]
        [pc: 15, line: 98]

so we must generate the resolve signature to point to addFirst(Ljava/lang/String;Ljava/lang/Object;)V.
Comment 5 Srikanth Sankaran CLA 2010-10-21 04:05:24 EDT
Reduced single file test case:

public class X extends Y<I>  implements I {
    public static void main(String[] args) {
        ((I) new X()).foo(null);
    }
}

interface I {
    public void foo(I i);
}
 
abstract class Y<T> {
	   public void foo(T t) {}
}

-----------------

Under investigation.
Comment 6 Srikanth Sankaran CLA 2010-10-21 04:23:30 EDT
Interestingly, both the original test case and
the abbreviated test case pass alright on 1.5
compliance and fail only with 1.6 mode.
Comment 7 Srikanth Sankaran CLA 2010-10-21 05:44:48 EDT
Likely a side effect of bug 288658.
See that the problem goes away if
AbstractFilterChain is public instead
of being package private.
Comment 8 Srikanth Sankaran CLA 2010-10-21 06:16:25 EDT
Created attachment 181378 [details]
Patch under test

This patch fixes the problem. Under test.

Basically the target of the bridge method
introduced by the fix for bug 288658 is
incorrect in case of the inherited method
using type parameters and such. We should be
bridging to the "original" method in this
case.
Comment 9 Srikanth Sankaran CLA 2010-10-21 08:13:30 EDT
All tests pass. Olivier, please review. Do you want this for 3.6.2 ?
Comment 10 Srikanth Sankaran CLA 2010-10-22 00:30:03 EDT
Released in HEAD for 3.7 M3

Will decide about 3.6.2 after code review.
Comment 11 Olivier Thomann CLA 2010-10-22 07:45:40 EDT
(In reply to comment #9)
> All tests pass. Olivier, please review. Do you want this for 3.6.2 ?
Patch looks good and since there is no good workaround and the code doesn't run with it, yes I would be tempted to release into 3.6.2.
Daniel ?
Comment 12 Srikanth Sankaran CLA 2010-10-25 01:22:52 EDT
Released in 3.6.x maintenance stream for 3.6.2
Comment 13 Jay Arthanareeswaran CLA 2010-10-26 13:10:59 EDT
Verified for 3.7M3 using build I20101025-0901
Comment 14 Satyam Kandula CLA 2011-01-20 03:51:01 EST
Verified for 3.6.2 RC2 using build M20110119-0834