This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR java/15576, class initialization optimization disable


Andrew Pinski writes:
 > This patch cleans up a little the class initialization and fixes
 > it so that it works with the tree-ssa/gimplifier.  What needed
 > to be done was to add a DECL_EXPR for the decl so that the
 > initializer was expanded and also we needed to ignore DECL_EXPR
 > in check_init as nobody else in the java front-end uses it and
 > the variable was only a scaler type with a constant initializer.
 > 
 > I also think this optimization can now be turned on for class file
 > to native compiling as we now do it function at a time compiling for
 > them (I think we don't do unit-at-a-time yet though) but that is for
 > another patch.
 > 
 > Built on powerpc-darwin.  I am in the middle of testing it. OK if
 > everthing passes?

OK, thanks, but it doesn't totally fix the bug.

The problem with this is that it does the optimization before
inlining, whereas it really needs to be done after.  Otherwise,
something like this:

class v
{
  static int m;

  static
  {
    m = Integer.getInteger((String)null).intValue();
  }
}


public class t
{
  static final int nn()
  {
    return v.m;
  }


  public static void main (String[] argv)
  {
    int n = 0;
    for (int i = 0; i < 1000; i++)
      n += nn();
  }
}


ends up calling _Jv_InitClass (&v.class) inside the loop.  This is
what we get:


t.main(java.lang.String[]) (argv)
{
  unsigned int D.836;
  int i;

<bb 0>:
  _Jv_InitClass (&t.class);
  i = 0;

<L1>:;
  _Jv_InitClass (&t.class);
  _Jv_InitClass (&v.class);

;
  D.836 = (unsigned int) i + 1;
  i = (int) D.836;
  if (D.836 == 1000) goto <L7>; else goto <L1>;

<L7>:;
  return;

}

The pre - tree SSA version of this code ran after inlining, thus
hoisting class initialization out of loops.

In the absence of inlining, however, this patch is fine.  Please check
it in.

Thanks,
Andrew.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]