Bug 235004 - [compiler] Misleading compiler warning
Summary: [compiler] Misleading compiler warning
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.5 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-31 17:00 EDT by Alexander Veit CLA
Modified: 2008-08-06 12:58 EDT (History)
2 users (show)

See Also:


Attachments
Proposed patch (38.41 KB, patch)
2008-06-03 19:15 EDT, 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 Alexander Veit CLA 2008-05-31 17:00:57 EDT
Build ID: Build id: I20070625-1500

Steps To Reproduce:
The Eclipse compiler reports the problem

"Read access to enclosing field SyntheticAccessorTest.m_iPrivateCnt is emulated by a synthetic accessor method. Increasing its visibility will improve your performance"

As the attached class suggests, there are no performance problems at all since modern (JIT) compilers seem to produce the same optimized code regardless of how the enclosing member is accessed.

So there's no need to force people to violate good OOP practices in favour of gaining performance.

More information:
Use this test program

D:\>java -version
java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing

javac -g:none performance/SyntheticAccessorTest.java

java performance.SyntheticAccessorTest
 or
java -XX:CompileThreshold=0 performance.SyntheticAccessorTest

- - - - - - - - - - - - - - - - - - - - - - - -
package performance;

public final class SyntheticAccessorTest
{
 private int m_iPrivateCnt;

 protected int m_iProtectedCnt;


 private SyntheticAccessorTest() {}


 public static void main(String[] args)
 {
  new SyntheticAccessorTest().run(1000000);

  Thread.yield();

  long l_lPrivate   = 0L;
  long l_lProtected = 0L;

  for (int i = 0; i < 100; i++)
  {
   final long[] l_result;

   l_result = new SyntheticAccessorTest().run(10000000);

   l_lPrivate   += l_result[0];
   l_lProtected += l_result[1];
  }

  System.out.println("private:   " + (l_lPrivate / 1000) + " us");
  System.out.println("protected: " + (l_lProtected / 1000) + " us");
 }


 private long[] run(final int p_iLoops)
 {
  final long l_lStartPrivate;
  final long l_lEndPrivate;
  final long l_lStartProtected;
  final long l_lEndProtected;

  // private
  m_iPrivateCnt   = 0;
  l_lStartPrivate = System.nanoTime();

  new Runnable()
  {
   @Override
   public void run()
   {
    for (int i = 0; i < p_iLoops; i++)
     m_iPrivateCnt++;
   }
  }.run();

  l_lEndPrivate = System.nanoTime();

  // protected
  m_iProtectedCnt   = 0;
  l_lStartProtected = System.nanoTime();

  new Runnable()
  {
   @Override
   public void run()
   {
    for (int i = 0; i < p_iLoops; i++)
     m_iProtectedCnt++;
   }
  }.run();

  l_lEndProtected = System.nanoTime();
  assert m_iProtectedCnt == p_iLoops;

  return new long[] {l_lEndPrivate - l_lStartPrivate, l_lEndProtected - l_lStartProtected};
 }
}
Comment 1 Philipe Mulet CLA 2008-06-02 11:40:54 EDT
This is indeed true for speed nowadays, which is a good evolution. Still it makes class files bigger. I agree the error message sounds a bit too harsh, it should stop mentioning performance ramifications.
Comment 2 Philipe Mulet CLA 2008-06-02 11:44:41 EDT
Also applications running in pure interpreted mode (no JIT) are slowed by such emulation
Comment 3 Philipe Mulet CLA 2008-06-03 19:15:23 EDT
Created attachment 103466 [details]
Proposed patch
Comment 4 Philipe Mulet CLA 2008-06-03 19:17:53 EDT
Message catalog is not changeable before next release (for translation purpose).
Comment 5 Alexander Veit CLA 2008-06-08 07:46:21 EDT
If I understand your patch correctly, the warning messages were changed.

From the standpoint of the compiler architects this may make sense. From an application programmer's point of view it is probably a useless warning.

BTW, Eclipse's problems view will still be flooded with hundreds of synthetic accessor warnings. This makes switching between projects in the same workspace very slow and may hide more serious warnings. Unfortunately I could not find a switch to turn these warnings off. Please provide such a switch.
Comment 6 Philipe Mulet CLA 2008-06-09 03:11:52 EDT
See preferences under:
Java Compiler>Errors/Warnings>Code style>Access to non-accessible member of an enclosing type

This warning is OFF by default.
Comment 7 Philipe Mulet CLA 2008-06-23 11:52:03 EDT
Released message change for 3.5M1
Fixed
Comment 8 Kent Johnson CLA 2008-08-06 12:58:24 EDT
Verified for 3.5M1 using I20080805-1307