Bug 12911 - Class initialization optimization pessimization
Summary: Class initialization optimization pessimization
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 3.4.0
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: missed-optimization
Depends on: 15576
  Show dependency treegraph
Reported: 2003-11-05 14:36 UTC by Anthony Green
Modified: 2006-03-05 03:50 UTC (History)
4 users (show)

See Also:
Known to work:
Known to fail: 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1 3.1.1 3.1.2 3.2 3.2.1 3.2.2 3.2.3 3.3 3.3.1 3.3.2 3.3.3 3.4.0 4.0.0
Last reconfirmed: 2006-03-05 03:50:41


Note You need to log in before you can comment on or make changes to this bug.
Description Anthony Green 2003-11-05 14:36:40 UTC
It would be nice to fix a class init optimization problem.  The compiler
should recognize that calls to constructors and calls to static methods
always initialize the called class, so we can force our
class-init-tracking local flag to `true' whenever we do these.  

public class A
  // This method should never call _Jv_InitClass on B.
  public int foo ()
    B b = new B();
    return B.bar;

  // Neither should this.
  public int foo2 ()
    return B.bar;

public class B
  public static int plus6(int x) { return x + 6; }
  public static int bar = 555;
Comment 1 Andrew Pinski 2003-11-05 14:48:55 UTC
Comment 2 Andrew Haley 2005-04-16 16:45:08 UTC
*** Bug 21044 has been marked as a duplicate of this bug. ***
Comment 3 Andrew Haley 2005-05-03 13:34:40 UTC
I'm tempted to change this to WONTFIX.

The patch for PR java/19285 party fixes this for indirect dispatch: in A.foo2(),
 the field B.bar is initialized by a call to _Jv_ResolvePoolEntry, and this is
only called once, the first time A.foo2() is invoked.

Granted, this only applies to the indirect dispatch (a.k.a. the "new ABI") case.
 However, optimizing known incorrect behaviour doesn't seem like a good use of
anyone's time.

Because of the binary compatibility rules we can't assume that B.bar will always
be a field of B; it might be a field of one of B's interfaces.  Initializing B
won't initialize its interfaces, so this code will fail.