[rvm-core] modifiers may not necessary

View: New views
4 Messages — Rating Filter:   Alert me  

[rvm-core] modifiers may not necessary

by vondart :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
org.mmtk.utility.alloc.BumpPointer;
contains two fields,that I want to reset values. So I put into a subclass constructor, functions to assign new value to those fields. But this requires the fields not to be "static final".
Should the modifiers necessarily be there?

protected /*static final*/ int LOG_BLOCK_SIZE = LOG_BYTES_IN_PAGE + 3;
  protected /*static final*/ Word BLOCK_MASK = Word.one().lsh(LOG_BLOCK_SIZE).minus(Word.one());
 
DaFENG
Coder
Telecommunication && Network Industry
Pudong
Shanghai
China



------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Jikesrvm-core mailing list
Jikesrvm-core@...
https://lists.sourceforge.net/lists/listinfo/jikesrvm-core

Re: [rvm-core] modifiers may not necessary

by Eliot Moss :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Da Feng wrote:
> org.mmtk.utility.alloc.BumpPointer;
> contains two fields,that I want to reset values. So I put into a
> subclass constructor, functions to assign new value to those fields. But
> this requires the fields not to be "static final".
> Should the modifiers necessarily be there?
>
> protected /*static final*/ int LOG_BLOCK_SIZE = LOG_BYTES_IN_PAGE + 3;
>   protected /*static final*/ Word BLOCK_MASK =
> Word.one().lsh(LOG_BLOCK_SIZE).minus(Word.one());

Yes! If you want decent performance these should be static final.
I can;t say what the performance hit will be, but possibly
substantial. Note that if you want to change them in a subclass,
the subclass can use its own static final, and the usual scope
rules will give preference to those, in the subclass (IIRC the
Java semantics).

Do you think you want to change them dynamically? This could be
confusing and costly.

On the other hand, if you just want them to be different from the
default, either just change the 3 to some other value, or, it can
be a variable AT BUILD TIME that then sets the values when the
class is initialized.

Hope this helps; I expect others will have more to say ....

Best wishes -- Eliot Moss

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Jikesrvm-core mailing list
Jikesrvm-core@...
https://lists.sourceforge.net/lists/listinfo/jikesrvm-core

Re: [rvm-core] modifiers may not necessary

by Filip Pizlo-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Da Feng,

Though I've not performed a performance study on the implications of making these fields not be static final, I believe that you can do it - and you shouldn't see any performance impact.  Note that I'm not an expert on this code, either, so perhaps others will have more to say.  I may even be contradicted. :-)

Here's a little background on why you may have to be concerned about the performance implications: if the fields are static final, then the compiler will evaluate the fields' values (i.e. the expressions "LOG_BYTES_IN_PAGE + 3" and "Word.one().lsh(LOG_BLOCK_SIZE).minus(Word.one())") before the program even executes.  Any expressions over those fields may also be evaluated by the compiler.  So the relevant use of the BLOCK_MASK in allocSlowOnce:

blockSize = Word.fromIntZeroExtend(bytes).plus(BLOCK_MASK).and(BLOCK_MASK.not()).toExtent();

will be optimized to something like:

blockSize = (bytes + 32767) & -32768;

Where -32768 is a compile-time constant, reflecting BLOCK_MASK.not().  (Assuming that LOG_BLOCK_SIZE is LOG_BYTES_IN_PAGE+3, and LOG_BYTES_IN_PAGE is 12.)

If, on the other hand, the BLOCK_MASK field is not "static final", then this expression will require an additional load of BLOCK_MASK, and additional arithmetic to bitwise-not the BLOCK_MASK.  This may not seem like much but can make a huge difference if this is on the critical path.

But I do not believe that this method is on the critical path.  It's the non-inline slow path for allocation ... if you end up in this method you've already paid the price of a mispredicted branch, a non-inline call, and potentially other stuff.  So I would say, go ahead and make these fields instance rather than "static final", and go ahead and make them dynamically configurable.  Of course, you may have to worry about concurrency issues (like, if you change the value while someone else is allocating using the same BumpAllocator), but that may not come up if you are already ensuring that your use of BumpAllocator is thread-local.

-Filip




On Nov 1, 2009, at 10:24 , Da Feng wrote:

org.mmtk.utility.alloc.BumpPointer;
contains two fields,that I want to reset values. So I put into a subclass constructor, functions to assign new value to those fields. But this requires the fields not to be "static final".
Should the modifiers necessarily be there?

protected /*static final*/ int LOG_BLOCK_SIZE = LOG_BYTES_IN_PAGE + 3;
  protected /*static final*/ Word BLOCK_MASK = Word.one().lsh(LOG_BLOCK_SIZE).minus(Word.one());
 
DaFENG
Coder
Telecommunication && Network Industry
Pudong
Shanghai
China


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference_______________________________________________
Jikesrvm-core mailing list
Jikesrvm-core@...
https://lists.sourceforge.net/lists/listinfo/jikesrvm-core


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Jikesrvm-core mailing list
Jikesrvm-core@...
https://lists.sourceforge.net/lists/listinfo/jikesrvm-core

Re: [rvm-core] modifiers may not necessary

by vondart :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
I will try to write the code first, and finally optimize it.
 
DaFENG
Coder
Telecommunication && Network Industry
Pudong
Shanghai
China



From: Eliot Moss <moss@...>
To: Discussion of day-to-day development and design among JikesRVM core team members <jikesrvm-core@...>
Sent: Mon, November 2, 2009 2:44:10 AM
Subject: Re: [rvm-core] modifiers may not necessary

Da Feng wrote:
> org.mmtk.utility.alloc.BumpPointer;
> contains two fields,that I want to reset values. So I put into a
> subclass constructor, functions to assign new value to those fields. But
> this requires the fields not to be "static final".
> Should the modifiers necessarily be there?
>
> protected /*static final*/ int LOG_BLOCK_SIZE = LOG_BYTES_IN_PAGE + 3;
>  protected /*static final*/ Word BLOCK_MASK =
> Word.one().lsh(LOG_BLOCK_SIZE).minus(Word.one());

Yes! If you want decent performance these should be static final.
I can;t say what the performance hit will be, but possibly
substantial. Note that if you want to change them in a subclass,
the subclass can use its own static final, and the usual scope
rules will give preference to those, in the subclass (IIRC the
Java semantics).

Do you think you want to change them dynamically? This could be
confusing and costly.

On the other hand, if you just want them to be different from the
default, either just change the 3 to some other value, or, it can
be a variable AT BUILD TIME that then sets the values when the
class is initialized.

Hope this helps; I expect others will have more to say ....

Best wishes -- Eliot Moss

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Jikesrvm-core mailing list
Jikesrvm-core@...
https://lists.sourceforge.net/lists/listinfo/jikesrvm-core


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Jikesrvm-core mailing list
Jikesrvm-core@...
https://lists.sourceforge.net/lists/listinfo/jikesrvm-core