diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-05-01 21:34:16 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-05-01 21:34:16 +0000 |
commit | 5e87c2806ff4e9057c4c46fa1d9c8ac91ce3dae9 (patch) | |
tree | e3583babaa67131fcef04311cf265c9415582ca9 /libgo/go/runtime/iface.go | |
parent | 1da37f43b21e0c35e57b627edfa99ec80d2976ee (diff) | |
download | gcc-5e87c2806ff4e9057c4c46fa1d9c8ac91ce3dae9.zip gcc-5e87c2806ff4e9057c4c46fa1d9c8ac91ce3dae9.tar.gz gcc-5e87c2806ff4e9057c4c46fa1d9c8ac91ce3dae9.tar.bz2 |
compiler,runtime: do more direct interfaces
A direct interface is an interface whose data word contains the
actual data value, instead of a pointer to it. The gc toolchain
creates a direct interface if the value is pointer shaped, that
includes pointers (including unsafe.Pointer), functions, channels,
maps, and structs and arrays containing a single pointer-shaped
field. In gccgo, we only do this for pointers. This CL unifies
direct interface types with gc. This reduces allocations when
converting such types to interfaces.
Our method functions used to always take pointer receivers, to
make interface calls easy. Now for direct interface types, their
value methods will take value receivers. For a pointer to those
types, when converted to interface, the interface data contains
the pointer. For that interface to call a value method, it will
need a wrapper method that dereference the pointer and invokes
the value method. The wrapper method, instead of the actual one,
is put into the itable of the pointer type.
In the runtime, adjust funcPC for the new layout of interfaces of
functions.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/168409
From-SVN: r270779
Diffstat (limited to 'libgo/go/runtime/iface.go')
-rw-r--r-- | libgo/go/runtime/iface.go | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/libgo/go/runtime/iface.go b/libgo/go/runtime/iface.go index dc92476..1c3a5f3 100644 --- a/libgo/go/runtime/iface.go +++ b/libgo/go/runtime/iface.go @@ -68,10 +68,9 @@ import ( // pointer to memory that holds the value. It follows from this that // kindDirectIface can only be set for a type whose representation is // simply a pointer. In the current gccgo implementation, this is set -// only for pointer types (including unsafe.Pointer). In the future it -// could also be set for other types: channels, maps, functions, -// single-field structs and single-element arrays whose single field -// is simply a pointer. +// for types that are pointer-shaped, including unsafe.Pointer, channels, +// maps, functions, single-field structs and single-element arrays whose +// single field is simply a pointer-shaped type. // For a nil interface value both fields in the interface struct are nil. @@ -458,7 +457,11 @@ func ifaceE2T2(t *_type, e eface, ret unsafe.Pointer) bool { typedmemclr(t, ret) return false } else { - typedmemmove(t, ret, e.data) + if isDirectIface(t) { + *(*unsafe.Pointer)(ret) = e.data + } else { + typedmemmove(t, ret, e.data) + } return true } } @@ -469,7 +472,11 @@ func ifaceI2T2(t *_type, i iface, ret unsafe.Pointer) bool { typedmemclr(t, ret) return false } else { - typedmemmove(t, ret, i.data) + if isDirectIface(t) { + *(*unsafe.Pointer)(ret) = i.data + } else { + typedmemmove(t, ret, i.data) + } return true } } |