[go] reflect: store receiver in pointer slot for reflect call

7 views
Skip to first unread message

Cherry Mui (Gerrit)

unread,
May 20, 2022, 7:51:23 PM5/20/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Cherry Mui has uploaded this change for review.

View Change

reflect: store receiver in pointer slot for reflect call

The code comment says that the receiver doesn't need to go into
the pointer slot as it will be kept alive in this frame. But it
doesn't. There is no direct reference of rcvr or v (the receiver)
after storing the arguments. Also, it is clearer to explicitly
keep it alive.

XXX same for method value call (reflect.callMethod)?

Fixes #52800.

Change-Id: Ie3fa8e83f6ecc69d62e8bfab767314d5181f5dc0
---
M src/reflect/value.go
1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/reflect/value.go b/src/reflect/value.go
index 0fc19ef..8ab0807 100644
--- a/src/reflect/value.go
+++ b/src/reflect/value.go
@@ -499,11 +499,10 @@
switch st := abid.call.steps[0]; st.kind {
case abiStepStack:
storeRcvr(rcvr, stackArgs)
- case abiStepIntReg, abiStepPointer:
- // Even pointers can go into the uintptr slot because
- // they'll be kept alive by the Values referenced by
- // this frame. Reflection forces these to be heap-allocated,
- // so we don't need to worry about stack copying.
+ case abiStepPointer:
+ storeRcvr(rcvr, unsafe.Pointer(&regArgs.Ptrs[st.ireg]))
+ fallthrough
+ case abiStepIntReg:
storeRcvr(rcvr, unsafe.Pointer(&regArgs.Ints[st.ireg]))
case abiStepFloatReg:
storeRcvr(rcvr, unsafe.Pointer(&regArgs.Floats[st.freg]))

To view, visit change 407508. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ie3fa8e83f6ecc69d62e8bfab767314d5181f5dc0
Gerrit-Change-Number: 407508
Gerrit-PatchSet: 1
Gerrit-Owner: Cherry Mui <cher...@google.com>
Gerrit-MessageType: newchange

Cherry Mui (Gerrit)

unread,
May 20, 2022, 7:51:47 PM5/20/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Patch set 1:Run-TryBot +1

View Change

    To view, visit change 407508. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ie3fa8e83f6ecc69d62e8bfab767314d5181f5dc0
    Gerrit-Change-Number: 407508
    Gerrit-PatchSet: 1
    Gerrit-Owner: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Comment-Date: Fri, 20 May 2022 23:51:43 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Michael Knyszek (Gerrit)

    unread,
    May 20, 2022, 9:31:09 PM5/20/22
    to Cherry Mui, goph...@pubsubhelper.golang.org, Gopher Robot, Austin Clements, golang-co...@googlegroups.com

    Attention is currently required from: Austin Clements, Cherry Mui.

    Patch set 1:Code-Review +2

    View Change

    2 comments:

    • Commit Message:

      • Patch Set #1, Line 15: XXX same for method value call (reflect.callMethod)?

        yeah I think this needs the same treatment.

    • Patchset:

      • Patch Set #1:

        ugh, the bug tail on the regabi reflect implementation is long... thanks for figuring this out!!

    To view, visit change 407508. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ie3fa8e83f6ecc69d62e8bfab767314d5181f5dc0
    Gerrit-Change-Number: 407508
    Gerrit-PatchSet: 1
    Gerrit-Owner: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Austin Clements <aus...@google.com>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-Attention: Austin Clements <aus...@google.com>
    Gerrit-Attention: Cherry Mui <cher...@google.com>
    Gerrit-Comment-Date: Sat, 21 May 2022 01:31:04 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Cherry Mui (Gerrit)

    unread,
    May 23, 2022, 11:47:46 AM5/23/22
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Austin Clements, Cherry Mui.

    Cherry Mui uploaded patch set #2 to this change.

    View Change

    The following approvals got outdated and were removed: Run-TryBot+1 by Cherry Mui, TryBot-Result+1 by Gopher Robot

    reflect: store receiver in pointer slot for reflect call

    The code comment says that the receiver doesn't need to go into
    the pointer slot as it will be kept alive in this frame. But it
    doesn't. There is no direct reference of rcvr or v (the receiver)
    after storing the arguments. Also, it is clearer to explicitly
    keep it alive.

    XXX same for method value call (reflect.callMethod)?

    Fixes #52800.

    Change-Id: Ie3fa8e83f6ecc69d62e8bfab767314d5181f5dc0
    ---
    M src/reflect/value.go
    1 file changed, 34 insertions(+), 8 deletions(-)

    To view, visit change 407508. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ie3fa8e83f6ecc69d62e8bfab767314d5181f5dc0
    Gerrit-Change-Number: 407508
    Gerrit-PatchSet: 2
    Gerrit-Owner: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Austin Clements <aus...@google.com>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-Attention: Austin Clements <aus...@google.com>
    Gerrit-Attention: Cherry Mui <cher...@google.com>
    Gerrit-MessageType: newpatchset

    Cherry Mui (Gerrit)

    unread,
    May 23, 2022, 11:47:58 AM5/23/22
    to goph...@pubsubhelper.golang.org, Gopher Robot, Austin Clements, golang-co...@googlegroups.com

    Attention is currently required from: Austin Clements.

    Patch set 2:Run-TryBot +1

    View Change

      To view, visit change 407508. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ie3fa8e83f6ecc69d62e8bfab767314d5181f5dc0
      Gerrit-Change-Number: 407508
      Gerrit-PatchSet: 2
      Gerrit-Owner: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Austin Clements <aus...@google.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
      Gerrit-Attention: Austin Clements <aus...@google.com>
      Gerrit-Comment-Date: Mon, 23 May 2022 15:47:55 +0000

      Cherry Mui (Gerrit)

      unread,
      May 23, 2022, 11:48:41 AM5/23/22
      to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

      Attention is currently required from: Austin Clements, Cherry Mui.

      Cherry Mui uploaded patch set #3 to this change.

      View Change

      The following approvals got outdated and were removed: Run-TryBot+1 by Cherry Mui

      reflect: store receiver in pointer slot for reflect call


      The code comment says that the receiver doesn't need to go into
      the pointer slot as it will be kept alive in this frame. But it
      doesn't. There is no direct reference of rcvr or v (the receiver)
      after storing the arguments. Also, it is clearer to explicitly
      keep it alive.

      Fixes #52800.

      Change-Id: Ie3fa8e83f6ecc69d62e8bfab767314d5181f5dc0
      ---
      M src/reflect/value.go
      1 file changed, 32 insertions(+), 8 deletions(-)

      To view, visit change 407508. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ie3fa8e83f6ecc69d62e8bfab767314d5181f5dc0
      Gerrit-Change-Number: 407508
      Gerrit-PatchSet: 3
      Gerrit-Owner: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Austin Clements <aus...@google.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
      Gerrit-Attention: Austin Clements <aus...@google.com>

      Cherry Mui (Gerrit)

      unread,
      May 23, 2022, 11:50:29 AM5/23/22
      to goph...@pubsubhelper.golang.org, Gopher Robot, Austin Clements, golang-co...@googlegroups.com

      Attention is currently required from: Austin Clements.

      View Change

      2 comments:

      • Commit Message:

        • Patch Set #1, Line 15: XXX same for method value call (reflect.callMethod)?

          yeah I think this needs the same treatment.

        • Done

      • File src/reflect/value.go:

        • Patch Set #3, Line 984: methodRegs.Ints[st.ireg]

          The old code uses &Ints, which is effectively &Ints[0]. I think st.ireg should always be 0 here. If you &Ints or &Ints[0] is preferred, I can change it back.

      To view, visit change 407508. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Ie3fa8e83f6ecc69d62e8bfab767314d5181f5dc0
      Gerrit-Change-Number: 407508
      Gerrit-PatchSet: 3
      Gerrit-Owner: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Austin Clements <aus...@google.com>
      Gerrit-Reviewer: Cherry Mui <cher...@google.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
      Gerrit-Attention: Austin Clements <aus...@google.com>
      Gerrit-Comment-Date: Mon, 23 May 2022 15:50:26 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Michael Knyszek <mkny...@google.com>
      Gerrit-MessageType: comment

      Cherry Mui (Gerrit)

      unread,
      May 23, 2022, 11:50:38 AM5/23/22
      to goph...@pubsubhelper.golang.org, Gopher Robot, Austin Clements, golang-co...@googlegroups.com

      Attention is currently required from: Austin Clements.

      Patch set 3:Run-TryBot +1

      View Change

        To view, visit change 407508. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Ie3fa8e83f6ecc69d62e8bfab767314d5181f5dc0
        Gerrit-Change-Number: 407508
        Gerrit-PatchSet: 3
        Gerrit-Owner: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Austin Clements <aus...@google.com>
        Gerrit-Reviewer: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
        Gerrit-Attention: Austin Clements <aus...@google.com>
        Gerrit-Comment-Date: Mon, 23 May 2022 15:50:33 +0000

        Michael Knyszek (Gerrit)

        unread,
        May 23, 2022, 2:36:25 PM5/23/22
        to Cherry Mui, goph...@pubsubhelper.golang.org, Gopher Robot, Austin Clements, golang-co...@googlegroups.com

        Attention is currently required from: Austin Clements, Cherry Mui.

        Patch set 3:Code-Review +2

        View Change

        1 comment:

        • File src/reflect/value.go:

          • The old code uses &Ints, which is effectively &Ints[0]. I think st.ireg should always be 0 here. […]

            I think that was just to avoid the zero-indexing issue. I think this is good.

        To view, visit change 407508. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Ie3fa8e83f6ecc69d62e8bfab767314d5181f5dc0
        Gerrit-Change-Number: 407508
        Gerrit-PatchSet: 3
        Gerrit-Owner: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Austin Clements <aus...@google.com>
        Gerrit-Reviewer: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
        Gerrit-Attention: Austin Clements <aus...@google.com>
        Gerrit-Attention: Cherry Mui <cher...@google.com>
        Gerrit-Comment-Date: Mon, 23 May 2022 18:36:21 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: Yes
        Comment-In-Reply-To: Cherry Mui <cher...@google.com>
        Gerrit-MessageType: comment

        Cherry Mui (Gerrit)

        unread,
        May 23, 2022, 2:40:59 PM5/23/22
        to goph...@pubsubhelper.golang.org, Gopher Robot, Austin Clements, golang-co...@googlegroups.com

        Attention is currently required from: Austin Clements.

        View Change

        1 comment:

        To view, visit change 407508. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Ie3fa8e83f6ecc69d62e8bfab767314d5181f5dc0
        Gerrit-Change-Number: 407508
        Gerrit-PatchSet: 3
        Gerrit-Owner: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Austin Clements <aus...@google.com>
        Gerrit-Reviewer: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
        Gerrit-Attention: Austin Clements <aus...@google.com>
        Gerrit-Comment-Date: Mon, 23 May 2022 18:40:56 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        Gerrit-MessageType: comment

        Cherry Mui (Gerrit)

        unread,
        May 23, 2022, 2:41:02 PM5/23/22
        to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Gopher Robot, Michael Knyszek, Austin Clements, golang-co...@googlegroups.com

        Cherry Mui submitted this change.

        View Change


        Approvals: Gopher Robot: TryBots succeeded Cherry Mui: Run TryBots Michael Knyszek: Looks good to me, approved
        reflect: store receiver in pointer slot for reflect call

        The code comment says that the receiver doesn't need to go into
        the pointer slot as it will be kept alive in this frame. But it
        doesn't. There is no direct reference of rcvr or v (the receiver)
        after storing the arguments. Also, it is clearer to explicitly
        keep it alive.

        Fixes #52800.

        Change-Id: Ie3fa8e83f6ecc69d62e8bfab767314d5181f5dc0
        Reviewed-on: https://go-review.googlesource.com/c/go/+/407508
        Run-TryBot: Cherry Mui <cher...@google.com>
        Reviewed-by: Michael Knyszek <mkny...@google.com>
        TryBot-Result: Gopher Robot <go...@golang.org>
        ---
        M src/reflect/value.go
        1 file changed, 36 insertions(+), 8 deletions(-)

        diff --git a/src/reflect/value.go b/src/reflect/value.go
        index 0fc19ef..400f24f 100644

        --- a/src/reflect/value.go
        +++ b/src/reflect/value.go
        @@ -499,11 +499,10 @@
        switch st := abid.call.steps[0]; st.kind {
        case abiStepStack:
        storeRcvr(rcvr, stackArgs)
        - case abiStepIntReg, abiStepPointer:
        - // Even pointers can go into the uintptr slot because
        - // they'll be kept alive by the Values referenced by
        - // this frame. Reflection forces these to be heap-allocated,
        - // so we don't need to worry about stack copying.
        + case abiStepPointer:
        + storeRcvr(rcvr, unsafe.Pointer(&regArgs.Ptrs[st.ireg]))
        + fallthrough
        + case abiStepIntReg:
        storeRcvr(rcvr, unsafe.Pointer(&regArgs.Ints[st.ireg]))
        case abiStepFloatReg:
        storeRcvr(rcvr, unsafe.Pointer(&regArgs.Floats[st.freg]))
        @@ -972,13 +971,21 @@
        var methodRegs abi.RegArgs

        // Deal with the receiver. It's guaranteed to only be one word in size.
        - if st := methodABI.call.steps[0]; st.kind == abiStepStack {
        + switch st := methodABI.call.steps[0]; st.kind {
        + case abiStepStack:
        // Only copy the receiver to the stack if the ABI says so.
        // Otherwise, it'll be in a register already.
        storeRcvr(rcvr, methodFrame)
        - } else {
        + case abiStepPointer:
        // Put the receiver in a register.
        - storeRcvr(rcvr, unsafe.Pointer(&methodRegs.Ints))
        + storeRcvr(rcvr, unsafe.Pointer(&methodRegs.Ptrs[st.ireg]))

        + fallthrough
        + case abiStepIntReg:
        +		storeRcvr(rcvr, unsafe.Pointer(&methodRegs.Ints[st.ireg]))
        + case abiStepFloatReg:
        + storeRcvr(rcvr, unsafe.Pointer(&methodRegs.Floats[st.freg]))
        + default:
        + panic("unknown ABI parameter kind")
        }

        // Translate the rest of the arguments.

        To view, visit change 407508. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Ie3fa8e83f6ecc69d62e8bfab767314d5181f5dc0
        Gerrit-Change-Number: 407508
        Gerrit-PatchSet: 4
        Gerrit-Owner: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Austin Clements <aus...@google.com>
        Gerrit-Reviewer: Cherry Mui <cher...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
        Gerrit-MessageType: merged
        Reply all
        Reply to author
        Forward
        0 new messages