class initialization check overhead

Anthony Green green@redhat.com
Thu Oct 24 05:34:00 GMT 2002


On Thu, 2002-10-24 at 02:10, C. van Reeuwijk wrote:
> - If a class has an empty init, change it to a superclass init (repeat).
> - Eliminate inits of java.lang.Object (since it's empty).
> - Within a method, keep track of the classes already initialized,
> and don't initialize a class again if you know for sure that it, or a
> subclass, has already been initialized.

I know we used to do this (without the subclass trick), by generating
something like the following for "x = foo.bar.y"...

  int _foo_bar__initialized_p = 0; // once per method

  if (! _foo_bar__initialized_p)  // each reference would do this
  {
    initialize foo.bar
    _foo_bar_initialized_p = 1;
  }
  x = foo.bar.y;

The compiler's normal optimizations will remove useless initializations,
and even eliminate _foo_bar__initialized_p from the final output. 
However, I believe this was changed somehow since the original
implementation.  To what, I don't recall.

apbianco once suggested also annotating the .class files with notes on
which classes each method guaranteed to initialize.

> - Inline small inits.


AG




More information about the Java mailing list