gcj internals documentation

David Daney ddaney@avtrex.com
Wed Oct 11 16:59:00 GMT 2006


Tom Tromey wrote:
> Paul> It looks like synchronization removal can simply be done by removing
> Paul> these function calls in cases where the object doesnt escape. Does
> Paul> this sound right?
>> Yes.
>> Paul> How does this all relate the the StringBuilder/StringBuffer problem?
> Paul> Assuming I have working inter-procedural escape analysis, how do I go
> Paul> about fixing the problems described in
> Paul> http://gcc.gnu.org/ml/java/2005-10/msg00006.html?
>> It all depends on which cases you want to solve.
>> The simplest case is dealing with StringBuilder. Suppose you can
> determine that a given StringBuilder does not escape from the method
> where it is created, and furthermore that the object is no longer used
> after toString is called.
>> In this situation we could replace the call to toString with a call to
> some as-yet-unwritten method (or plain old _Jv_something function --
> this avoids troublesome access control checks in the BC case). This
> new method would transfer ownership of the StringBuilder's char[] to
> the new String, avoiding an allocation.
>>> A more complicated optimization along the same lines would be to
> automatically replace StringBuffer with StringBuilder when the same
> conditions hold. This sort of thing is common in 1.4 code (in 1.5 I
> think String "+" operations are generally translated to StringBuilder
> instead) and also on occasion in hand-written code.
>
FWIW, I have been thinking that this type of transform might be best 
done at the stage where the byte code is being converted to trees rather 
than in the middle end with the gimplefied/tree-ssa form. Perhaps in 
conjunction with the bytecode verifier (which already has to do analysis 
on the bytcodes).
I say this because I once attempted to write an tree-ssa optimizer to do 
this exact special case. The attempt failed because I could not figure 
out how to convert the type of the object (from 
java.lang.String[Buffer|Builder] to gnu.gcj.runtime.StringBuffer) in a 
manner that maintained the required consistency in the tree. Perhaps a 
person with more experience with tree-ssa would have been successful.
David Daney.


More information about the Java mailing list

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