java aliasing rules

Tom Tromey tromey@redhat.com
Wed Mar 27 13:53:00 GMT 2002


>>>>> "Dan" == Dan Nicolaescu <dann@godzilla.ICS.UCI.EDU> writes:

Dan> Given this code:
Dan> class first  {  int i; char a;  char f1;  char f2; double d;};
Dan> class second {  char b;  char f2;  int f3;};

Dan> public class t
Dan> {
Dan>     public  void f (first  ps1, second ps2)
Dan>     {
Dan>         ps1.f1++;
Dan>         ps2.f2++;
Dan>         ps1.f1++;
Dan>         ps2.f2++;
Dan>     }
Dan> }

Dan> can it be assumed that given that "first" and "second" are
Dan> incompatible

Yes.

Dan> The more general question is if 2 COMPONENT_REFs that refer to
Dan> classes that are in conflicting alias sets (ie
Dan> alias_sets_conflict_p) alias in java. I have a hunch that this
Dan> might be true, but I don't know enough about java to be sure.  If
Dan> the above is not true, is there a restricted case when it is
Dan> true?

My understanding, and please if you don't mind clear things up if I'm
wrong, is that each front end is free to write its own aliasing
function.  And as far as I know gcj doesn't have one.  So I don't know
how conflicting alias sets for Java are currently computed, but I
imagine it is just very conservative and doesn't follow the language
rules.

Better aliasing support is definitely something we'd like.  It's on my
to-do list (and, I'd wager, Bryce's), but I haven't had time to look
at it.

Anyway, in Java, casts are *always* done according to the type system.
There is no way to circumvent it.  So in your above example, it is
never possible to turn a `first' into a `second' -- they are not
compatible.

Does this answer your questions?

Tom



More information about the Java mailing list