Help with generating library call

Rohit Arul Raj rohitarulraj at
Wed Aug 2 15:32:23 UTC 2017

On Mon, Jul 31, 2017 at 1:48 PM, Andrew Haley <aph at> wrote:
> On 31/07/17 05:33, Rohit Arul Raj wrote:
>> Can any one point me in the right direction? Any reference to similar
>> implementation of any other C or Math library function will be
>> helpful?
>> I ended up doing the following, but not sure if this is the right way
>> to go about it.
>> push (c_rarg2);
>> push (c_rarg1);
>> push (c_rarg0);
>> call_VM_leaf(CAST_FROM_FN_PTR(address, memset),3);
> This doesn't look totally wrong.
> There are many examples in the source.  For example, look at any calls
> to MacroAssembler::call_VM and call_VM_leaf.  Be aware, however, that
> if you're calling this from compiled code most registers are live so
> you're going to have to be extremely careful to save and restore them.
> One of the advantages of using HotSpot's builtins for zeroing is that
> we can know exactly which registers are used.
> --
> Andrew Haley
> Java Platform Lead Engineer
> Red Hat UK Ltd. <>
> EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671

Thanks Andrew, I managed to generate the required instructions. But
while generating the code (from the interpreter), the instructions are
getting re-ordered. Is there a way to generate a sequence of
instructions without breaking the chain?

Any suggestions?

   push (base_ptr);
    push (c_rarg0);
    push (c_rarg1);
    push (c_rarg2);

    if (base_ptr != c_rarg0)
      if (base_ptr != c_rarg2) {
        movq(c_rarg0, base_ptr);
        if (cnt_dwords != c_rarg2)
          movq(c_rarg2, cnt_dwords);
      else {
        if (cnt_dwords != c_rarg2)
          movq(c_rarg2, cnt_dwords);
        movq(c_rarg0, base_ptr);
    else {
      if (cnt_dwords != c_rarg2)
        movq(c_rarg2, cnt_dwords);

    addq(c_rarg0, disp);
    xorl (c_rarg1, c_rarg1);

    call_VM_leaf(CAST_FROM_FN_PTR(address, memset), c_rarg0, c_rarg1, c_rarg2);
    pop (c_rarg2);
    pop (c_rarg1);
    pop (c_rarg0);
    pop (base_ptr);


More information about the hotspot-dev mailing list