Skip to content

Commit

Permalink
feat(jit): go1.23 for the last supported version (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaost authored Aug 2, 2024
1 parent a489639 commit 5a7ade6
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 118 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build go1.21 && !go1.23
// +build go1.21,!go1.23
//go:build go1.21 && !go1.24
// +build go1.21,!go1.24

/*
* Copyright 2022 CloudWeGo Authors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build go1.18 && !go1.23
// +build go1.18,!go1.23
//go:build go1.18 && !go1.24
// +build go1.18,!go1.24

/*
* Copyright 2022 CloudWeGo Authors
Expand Down
8 changes: 4 additions & 4 deletions internal/loader/funcdata_invalid.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !go1.16 || go1.23
// +build !go1.16 go1.23
//go:build !go1.16 || go1.24
// +build !go1.16 go1.24

/*
* Copyright 2022 CloudWeGo Authors
Expand All @@ -25,9 +25,9 @@ import (

// triggers a compilation error
const (
_ = panic("Unsupported Go version. Supported versions are 1.17 ~ 1.22")
_ = panic("Unsupported Go version. Supported versions are 1.17 ~ 1.23")
)

func registerFunction(_ string, _ uintptr, _ uintptr, _ rt.Frame) {
panic("Unsupported Go version. Supported versions are 1.17 ~ 1.22")
panic("Unsupported Go version. Supported versions are 1.17 ~ 1.23")
}
88 changes: 88 additions & 0 deletions internal/loader/moduledata_go123.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//go:build go1.23
// +build go1.23

/*
* Copyright 2024 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package loader

import (
"unsafe"

"github.com/cloudwego/frugal/internal/rt"
)

type _Func struct {
entryOff uint32
nameoff int32
args int32
deferreturn uint32
pcsp uint32
pcfile uint32
pcln uint32
npcdata uint32
cuOffset uint32
startLine int32
funcID uint8
flag uint8
_ [1]byte
nfuncdata uint8
pcdata [2]uint32
argptrs uint32
localptrs uint32
}

type _ModuleData struct {
pcHeader *_PCHeader
funcnametab []byte
cutab []uint32
filetab []byte
pctab []byte
pclntable []byte
ftab []_FuncTab
findfunctab uintptr
minpc, maxpc uintptr
text, etext uintptr
noptrdata, enoptrdata uintptr
data, edata uintptr
bss, ebss uintptr
noptrbss, enoptrbss uintptr
covctrs, ecovctrs uintptr
end, gcdata, gcbss uintptr
types, etypes uintptr
rodata uintptr
gofunc uintptr
textsectmap [][3]uintptr
typelinks []int32
itablinks []*rt.GoItab
ptab [][2]int32
pluginpath string
pkghashes []struct{}
// This slice records the initializing tasks that need to be
// done to start up the program. It is built by the linker.
inittasks []unsafe.Pointer
modulename string
modulehashes []struct{}
hasmain uint8
bad bool
gcdatamask, gcbssmask _BitVector
typemap map[int32]*rt.GoType
next *_ModuleData
}

const (
_ModuleMagic = 0xfffffff1
)
42 changes: 0 additions & 42 deletions internal/rt/stackmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
package rt

import (
"fmt"
"reflect"
"testing"
"unsafe"
)

Expand Down Expand Up @@ -48,37 +45,6 @@ func (bv *bitvector) ptrbit(i uintptr) uint8 {
return (b >> (i % 8)) & 1
}

//go:linkname findfunc runtime.findfunc
func findfunc(_ uintptr) funcInfo

//go:linkname funcdata runtime.funcdata
func funcdata(_ funcInfo, _ uint8) unsafe.Pointer

//go:linkname stackmapdata runtime.stackmapdata
func stackmapdata(_ *StackMap, _ int32) bitvector

func stackMap(f interface{}) (*StackMap, *StackMap) {
fv := reflect.ValueOf(f)
if fv.Kind() != reflect.Func {
panic("f must be reflect.Func kind!")
}
fi := findfunc(fv.Pointer())
args := funcdata(fi, uint8(_FUNCDATA_ArgsPointerMaps))
locals := funcdata(fi, uint8(_FUNCDATA_LocalsPointerMaps))
return (*StackMap)(args), (*StackMap)(locals)
}

func dumpstackmap(m *StackMap) {
for i := int32(0); i < m.N; i++ {
fmt.Printf("bitmap #%d/%d: ", i, m.L)
bv := stackmapdata(m, i)
for j := int32(0); j < bv.n; j++ {
fmt.Printf("%d ", bv.ptrbit(uintptr(j)))
}
fmt.Printf("\n")
}
}

var keepalive struct {
s string
i int
Expand All @@ -98,11 +64,3 @@ func stackmaptestfunc(s string, i int, vp unsafe.Pointer, sb interface{}, fv uin
keepalive.fv = fv
return
}

func TestStackMap_Dump(t *testing.T) {
args, locals := stackMap(stackmaptestfunc)
println("--- args ---")
dumpstackmap(args)
println("--- locals ---")
dumpstackmap(locals)
}
58 changes: 0 additions & 58 deletions tests/debughook_amd64.go

This file was deleted.

10 changes: 5 additions & 5 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ require (

require (
github.com/bytedance/gopkg v0.0.0-20240711085056-a03554c296f8 // indirect
github.com/bytedance/sonic v1.11.8 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/bytedance/sonic v1.12.0 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/gopkg v0.1.0 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/cloudwego/runtimex v0.1.0 // indirect
github.com/cloudwego/thriftgo v0.3.6 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/pprof v0.0.0-20220608213341-c488b8fa1db3 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/oleiade/lane v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
golang.org/x/arch v0.2.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/sys v0.22.0 // indirect
google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
15 changes: 10 additions & 5 deletions tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ github.com/bytedance/gopkg v0.0.0-20240711085056-a03554c296f8 h1:rDwLxYTMoKHaw4c
github.com/bytedance/gopkg v0.0.0-20240711085056-a03554c296f8/go.mod h1:FtQG3YbQG9L/91pbKSw787yBQPutC+457AvDW77fgUQ=
github.com/bytedance/mockey v1.2.7/go.mod h1:bNrUnI1u7+pAc0TYDgPATM+wF2yzHxmNH+iDXg4AOCU=
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic v1.11.8 h1:Zw/j1KfiS+OYTi9lyB3bb0CFxPJVkM17k1wyDG32LRA=
github.com/bytedance/sonic v1.11.8/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
github.com/bytedance/sonic v1.12.0 h1:YGPgxF9xzaCNvd/ZKdQ28yRovhfMFZQjuk6fKBzZ3ls=
github.com/bytedance/sonic v1.12.0/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP1iU4kWM=
github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY=
github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic=
Expand Down Expand Up @@ -89,8 +91,9 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down Expand Up @@ -138,8 +141,9 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff/go.mod h1:flIaEI6LNU6xOCD5PaJvn9wGP0agmIOqjrtsKGRguv4=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.2.0 h1:W1sUEHXiJTfjaFJ5SLo0N6lZn+0eO5gWD1MFeTGqQEY=
golang.org/x/arch v0.2.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down Expand Up @@ -205,8 +209,9 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
Expand Down

0 comments on commit 5a7ade6

Please sign in to comment.