How to add a new intrinsic

Jaromir Hamala jaromir.hamala at gmail.com
Sun Nov 9 20:38:48 UTC 2014


Hi Aleksey,

thanks again for your feedback & help! I'm working on C1 right now and your
examples made it way easier for me. I'll sort out the OCA thing.

Cheers,
Jaromir



On Sun, Nov 9, 2014 at 7:48 PM, Aleksey Shipilev <
aleksey.shipilev at oracle.com> wrote:

> Hi Jaromir,
>
> On 11/09/2014 09:53 PM, Jaromir Hamala wrote:
> > I do not have ambitions to include it in OpenJDK,
>
> Why not? Please follow the step 0 from here:
> http://openjdk.java.net/contribute/ -- submit the OCA.
>
>
> > but I greatly appreciate any feedback / help. I guess the next step
> > for me is to include C1 and eventually C2 support - again - any
> > pointers are very highly appreciated!
>
> This may be a shortest example for simple Unsafe intrinsic handled in
> interpreter, C1 and C2 (notice how much shorter the interpreter code is,
> since we "just" use the native methods as interpreter handlers):
>   http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/ad6097d547e1
>   http://hg.openjdk.java.net/jdk8/jdk8/hotspot/rev/1e41b0bc58a0
>
>
> IIRC, for C1, you would need to:
>
>  1) Handle the intrinsic in LIRGenerator::do_Intrinsic
> (c1_LIRGenerator.cpp), it should add the nodes to C1 IR, see e.g.
> membar_acquire(). You will have to create a new LirOp, with 0 arguments,
> in LIR_Code enum, say, "lir_pause".
>
>  2) Lower the lir_pause to machine code in LIR_Assembler::emit_op0 (see
> c1_LIRAssembler.cpp). There should be a call to macro-assembler defining
> the PAUSE instruction.
>
>
> For C2, you would need to:
>
>  1) Add the intrinsic definitions and intrinsic code into
> library_call.cpp/hpp. It would be easier to follow the code for some
> already-existing simple intrinsic, see e.g. inline_unsafe_prefetch. Your
> code should emit a new, special-named IR node, say, PauseNode.
>
>  2) Add the matching rule for PauseNode into architecture description
> file (x86_32.ad or x86_64.ad). This file matches the IR node to the
> concrete machine code to emit. It is usually macroed into assembler
> call. E.g. PrefetchRead node with mem argument is matched to
> Assembler::prefetchr in assembler_x86.cpp. There, the exact machine code
> is emitted.
>
>
> I think this is enough to make a working example.
>
> -Aleksey.
>
>


-- 
“Perfection is achieved, not when there is nothing more to add, but when
there is nothing left to take away.”
Antoine de Saint Exupéry


More information about the hotspot-dev mailing list