Can access by local method variables be faster then access by member variables ?
Ulf Zibis
Ulf.Zibis at gmx.de
Fri Aug 15 17:08:25 PDT 2008
Thanks for your answer.
It's hard to follow for me in detail. What's C1 and C2 ?
-Ulf
Am 16.08.2008 01:16, Tom Rodriguez schrieb:
> What pushes and pops are you talking about? You should consider stack
> and local variable access to be completely free when any reasonable
> JIT is involved. The bytecodes that operate on the stack and locals
> don't correspond to any code that it's emitted by C1 or C2.
> Operations on member variables are definitely not free, though
> depending on how good your JIT is it may be able to reduce the number
> of actuals loads and stores that are issued. In general though the
> number issued will never become zero. C2 is fairly good at this and
> C1 does ok for simple cases but doesn't include any loop optimizations
> so it will be much less efficient for loopy code like you're showing.
>
> Basically the revision 302 code could be transformed into the revision
> 291 by a good compiler. 291 will definitely run faster with C1
> because it doesn't have any loop optimizations around memory
> operations. C2 might be able to reproduce equivalent code, though I'm
> not positive it can delay the stores implied by the srcPos++ dstPos++
> until the whole loop has completed.
>
> tom
>
> On Aug 15, 2008, at 3:02 PM, Ulf Zibis wrote:
>
>> Hi experts,
>>
>> to avoid stack push + pop of src, dst I have refactored my code in
>> moving the local method variables (sp, ...) to member variables
>> (srcPos, ...).
>>
>> After this I have experienced that my code was little slower.
>>
>> For full source code see:
>> https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/trunk/src/sun/nio/cs/SingleByteEncoder.java?rev=291&view=markup
>>
>> https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/trunk/src/sun/nio/cs/SingleByteEncoder.java?rev=302&view=markup
>>
>>
>> ======================================== revisions 291
>> ========================================
>>
>> private CoderResult encodeArraysLoop(CharBuffer src, ByteBuffer dst) {
>> char[] sa = src.array();
>> int sp = src.arrayOffset() + src.position();
>> int sl = src.arrayOffset() + src.limit();
>> assert (sp <= sl);
>> byte[] da = dst.array();
>> int dp = dst.arrayOffset() + dst.position();
>> int dl = dst.arrayOffset() + dst.limit();
>> assert (dp <= dl);
>> try {
>> for (; sp < sl; sp++) {
>> current = sa[sp];
>> byte b = encodeSingle();
>> if (dp >= dl)
>> return CoderResult.OVERFLOW;
>> da[dp++] = b;
>> }
>> return CoderResult.UNDERFLOW;
>> } catch (UnmappableCharacterException e) {
>> if (Surrogate.isLow(current) || current >= '\uFFFE')
>> return CODERRESULT_MALFORMED;
>> if (Surrogate.isHigh(current))
>> try {
>> if (sp+1 >= sl)
>> return CoderResult.UNDERFLOW;
>> encodeSurrogate(sa[sp+1]);
>> } catch (UnmappableCharacterException e2) {
>> return CODERRESULT_UNMAPPABLE2;
>> } catch (MalformedInputException e2) {
>> return CODERRESULT_MALFORMED2;
>> }
>> return CODERRESULT_UNMAPPABLE;
>> } finally {
>> src.position(sp - src.arrayOffset());
>> dst.position(dp - dst.arrayOffset());
>> }
>> }
>>
>> ======================================== revisions 302
>> ========================================
>>
>> private CoderResult encodeArraysLoop() throws RuntimeException,
>> UnmappableCharacterException {
>> for (; srcPos < srcLimit; srcPos++) {
>> current = srcArray[srcPos];
>> byte b = encodeSingle();
>> if (dstPos < dstLimit)
>> dstArray[dstPos++] = b;
>> else
>> return CoderResult.OVERFLOW;
>> }
>> return CoderResult.UNDERFLOW;
>> }
>>
>> ===============================================================================================
>>
>>
>>
>> Thanks for your explanations,
>>
>> Ulf
>>
>>
>>
>>
>
>
More information about the hotspot-dev
mailing list