questions on Word operations

Christian Wimmer christian.wimmer at oracle.com
Fri Sep 13 10:19:05 PDT 2013


All functions on word types (everything implementing the interface 
WordBase) are compiler intrinsics. If you use Word in a snippet, and 
call one of the methods on it, the body of these methods is actually 
irrelevant. The only thing that matters is how the WordTypeRewriterPhase 
replaces the method call with low-level compiler nodes. The @Operation 
annotation is used by the WordTypeRewriterPhase to distinguish what to do.

Word only provides the very basic arithmetic and memory operations (+, 
-, * , /, read, write).  Adding methods for atomic operations like you 
want is possible, but I don't think it is the easiest way to achieve 
what you want to do.

Can you explain what your final goal is?

-Christian


On 09/13/2013 09:47 AM, Deneau, Tom wrote:
> I would like to add a new Word method that can be used from an allocation Snippet I am trying to write.
>
> The new method would look like:
>
> 	public Word atomicGetAndAddWord(int offset, int delta) {
>
> 	}
>
> So given a Word (address), this would do an atomic get and add of delta on the word located at the address this.rawValue + offset.  Like j.u.c.atomic.getAndAdd, it would return the original word value at that address.
>
> A couple of questions:
>
>     *  Is the following a legal body for such a method?  I see that it compiles but is it legal to call toObject() on a Word value?  As used in the snippet the Word value would be the pointer returned by thread().  I noticed there is no unsafe.getAndAddLong(long address, long delta), only unsafe.getAndAddLong(Object o, long offset, long delta)
>
>             return box(unsafe.getAndAddLong(toObject(), offset, delta));
>
>     *  I notice all the Word methods have @Operation annotations but I don't really understand the semantics of this annotation.  What should be the annotation for this method?
>
>
>     *  What is the purpose of the locationIdentity parameter on some of the word operations such as
>
>         @Operation(opcode = Opcode.READ)
>         public Word readWord(WordBase offset, LocationIdentity locationIdentity) {
>             return box(unsafe.getAddress(add((Word) offset).unbox()));
>         }
>
> -- Tom
>


More information about the graal-dev mailing list