This is the mail archive of the
java-prs@gcc.gnu.org
mailing list for the Java project.
[Bug java/21855] array bounds checking elimination
- From: "aph at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: java-prs at gcc dot gnu dot org
- Date: Tue, 10 Jan 2012 16:26:51 +0000
- Subject: [Bug java/21855] array bounds checking elimination
- Auto-submitted: auto-generated
- References: <bug-21855-8172@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21855
--- Comment #16 from Andrew Haley <aph at gcc dot gnu.org> 2012-01-10 16:26:51 UTC ---
(In reply to comment #15)
> (In reply to comment #14)
> > (In reply to comment #13)
> > > We can't optimize this because System.out.println can change args[].
> >
> > That's the whole point: System.out.println cannot change args[], which is a
> > java array, and the length of a Java array is constant. It is not an invalid
> > test case.
>
> I suppose
>
> public static void main(String[] args)
>
> is passing args by value (but the implementation detail uses reference
> passing for efficiency?).
args is indeed a reference to a Java array. The length field of a Java
array is immutable. The elements of an array are not immutable.
> In this case the Java frontend should do
> like the C++ frontend and tell this to the middle-end by properly
> marking args as 1) DECL_BY_REFERENCE, 2) use a TYPE_RESTRICT qualified
> pointer for the reference. Then we would optimize this case.
If we could mark the length field as immutable that would fix it. Is there any
way to do that?