java aliasing rules

Dan Nicolaescu dann@godzilla.ICS.UCI.EDU
Wed Mar 27 16:03:00 GMT 2002


Tom Tromey <tromey@redhat.com> writes:
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?
Tom> My understanding, and please if you don't mind clear things up if I'm
Tom> wrong, is that each front end is free to write its own aliasing
Tom> function. And as far as I know gcj doesn't have one. So I don't know
Tom> how conflicting alias sets for Java are currently computed, but I
Tom> imagine it is just very conservative and doesn't follow the language
Tom> rules.
Yes, a language can define it's own alias set function, if it doesn't
alias sets will be computed based on the contents of the type. 
For example 
class one {int i;};
class two {int i;};
will be put in the same alias set even though, AFAIK, they are not
compatible. 
Tom> Better aliasing support is definitely something we'd like. It's on my
Tom> to-do list (and, I'd wager, Bryce's), but I haven't had time to look
Tom> at it.
IMHO this might be as simple as a < 5 lines function (but I might be
wrong...)
Dealing with the the example above will take you a long way (I'd be
glad to help if you need it).
But all this is unrelated to my question. 
In my first mail the "first" and "second" were already in different
alias sets. 
Tom> Anyway, in Java, casts are *always* done according to the type system.
Tom> There is no way to circumvent it. So in your above example, it is
Tom> never possible to turn a `first' into a `second' -- they are not
Tom> compatible.
Tom> 
Tom> Does this answer your questions?
Yes, this is exactly I wanted to know. 
Could you test the following hack (I'll create a proper langhook
later) on a big java program and see if it makes a difference? 
(it made cc1 1% smaller, and I expect even more on java). 
Just set the COMPONENT_REF_ALIAS environment variable and recompile
the program... 
Index: alias.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/alias.c,v
retrieving revision 1.167
diff -c -3 -p -c -r1.167 alias.c
*** alias.c	2002年03月11日 18:01:53	1.167
--- alias.c	2002年03月27日 23:48:58
*************** nonoverlapping_component_refs_p (x, y)
*** 1810,1815 ****
--- 1855,1887 ----
 {
 tree fieldx, fieldy, typex, typey, orig_y;
 
+ /* Component refs that belong to structures that are known not to
+ alias, don't alias. */
+ if (getenv ("COMPONENT_REF_ALIAS"))
+ {
+ typex = DECL_CONTEXT (TREE_OPERAND (x, 1));
+ typey = DECL_CONTEXT (TREE_OPERAND (y, 1));
+ if (typex != NULL && typey != NULL
+ && TREE_CODE (typex) == RECORD_TYPE
+ && TREE_CODE (typey) == RECORD_TYPE 
+ && ! alias_sets_conflict_p (get_alias_set (typex),
+ get_alias_set (typey)))
+ {
+ return 1;
+ }
+ 
+ }
 do
 {
 /* The comparison has to be done at a common type, since we don't


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /