Java & aliasing question

Bryce McKinlay bryce@waitaki.otago.ac.nz
Mon Jan 28 10:24:00 GMT 2002


Consider:

class A
{
  int a;
  int b;
}

class B
{
  int a = 5;
}

class Alias
{
  void foo(A a, B b)
  {
    a.a = b.a;
    a.b = b.a;
  }
}

In Java, incompatible types like A and B can never alias each other, yet 
we currently generate code that assumes they could:

Alias::foo(A*, B*):
    lwz 0,4(5)
    stw 0,4(4)
    lwz 9,4(5)
    stw 9,8(4)
    blr

If the Java front end implements lang_hooks.get_alias_set(), can gcc 
eliminate the redundant load?

Further, given something like:

class A {}
class B extends A {}
class C extends A {}

an "A" could alias either a "B" or a "C", but a "B" can't alias a "C" 
simply because they cannot possibly point to the same object. Is it 
possible for gcj to express this to the aliasing code? Even better, 
could it operate on the individual elements, so that only fields 
declared in A would be considered aliasing?

regards

Bryce.




More information about the Gcc mailing list