[DTrace-devel] [PATCH] test: Add tests on register management for strjoin()

Eugene Loh eugene.loh at oracle.com
Mon May 22 20:31:44 UTC 2023


ping

On 10/18/22 16:33, eugene.loh at oracle.com wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
>
> The current register management in the code generator needs overhaul.
> Here are some tests to check operations in strjoin().  Some of these
> tests are marked @@xfail until the overhaul has been done.
>
> For example, here is what happens in tst.reg_spilling5.d.
>
> The D script is:
>
>    trace(strjoin("abc",
>                  strjoin("def",
>                          strjoin("ghi",
>                                  strjoin("jkl",
>                                          strjoin("mno",
>                                                  "pqrstuvwx"
>                                                 )
>                                         )
>                                 )
>                         )
>                 )
>         );
>
> The generated code basically does this:
>      r8 = pointer to "abc"
>      r7 = pointer to "def"
>      r6 = pointer to "ghi"
>      r5 = pointer to "jkl"
>      r4 = pointer to "mno"
>      r3 = pointer to "pqrstuvwx"
>
> Then it does the innermost strjoin:
>      r2 = pointer to tstring(0)
>      spill %r2
>      spill %r3
>      spill %r4
>      spill %r5
>      dt_strjoin(tstring(0), "mno", "pqrstuvwx");
>      restore %r2
>      restore %r5
>
> Then it starts the next strjoin:
>      r4 = pointer to tstring(1)
>      spill %r2
>      spill %r4
>      spill %r5
>
> Next, it must fill the arguments for the dt_strjoin(dst, s1, s2) call.
> It uses the following code from dt_cg_subr_strjoin():
>      BPF_MOV_REG(BPF_REG_1, dnp->dn_reg);
>      BPF_MOV_REG(BPF_REG_2, s1->dn_reg);
>      dt_regset_free(s1->dn_reg);
>      BPF_MOV_REG(BPF_REG_3, s2->dn_reg);
>      dt_regset_free(s2->dn_reg);
>
> At this point, however:
>      r4  is  dst
>      r5  is  s1
>      r2  is  s2
> So the code is:
>      r1 = r4        // loads dst into r1, okay
>      r2 = r5        // loads s1 into r2, but overwrites s2!
>      fill r5        // okay, we do not care
>      r3 = r2        // uses overwritten value!
>      fill r2        // overwrites a function arg!
>
> Careful register management in dt_cg_subr_strjoin() could fix this
> problem, but resolution will be left for the larger overhaul.
>
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
> ---
>   test/unittest/codegen/tst.reg_spilling2.d | 23 ++++++++++++++++
>   test/unittest/codegen/tst.reg_spilling2.r |  1 +
>   test/unittest/codegen/tst.reg_spilling3.d | 25 ++++++++++++++++++
>   test/unittest/codegen/tst.reg_spilling3.r |  1 +
>   test/unittest/codegen/tst.reg_spilling4.d | 27 +++++++++++++++++++
>   test/unittest/codegen/tst.reg_spilling4.r |  1 +
>   test/unittest/codegen/tst.reg_spilling5.d | 30 +++++++++++++++++++++
>   test/unittest/codegen/tst.reg_spilling5.r |  1 +
>   test/unittest/codegen/tst.reg_spilling6.d | 32 +++++++++++++++++++++++
>   test/unittest/codegen/tst.reg_spilling6.r |  1 +
>   test/unittest/codegen/tst.reg_spilling7.d | 32 +++++++++++++++++++++++
>   test/unittest/codegen/tst.reg_spilling7.r |  1 +
>   12 files changed, 175 insertions(+)
>   create mode 100644 test/unittest/codegen/tst.reg_spilling2.d
>   create mode 100644 test/unittest/codegen/tst.reg_spilling2.r
>   create mode 100644 test/unittest/codegen/tst.reg_spilling3.d
>   create mode 100644 test/unittest/codegen/tst.reg_spilling3.r
>   create mode 100644 test/unittest/codegen/tst.reg_spilling4.d
>   create mode 100644 test/unittest/codegen/tst.reg_spilling4.r
>   create mode 100644 test/unittest/codegen/tst.reg_spilling5.d
>   create mode 100644 test/unittest/codegen/tst.reg_spilling5.r
>   create mode 100644 test/unittest/codegen/tst.reg_spilling6.d
>   create mode 100644 test/unittest/codegen/tst.reg_spilling6.r
>   create mode 100644 test/unittest/codegen/tst.reg_spilling7.d
>   create mode 100644 test/unittest/codegen/tst.reg_spilling7.r
>
> diff --git a/test/unittest/codegen/tst.reg_spilling2.d b/test/unittest/codegen/tst.reg_spilling2.d
> new file mode 100644
> index 00000000..494880d5
> --- /dev/null
> +++ b/test/unittest/codegen/tst.reg_spilling2.d
> @@ -0,0 +1,23 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
> + * Licensed under the Universal Permissive License v 1.0 as shown at
> + * http://oss.oracle.com/licenses/upl.
> + */
> +
> +/*
> + * ASSERTION: Test that the code generator's spill/fill works with strjoin().
> + */
> +
> +#pragma D option quiet
> +
> +BEGIN
> +{
> +  trace(strjoin("abc",
> +                strjoin("def",
> +                        "ghijklmnopqrstuvwx"
> +                       )
> +               )
> +       );
> +  exit(0);
> +}
> diff --git a/test/unittest/codegen/tst.reg_spilling2.r b/test/unittest/codegen/tst.reg_spilling2.r
> new file mode 100644
> index 00000000..588efd11
> --- /dev/null
> +++ b/test/unittest/codegen/tst.reg_spilling2.r
> @@ -0,0 +1 @@
> +abcdefghijklmnopqrstuvwx
> diff --git a/test/unittest/codegen/tst.reg_spilling3.d b/test/unittest/codegen/tst.reg_spilling3.d
> new file mode 100644
> index 00000000..ff219d75
> --- /dev/null
> +++ b/test/unittest/codegen/tst.reg_spilling3.d
> @@ -0,0 +1,25 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
> + * Licensed under the Universal Permissive License v 1.0 as shown at
> + * http://oss.oracle.com/licenses/upl.
> + */
> +
> +/*
> + * ASSERTION: Test that the code generator's spill/fill works with strjoin().
> + */
> +
> +#pragma D option quiet
> +
> +BEGIN
> +{
> +  trace(strjoin("abc",
> +                strjoin("def",
> +                        strjoin("ghi",
> +                                "jklmnopqrstuvwx"
> +                               )
> +                       )
> +               )
> +       );
> +  exit(0);
> +}
> diff --git a/test/unittest/codegen/tst.reg_spilling3.r b/test/unittest/codegen/tst.reg_spilling3.r
> new file mode 100644
> index 00000000..588efd11
> --- /dev/null
> +++ b/test/unittest/codegen/tst.reg_spilling3.r
> @@ -0,0 +1 @@
> +abcdefghijklmnopqrstuvwx
> diff --git a/test/unittest/codegen/tst.reg_spilling4.d b/test/unittest/codegen/tst.reg_spilling4.d
> new file mode 100644
> index 00000000..04961a61
> --- /dev/null
> +++ b/test/unittest/codegen/tst.reg_spilling4.d
> @@ -0,0 +1,27 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
> + * Licensed under the Universal Permissive License v 1.0 as shown at
> + * http://oss.oracle.com/licenses/upl.
> + */
> +
> +/*
> + * ASSERTION: Test that the code generator's spill/fill works with strjoin().
> + */
> +
> +#pragma D option quiet
> +
> +BEGIN
> +{
> +  trace(strjoin("abc",
> +                strjoin("def",
> +                        strjoin("ghi",
> +                                strjoin("jkl",
> +                                        "mnopqrstuvwx"
> +                                       )
> +                               )
> +                       )
> +               )
> +       );
> +  exit(0);
> +}
> diff --git a/test/unittest/codegen/tst.reg_spilling4.r b/test/unittest/codegen/tst.reg_spilling4.r
> new file mode 100644
> index 00000000..588efd11
> --- /dev/null
> +++ b/test/unittest/codegen/tst.reg_spilling4.r
> @@ -0,0 +1 @@
> +abcdefghijklmnopqrstuvwx
> diff --git a/test/unittest/codegen/tst.reg_spilling5.d b/test/unittest/codegen/tst.reg_spilling5.d
> new file mode 100644
> index 00000000..aec71a2f
> --- /dev/null
> +++ b/test/unittest/codegen/tst.reg_spilling5.d
> @@ -0,0 +1,30 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
> + * Licensed under the Universal Permissive License v 1.0 as shown at
> + * http://oss.oracle.com/licenses/upl.
> + */
> +
> +/*
> + * ASSERTION: Test that the code generator's spill/fill works with strjoin().
> + */
> +/* @@xfail: DTv2 register management */
> +
> +#pragma D option quiet
> +
> +BEGIN
> +{
> +  trace(strjoin("abc",
> +                strjoin("def",
> +                        strjoin("ghi",
> +                                strjoin("jkl",
> +                                        strjoin("mno",
> +                                                "pqrstuvwx"
> +                                               )
> +                                       )
> +                               )
> +                       )
> +               )
> +       );
> +  exit(0);
> +}
> diff --git a/test/unittest/codegen/tst.reg_spilling5.r b/test/unittest/codegen/tst.reg_spilling5.r
> new file mode 100644
> index 00000000..588efd11
> --- /dev/null
> +++ b/test/unittest/codegen/tst.reg_spilling5.r
> @@ -0,0 +1 @@
> +abcdefghijklmnopqrstuvwx
> diff --git a/test/unittest/codegen/tst.reg_spilling6.d b/test/unittest/codegen/tst.reg_spilling6.d
> new file mode 100644
> index 00000000..31a2c6d9
> --- /dev/null
> +++ b/test/unittest/codegen/tst.reg_spilling6.d
> @@ -0,0 +1,32 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
> + * Licensed under the Universal Permissive License v 1.0 as shown at
> + * http://oss.oracle.com/licenses/upl.
> + */
> +
> +/*
> + * ASSERTION: Test that the code generator's spill/fill works with strjoin().
> + */
> +/* @@xfail: DTv2 register management */
> +
> +#pragma D option quiet
> +
> +BEGIN
> +{
> +  trace(strjoin("abc",
> +                strjoin("def",
> +                        strjoin("ghi",
> +                                strjoin("jkl",
> +                                        strjoin("mno",
> +                                                strjoin("pqr",
> +                                                        "stuvwx"
> +                                                       )
> +                                               )
> +                                       )
> +                               )
> +                       )
> +               )
> +       );
> +  exit(0);
> +}
> diff --git a/test/unittest/codegen/tst.reg_spilling6.r b/test/unittest/codegen/tst.reg_spilling6.r
> new file mode 100644
> index 00000000..588efd11
> --- /dev/null
> +++ b/test/unittest/codegen/tst.reg_spilling6.r
> @@ -0,0 +1 @@
> +abcdefghijklmnopqrstuvwx
> diff --git a/test/unittest/codegen/tst.reg_spilling7.d b/test/unittest/codegen/tst.reg_spilling7.d
> new file mode 100644
> index 00000000..ade2136a
> --- /dev/null
> +++ b/test/unittest/codegen/tst.reg_spilling7.d
> @@ -0,0 +1,32 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
> + * Licensed under the Universal Permissive License v 1.0 as shown at
> + * http://oss.oracle.com/licenses/upl.
> + */
> +
> +/*
> + * ASSERTION: Test that the code generator's spill/fill works with strjoin().
> + */
> +/* @@xfail: DTv2 register management */
> +
> +#pragma D option quiet
> +
> +BEGIN
> +{
> +  trace(strjoin("abc",
> +                strjoin("def",
> +                        strjoin("ghi",
> +                                strjoin("jkl",
> +                                        strjoin("mno",
> +                                                strjoin("pqr",
> +                                                        strjoin("stu", "vwx")
> +                                                       )
> +                                               )
> +                                       )
> +                               )
> +                       )
> +               )
> +       );
> +  exit(0);
> +}
> diff --git a/test/unittest/codegen/tst.reg_spilling7.r b/test/unittest/codegen/tst.reg_spilling7.r
> new file mode 100644
> index 00000000..588efd11
> --- /dev/null
> +++ b/test/unittest/codegen/tst.reg_spilling7.r
> @@ -0,0 +1 @@
> +abcdefghijklmnopqrstuvwx



More information about the DTrace-devel mailing list