Current Status

Jeff Sturm jsturm@sigma6.com
Wed Feb 17 12:30:00 GMT 1999


Hans Erik Martino Hansen wrote:
> 
> On Wed, Feb 17, 1999 at 09:31:40AM -0500, Jeff Sturm wrote:
> > You can't inline across class boundaries to be sure... but private
> > methods are normally safe to inline.  They are common enough to be a
> > worthwhile optimization.
> 
> It is only when compiling to .class files you cannot inline across
> class boundaries. Example
> 
> class A {
>   void f() { do this and do that; }
> }
> 
> class B {
>   void f() { A a = new A(); a.f(); }
> }
> 
> When calling a.f() we know exactly what f is being called, it cannot
> be overrided by subclassing A. And in contrary to compiling to .class
> files A cannot be recompiled either. No dynamic linking here. So we
> can just as well inline it.

But what if class A has private fields, e.g.:

class A {
  private int x;
  void f() { x = 0; }
}

Then it would be illegal for B to inline A.f() since the bytecode would
be accessing a private member outside of its enclosing class.

-- 
Jeff Sturm
jsturm@sigma6.com


More information about the Java mailing list