summaryrefslogtreecommitdiff
path: root/vendor/github.com/bytedance/sonic/internal/rt
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/bytedance/sonic/internal/rt')
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/asm_amd64.s41
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/asm_compat.s1
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/assertI2I.go42
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/base64_amd64.go20
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/base64_compat.go20
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/fastconv.go175
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/fastmem.go36
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/fastvalue.go236
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/gcwb.go55
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/gcwb_legacy.go29
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/growslice.go36
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/growslice_legacy.go27
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/pool.go31
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/stackmap.go2
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/stubs.go165
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/table.go118
-rw-r--r--vendor/github.com/bytedance/sonic/internal/rt/types.go45
17 files changed, 879 insertions, 200 deletions
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/asm_amd64.s b/vendor/github.com/bytedance/sonic/internal/rt/asm_amd64.s
index 4998d5f79..48a564bee 100644
--- a/vendor/github.com/bytedance/sonic/internal/rt/asm_amd64.s
+++ b/vendor/github.com/bytedance/sonic/internal/rt/asm_amd64.s
@@ -1,4 +1,5 @@
// +build !noasm,amd64 !appengine,amd64
+// Code generated by asm2asm, DO NOT EDIT·
#include "go_asm.h"
#include "funcdata.h"
@@ -17,43 +18,3 @@ _entry:
_stack_grow:
CALL runtime·morestack_noctxt<>(SB)
JMP _entry
-
-
-TEXT ·StopProf(SB), NOSPLIT, $0-0
- NO_LOCAL_POINTERS
- CMPB github·com∕bytedance∕sonic∕internal∕rt·StopProfiling(SB), $0
- JEQ _ret_1
- MOVL $1, AX
- LEAQ github·com∕bytedance∕sonic∕internal∕rt·yieldCount(SB), CX
- LOCK
- XADDL AX, (CX)
- MOVL runtime·prof+4(SB), AX
- TESTL AX, AX
- JEQ _ret_1
- MOVL AX, github·com∕bytedance∕sonic∕internal∕rt·oldHz(SB)
- MOVL $0, runtime·prof+4(SB)
-_ret_1:
- RET
-
-
-TEXT ·StartProf(SB), NOSPLIT, $0-0
- NO_LOCAL_POINTERS
- CMPB github·com∕bytedance∕sonic∕internal∕rt·StopProfiling(SB), $0
- JEQ _ret_2
- MOVL $-1, AX
- LEAQ github·com∕bytedance∕sonic∕internal∕rt·yieldCount(SB), CX
- LOCK
- XADDL AX, (CX)
- CMPL github·com∕bytedance∕sonic∕internal∕rt·yieldCount(SB), $0
- JNE _ret_2
- CMPL runtime·prof+4(SB), $0
- JNE _ret_2
- CMPL github·com∕bytedance∕sonic∕internal∕rt·oldHz(SB), $0
- JNE _branch_1
- MOVL $100, github·com∕bytedance∕sonic∕internal∕rt·oldHz(SB)
-_branch_1:
- MOVL github·com∕bytedance∕sonic∕internal∕rt·oldHz(SB), AX
- MOVL AX, runtime·prof+4(SB)
-_ret_2:
- RET
- \ No newline at end of file
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/asm_compat.s b/vendor/github.com/bytedance/sonic/internal/rt/asm_compat.s
index 7d50b6483..c807d8343 100644
--- a/vendor/github.com/bytedance/sonic/internal/rt/asm_compat.s
+++ b/vendor/github.com/bytedance/sonic/internal/rt/asm_compat.s
@@ -1,4 +1,5 @@
// +build !noasm,!amd64 !appengine,!amd64
+// Code generated by asm2asm, DO NOT EDIT.
#include "go_asm.h"
#include "funcdata.h"
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/assertI2I.go b/vendor/github.com/bytedance/sonic/internal/rt/assertI2I.go
new file mode 100644
index 000000000..d19376a60
--- /dev/null
+++ b/vendor/github.com/bytedance/sonic/internal/rt/assertI2I.go
@@ -0,0 +1,42 @@
+// +build go1.17
+
+/*
+ * Copyright 2021 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 rt
+
+import (
+ _ `unsafe`
+)
+
+func AssertI2I(t *GoType, i GoIface) (r GoIface) {
+ inter := IfaceType(t)
+ tab := i.Itab
+ if tab == nil {
+ return
+ }
+ if (*GoInterfaceType)(tab.it) != inter {
+ tab = GetItab(inter, tab.Vt, true)
+ if tab == nil {
+ return
+ }
+ }
+ r.Itab = tab
+ r.Value = i.Value
+ return
+}
+
+
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/base64_amd64.go b/vendor/github.com/bytedance/sonic/internal/rt/base64_amd64.go
new file mode 100644
index 000000000..263bc592f
--- /dev/null
+++ b/vendor/github.com/bytedance/sonic/internal/rt/base64_amd64.go
@@ -0,0 +1,20 @@
+// +build amd64,go1.17,!go1.24
+
+package rt
+
+import (
+ "github.com/cloudwego/base64x"
+)
+
+func DecodeBase64(raw []byte) ([]byte, error) {
+ ret := make([]byte, base64x.StdEncoding.DecodedLen(len(raw)))
+ n, err := base64x.StdEncoding.Decode(ret, raw)
+ if err != nil {
+ return nil, err
+ }
+ return ret[:n], nil
+}
+
+func EncodeBase64(src []byte) string {
+ return base64x.StdEncoding.EncodeToString(src)
+}
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/base64_compat.go b/vendor/github.com/bytedance/sonic/internal/rt/base64_compat.go
new file mode 100644
index 000000000..791f79355
--- /dev/null
+++ b/vendor/github.com/bytedance/sonic/internal/rt/base64_compat.go
@@ -0,0 +1,20 @@
+// +build !amd64 !go1.17 go1.24
+
+package rt
+
+import (
+ "encoding/base64"
+)
+
+func DecodeBase64(raw []byte) ([]byte, error) {
+ ret := make([]byte, base64.StdEncoding.DecodedLen(len(raw)))
+ n, err := base64.StdEncoding.Decode(ret, raw)
+ if err != nil {
+ return nil, err
+ }
+ return ret[:n], nil
+}
+
+func EncodeBase64(src []byte) string {
+ return base64.StdEncoding.EncodeToString(src)
+}
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/fastconv.go b/vendor/github.com/bytedance/sonic/internal/rt/fastconv.go
new file mode 100644
index 000000000..81196650d
--- /dev/null
+++ b/vendor/github.com/bytedance/sonic/internal/rt/fastconv.go
@@ -0,0 +1,175 @@
+package rt
+
+import (
+ "unsafe"
+ "encoding/json"
+)
+
+// Copied from Golang
+var staticuint64s = [...]uint64{
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
+ 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
+ 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
+ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
+ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
+ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
+}
+
+const maxZero = 1024 // must match value in reflect/value.go:maxZero cmd/compile/internal/gc/walk.go:zeroValSize
+var zeroVal [maxZero]byte
+
+
+type TslicePool struct {
+ pool []GoSlice
+ index int
+}
+
+func NewTslicePool (hint int) TslicePool {
+ return TslicePool{
+ pool: make([]GoSlice, hint, hint),
+ index: 0,
+ }
+}
+
+func (self *TslicePool) Conv(val GoSlice, typ *GoType, ep *interface{}) {
+ var vp unsafe.Pointer
+
+ if ((*GoSlice)(unsafe.Pointer(&val))).Ptr == nil {
+ vp = unsafe.Pointer(&zeroVal[0])
+ } else if self.index < len(self.pool) {
+ dst := &(self.pool)[self.index]
+ *dst = val
+ self.index++
+ vp = unsafe.Pointer(dst)
+ } else {
+ vp = Mallocgc(unsafe.Sizeof(val), BytesType, true)
+ }
+ *((*GoEface)(unsafe.Pointer(ep))) = GoEface{Type: typ, Value: vp}
+}
+
+func (self *TslicePool) Free() {
+ self.pool = nil
+}
+
+type TstringPool struct {
+ pool []string
+ index int
+}
+
+func NewTstringPool (hint int) TstringPool {
+ return TstringPool{
+ pool: make([]string, hint),
+ index: 0,
+ }
+}
+
+func (self *TstringPool) Conv(val string, ep *interface{}) {
+ var vp unsafe.Pointer
+ if val == "" {
+ vp = unsafe.Pointer(&zeroVal[0])
+ } else if self.index < len(self.pool) {
+ dst := &(self.pool)[self.index]
+ *dst = val
+ self.index++
+ vp = unsafe.Pointer(dst)
+ } else {
+ vp = Mallocgc(unsafe.Sizeof(val), StringType, true)
+ }
+
+ // convert into interface{}
+ *((*GoEface)(unsafe.Pointer(ep))) = GoEface{Type: StringType, Value: vp}
+}
+
+
+func (self *TstringPool) ConvNum(val json.Number, ep *interface{}) {
+ var vp unsafe.Pointer
+ if val == "" {
+ vp = unsafe.Pointer(&zeroVal[0])
+ } else if self.index < len(self.pool) {
+ dst := &(self.pool)[self.index]
+ *dst = string(val)
+ self.index++
+ vp = unsafe.Pointer(dst)
+ } else {
+ vp = Mallocgc(unsafe.Sizeof(val), StringType, true)
+ }
+
+ // convert into interface{}
+ *((*GoEface)(unsafe.Pointer(ep))) = GoEface{Type: JsonNumberType, Value: vp}
+}
+
+
+func (self *TstringPool) Free() {
+ self.pool = nil
+}
+
+type T64Pool struct {
+ pool []uint64
+ index int
+}
+
+func NewT64Pool (hint int) T64Pool {
+ return T64Pool{
+ pool: make([]uint64, hint, hint),
+ index: 0,
+ }
+}
+
+func (self *T64Pool) Conv(val uint64, typ *GoType, ep *interface{}) {
+ var vp unsafe.Pointer
+ if val < uint64(len(staticuint64s)) {
+ vp = unsafe.Pointer(&staticuint64s[val])
+ } else if self.index < len(self.pool) {
+ dst := &(self.pool)[self.index]
+ *dst = val
+ self.index++
+ vp = unsafe.Pointer(dst)
+ } else {
+ vp = Mallocgc(8, Uint64Type, false)
+ }
+
+ // convert into interface{}
+ *((*GoEface)(unsafe.Pointer(ep))) = GoEface{Type: typ, Value: vp}
+}
+
+func (self *T64Pool) Free() {
+ self.pool = nil
+}
+
+func ConvTBool(val bool, ep *interface{}) {
+ var vp unsafe.Pointer
+ if val {
+ vp = unsafe.Pointer(&staticuint64s[1])
+ } else {
+ vp = unsafe.Pointer(&staticuint64s[0])
+ }
+
+ *((*GoEface)(unsafe.Pointer(ep))) = GoEface{Type: BoolType, Value: vp}
+}
+
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/fastmem.go b/vendor/github.com/bytedance/sonic/internal/rt/fastmem.go
index a68d98aff..508be4765 100644
--- a/vendor/github.com/bytedance/sonic/internal/rt/fastmem.go
+++ b/vendor/github.com/bytedance/sonic/internal/rt/fastmem.go
@@ -17,8 +17,10 @@
package rt
import (
- `unsafe`
- `reflect`
+ "reflect"
+ "unsafe"
+
+ "github.com/bytedance/sonic/option"
)
//go:nosplit
@@ -90,6 +92,21 @@ func GuardSlice(buf *[]byte, n int) {
}
}
+func GuardSlice2(buf []byte, n int) []byte {
+ c := cap(buf)
+ l := len(buf)
+ if c-l < n {
+ c = c>>1 + n + l
+ if c < 32 {
+ c = 32
+ }
+ tmp := make([]byte, l, c)
+ copy(tmp, buf)
+ buf = tmp
+ }
+ return buf
+}
+
//go:nosplit
func Ptr2SlicePtr(s unsafe.Pointer, l int, c int) unsafe.Pointer {
slice := &GoSlice{
@@ -122,4 +139,17 @@ func StrFrom(p unsafe.Pointer, n int64) (s string) {
func NoEscape(p unsafe.Pointer) unsafe.Pointer {
x := uintptr(p)
return unsafe.Pointer(x ^ 0)
-} \ No newline at end of file
+}
+
+//go:nosplit
+func MoreStack(size uintptr)
+
+//go:nosplit
+func Add(ptr unsafe.Pointer, off uintptr) unsafe.Pointer {
+ return unsafe.Pointer(uintptr(ptr) + off)
+}
+
+// CanSizeResue
+func CanSizeResue(cap int) bool {
+ return cap <= int(option.LimitBufferSize)
+}
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/fastvalue.go b/vendor/github.com/bytedance/sonic/internal/rt/fastvalue.go
index 6657220ab..85c90fc07 100644
--- a/vendor/github.com/bytedance/sonic/internal/rt/fastvalue.go
+++ b/vendor/github.com/bytedance/sonic/internal/rt/fastvalue.go
@@ -17,209 +17,209 @@
package rt
import (
- `reflect`
- `unsafe`
+ "reflect"
+ "unsafe"
)
var (
- reflectRtypeItab = findReflectRtypeItab()
+ reflectRtypeItab = findReflectRtypeItab()
)
// GoType.KindFlags const
const (
- F_direct = 1 << 5
- F_kind_mask = (1 << 5) - 1
+ F_direct = 1 << 5
+ F_kind_mask = (1 << 5) - 1
)
// GoType.Flags const
const (
- tflagUncommon uint8 = 1 << 0
- tflagExtraStar uint8 = 1 << 1
- tflagNamed uint8 = 1 << 2
- tflagRegularMemory uint8 = 1 << 3
+ tflagUncommon uint8 = 1 << 0
+ tflagExtraStar uint8 = 1 << 1
+ tflagNamed uint8 = 1 << 2
+ tflagRegularMemory uint8 = 1 << 3
)
type GoType struct {
- Size uintptr
- PtrData uintptr
- Hash uint32
- Flags uint8
- Align uint8
- FieldAlign uint8
- KindFlags uint8
- Traits unsafe.Pointer
- GCData *byte
- Str int32
- PtrToSelf int32
+ Size uintptr
+ PtrData uintptr
+ Hash uint32
+ Flags uint8
+ Align uint8
+ FieldAlign uint8
+ KindFlags uint8
+ Traits unsafe.Pointer
+ GCData *byte
+ Str int32
+ PtrToSelf int32
}
func (self *GoType) IsNamed() bool {
- return (self.Flags & tflagNamed) != 0
+ return (self.Flags & tflagNamed) != 0
}
func (self *GoType) Kind() reflect.Kind {
- return reflect.Kind(self.KindFlags & F_kind_mask)
+ return reflect.Kind(self.KindFlags & F_kind_mask)
}
func (self *GoType) Pack() (t reflect.Type) {
- (*GoIface)(unsafe.Pointer(&t)).Itab = reflectRtypeItab
- (*GoIface)(unsafe.Pointer(&t)).Value = unsafe.Pointer(self)
- return
+ (*GoIface)(unsafe.Pointer(&t)).Itab = reflectRtypeItab
+ (*GoIface)(unsafe.Pointer(&t)).Value = unsafe.Pointer(self)
+ return
}
func (self *GoType) String() string {
- return self.Pack().String()
+ return self.Pack().String()
}
func (self *GoType) Indirect() bool {
- return self.KindFlags & F_direct == 0
+ return self.KindFlags&F_direct == 0
}
type GoMap struct {
- Count int
- Flags uint8
- B uint8
- Overflow uint16
- Hash0 uint32
- Buckets unsafe.Pointer
- OldBuckets unsafe.Pointer
- Evacuate uintptr
- Extra unsafe.Pointer
+ Count int
+ Flags uint8
+ B uint8
+ Overflow uint16
+ Hash0 uint32
+ Buckets unsafe.Pointer
+ OldBuckets unsafe.Pointer
+ Evacuate uintptr
+ Extra unsafe.Pointer
}
type GoMapIterator struct {
- K unsafe.Pointer
- V unsafe.Pointer
- T *GoMapType
- H *GoMap
- Buckets unsafe.Pointer
- Bptr *unsafe.Pointer
- Overflow *[]unsafe.Pointer
- OldOverflow *[]unsafe.Pointer
- StartBucket uintptr
- Offset uint8
- Wrapped bool
- B uint8
- I uint8
- Bucket uintptr
- CheckBucket uintptr
+ K unsafe.Pointer
+ V unsafe.Pointer
+ T *GoMapType
+ H *GoMap
+ Buckets unsafe.Pointer
+ Bptr *unsafe.Pointer
+ Overflow *[]unsafe.Pointer
+ OldOverflow *[]unsafe.Pointer
+ StartBucket uintptr
+ Offset uint8
+ Wrapped bool
+ B uint8
+ I uint8
+ Bucket uintptr
+ CheckBucket uintptr
}
type GoItab struct {
- it unsafe.Pointer
- Vt *GoType
- hv uint32
- _ [4]byte
- fn [1]uintptr
+ it unsafe.Pointer
+ Vt *GoType
+ hv uint32
+ _ [4]byte
+ fn [1]uintptr
}
type GoIface struct {
- Itab *GoItab
- Value unsafe.Pointer
+ Itab *GoItab
+ Value unsafe.Pointer
}
type GoEface struct {
- Type *GoType
- Value unsafe.Pointer
+ Type *GoType
+ Value unsafe.Pointer
}
func (self GoEface) Pack() (v interface{}) {
- *(*GoEface)(unsafe.Pointer(&v)) = self
- return
+ *(*GoEface)(unsafe.Pointer(&v)) = self
+ return
}
type GoPtrType struct {
- GoType
- Elem *GoType
+ GoType
+ Elem *GoType
}
type GoMapType struct {
- GoType
- Key *GoType
- Elem *GoType
- Bucket *GoType
- Hasher func(unsafe.Pointer, uintptr) uintptr
- KeySize uint8
- ElemSize uint8
- BucketSize uint16
- Flags uint32
+ GoType
+ Key *GoType
+ Elem *GoType
+ Bucket *GoType
+ Hasher func(unsafe.Pointer, uintptr) uintptr
+ KeySize uint8
+ ElemSize uint8
+ BucketSize uint16
+ Flags uint32
}
func (self *GoMapType) IndirectElem() bool {
- return self.Flags & 2 != 0
+ return self.Flags&2 != 0
}
type GoStructType struct {
- GoType
- Pkg *byte
- Fields []GoStructField
+ GoType
+ Pkg *byte
+ Fields []GoStructField
}
type GoStructField struct {
- Name *byte
- Type *GoType
- OffEmbed uintptr
+ Name *byte
+ Type *GoType
+ OffEmbed uintptr
}
type GoInterfaceType struct {
- GoType
- PkgPath *byte
- Methods []GoInterfaceMethod
+ GoType
+ PkgPath *byte
+ Methods []GoInterfaceMethod
}
type GoInterfaceMethod struct {
- Name int32
- Type int32
+ Name int32
+ Type int32
}
type GoSlice struct {
- Ptr unsafe.Pointer
- Len int
- Cap int
+ Ptr unsafe.Pointer
+ Len int
+ Cap int
}
type GoString struct {
- Ptr unsafe.Pointer
- Len int
+ Ptr unsafe.Pointer
+ Len int
}
func PtrElem(t *GoType) *GoType {
- return (*GoPtrType)(unsafe.Pointer(t)).Elem
+ return (*GoPtrType)(unsafe.Pointer(t)).Elem
}
func MapType(t *GoType) *GoMapType {
- return (*GoMapType)(unsafe.Pointer(t))
+ return (*GoMapType)(unsafe.Pointer(t))
}
func IfaceType(t *GoType) *GoInterfaceType {
- return (*GoInterfaceType)(unsafe.Pointer(t))
+ return (*GoInterfaceType)(unsafe.Pointer(t))
}
func UnpackType(t reflect.Type) *GoType {
- return (*GoType)((*GoIface)(unsafe.Pointer(&t)).Value)
+ return (*GoType)((*GoIface)(unsafe.Pointer(&t)).Value)
}
func UnpackEface(v interface{}) GoEface {
- return *(*GoEface)(unsafe.Pointer(&v))
+ return *(*GoEface)(unsafe.Pointer(&v))
}
func UnpackIface(v interface{}) GoIface {
- return *(*GoIface)(unsafe.Pointer(&v))
+ return *(*GoIface)(unsafe.Pointer(&v))
}
func findReflectRtypeItab() *GoItab {
- v := reflect.TypeOf(struct{}{})
- return (*GoIface)(unsafe.Pointer(&v)).Itab
+ v := reflect.TypeOf(struct{}{})
+ return (*GoIface)(unsafe.Pointer(&v)).Itab
}
func AssertI2I2(t *GoType, i GoIface) (r GoIface) {
- inter := IfaceType(t)
+ inter := IfaceType(t)
tab := i.Itab
if tab == nil {
return
}
if (*GoInterfaceType)(tab.it) != inter {
- tab = Getitab(inter, tab.Vt, true)
+ tab = GetItab(inter, tab.Vt, true)
if tab == nil {
return
}
@@ -229,15 +229,33 @@ func AssertI2I2(t *GoType, i GoIface) (r GoIface) {
return
}
+func (t *GoType) IsInt64() bool {
+ return t.Kind() == reflect.Int64 || (t.Kind() == reflect.Int && t.Size == 8)
+}
+
+func (t *GoType) IsInt32() bool {
+ return t.Kind() == reflect.Int32 || (t.Kind() == reflect.Int && t.Size == 4)
+}
+
+//go:nosplit
+func (t *GoType) IsUint64() bool {
+ isUint := t.Kind() == reflect.Uint || t.Kind() == reflect.Uintptr
+ return t.Kind() == reflect.Uint64 || (isUint && t.Size == 8)
+}
+
+//go:nosplit
+func (t *GoType) IsUint32() bool {
+ isUint := t.Kind() == reflect.Uint || t.Kind() == reflect.Uintptr
+ return t.Kind() == reflect.Uint32 || (isUint && t.Size == 4)
+}
+
+//go:nosplit
+func PtrAdd(ptr unsafe.Pointer, offset uintptr) unsafe.Pointer {
+ return unsafe.Pointer(uintptr(ptr) + offset)
+}
+
//go:noescape
-//go:linkname Getitab runtime.getitab
-func Getitab(inter *GoInterfaceType, typ *GoType, canfail bool) *GoItab
+//go:linkname GetItab runtime.getitab
+func GetItab(inter *GoInterfaceType, typ *GoType, canfail bool) *GoItab
-func GetFuncPC(fn interface{}) uintptr {
- ft := UnpackEface(fn)
- if ft.Type.Kind() != reflect.Func {
- panic("not a function")
- }
- return *(*uintptr)(ft.Value)
-} \ No newline at end of file
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/gcwb.go b/vendor/github.com/bytedance/sonic/internal/rt/gcwb.go
index c3217c899..9c670e721 100644
--- a/vendor/github.com/bytedance/sonic/internal/rt/gcwb.go
+++ b/vendor/github.com/bytedance/sonic/internal/rt/gcwb.go
@@ -1,3 +1,5 @@
+// +build go1.21
+
/*
* Copyright 2021 ByteDance Inc.
*
@@ -17,13 +19,18 @@
package rt
import (
- `os`
`sync/atomic`
`unsafe`
`golang.org/x/arch/x86/x86asm`
)
+//go:linkname GcWriteBarrier2 runtime.gcWriteBarrier2
+func GcWriteBarrier2()
+
+//go:linkname RuntimeWriteBarrier runtime.writeBarrier
+var RuntimeWriteBarrier uintptr
+
const (
_MaxInstr = 15
)
@@ -76,49 +83,3 @@ func GcwbAddr() uintptr {
}
}
-// StopProfiling is used to stop traceback introduced by SIGPROF while native code is running.
-// WARN: this option is only a workaround for traceback issue (https://github.com/bytedance/sonic/issues/310),
-// and will be dropped when the issue is fixed.
-var StopProfiling = os.Getenv("SONIC_STOP_PROFILING") != ""
-
-// WARN: must be aligned with runtime.Prof
-// type Prof struct {
-// signalLock uint32
-// hz int32
-// }
-
-var (
- // // go:linkname runtimeProf runtime.prof
- // runtimeProf Prof
-
- // count of native-C calls
- yieldCount uint32
-
- // previous value of runtimeProf.hz
- oldHz int32
-)
-
-//go:nosplit
-func MoreStack(size uintptr)
-
-func StopProf()
-
-// func StopProf() {
-// atomic.AddUint32(&yieldCount, 1)
-// if runtimeProf.hz != 0 {
-// oldHz = runtimeProf.hz
-// runtimeProf.hz = 0
-// }
-// }
-
-func StartProf()
-
-// func StartProf() {
-// atomic.AddUint32(&yieldCount, ^uint32(0))
-// if yieldCount == 0 && runtimeProf.hz == 0 {
-// if oldHz == 0 {
-// oldHz = 100
-// }
-// runtimeProf.hz = oldHz
-// }
-// }
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/gcwb_legacy.go b/vendor/github.com/bytedance/sonic/internal/rt/gcwb_legacy.go
new file mode 100644
index 000000000..86e14f2b2
--- /dev/null
+++ b/vendor/github.com/bytedance/sonic/internal/rt/gcwb_legacy.go
@@ -0,0 +1,29 @@
+// +build go1.16,!go1.21
+
+/*
+ * Copyright 2021 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 rt
+
+import (
+ _ `unsafe`
+)
+
+//go:linkname GcWriteBarrierAX runtime.gcWriteBarrier
+func GcWriteBarrierAX()
+
+//go:linkname RuntimeWriteBarrier runtime.writeBarrier
+var RuntimeWriteBarrier uintptr
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/growslice.go b/vendor/github.com/bytedance/sonic/internal/rt/growslice.go
new file mode 100644
index 000000000..fe182a5c9
--- /dev/null
+++ b/vendor/github.com/bytedance/sonic/internal/rt/growslice.go
@@ -0,0 +1,36 @@
+// +build go1.20
+
+/*
+ * Copyright 2021 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 rt
+
+import "unsafe"
+
+// Growslice to newCap, not append length
+// Note: the [old, newCap) will not be zeroed if et does not have any ptr data.
+func GrowSlice(et *GoType, old GoSlice, newCap int) GoSlice {
+ if newCap < old.Len {
+ panic("growslice's newCap is smaller than old length")
+ }
+ s := growslice(old.Ptr, newCap, old.Cap, newCap - old.Len, et)
+ s.Len = old.Len
+ return s
+}
+
+//go:linkname growslice runtime.growslice
+//goland:noinspection GoUnusedParameter
+func growslice(oldPtr unsafe.Pointer, newLen, oldCap, num int, et *GoType) GoSlice
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/growslice_legacy.go b/vendor/github.com/bytedance/sonic/internal/rt/growslice_legacy.go
new file mode 100644
index 000000000..2456ffbbb
--- /dev/null
+++ b/vendor/github.com/bytedance/sonic/internal/rt/growslice_legacy.go
@@ -0,0 +1,27 @@
+// +build go1.16,!go1.20
+
+/*
+ * Copyright 2021 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 rt
+
+import (
+ _ `unsafe`
+)
+
+//go:linkname GrowSlice runtime.growslice
+//goland:noinspection GoUnusedParameter
+func GrowSlice(et *GoType, old GoSlice, cap int) GoSlice
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/pool.go b/vendor/github.com/bytedance/sonic/internal/rt/pool.go
new file mode 100644
index 000000000..60545b1ff
--- /dev/null
+++ b/vendor/github.com/bytedance/sonic/internal/rt/pool.go
@@ -0,0 +1,31 @@
+package rt
+
+import (
+ "unsafe"
+)
+
+type SlicePool struct {
+ pool unsafe.Pointer
+ len int
+ index int
+ typ uintptr
+}
+
+func NewPool(typ *GoType, size int) SlicePool {
+ return SlicePool{pool: newarray(typ, size), len: size, typ: uintptr(unsafe.Pointer(typ))}
+}
+
+func (self *SlicePool) GetSlice(size int) unsafe.Pointer {
+ // pool is full, fallback to normal alloc
+ if size > self.Remain() {
+ return newarray(AsGoType(self.typ), size)
+ }
+
+ ptr := PtrAdd(self.pool, uintptr(self.index)* AsGoType(self.typ).Size)
+ self.index += size
+ return ptr
+}
+
+func (self *SlicePool) Remain() int {
+ return self.len - self.index
+}
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/stackmap.go b/vendor/github.com/bytedance/sonic/internal/rt/stackmap.go
index 84ed9a95f..024912029 100644
--- a/vendor/github.com/bytedance/sonic/internal/rt/stackmap.go
+++ b/vendor/github.com/bytedance/sonic/internal/rt/stackmap.go
@@ -178,4 +178,4 @@ func (self *StackMapBuilder) AddFields(n int, ptr bool) {
} else {
self.b.AppendMany(n, 0)
}
-} \ No newline at end of file
+}
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/stubs.go b/vendor/github.com/bytedance/sonic/internal/rt/stubs.go
new file mode 100644
index 000000000..5104a0793
--- /dev/null
+++ b/vendor/github.com/bytedance/sonic/internal/rt/stubs.go
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2021 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 rt
+
+import (
+ "reflect"
+ "unsafe"
+)
+
+//go:noescape
+//go:linkname Memmove runtime.memmove
+func Memmove(to unsafe.Pointer, from unsafe.Pointer, n uintptr)
+
+//go:linkname Mapiternext runtime.mapiternext
+func Mapiternext(it *GoMapIterator)
+
+//go:linkname Mapiterinit runtime.mapiterinit
+func Mapiterinit(t *GoMapType, m *GoMap, it *GoMapIterator)
+
+//go:linkname IsValidNumber encoding/json.isValidNumber
+func IsValidNumber(s string) bool
+
+//go:nosplit
+//go:linkname MemclrHasPointers runtime.memclrHasPointers
+//goland:noinspection GoUnusedParameter
+func MemclrHasPointers(ptr unsafe.Pointer, n uintptr)
+
+//go:linkname MemclrNoHeapPointers runtime.memclrNoHeapPointers
+//goland:noinspection GoUnusedParameter
+func MemclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
+
+//go:linkname newarray runtime.newarray
+func newarray(typ *GoType, n int) unsafe.Pointer
+
+func add(p unsafe.Pointer, x uintptr) unsafe.Pointer {
+ return unsafe.Pointer(uintptr(p) + x)
+}
+
+func ClearMemory(et *GoType, ptr unsafe.Pointer, size uintptr) {
+ if et.PtrData == 0 {
+ MemclrNoHeapPointers(ptr, size)
+ } else {
+ MemclrHasPointers(ptr, size)
+ }
+}
+
+// runtime.maxElementSize
+const _max_map_element_size uintptr = 128
+
+func IsMapfast(vt reflect.Type) bool {
+ return vt.Elem().Size() <= _max_map_element_size
+}
+
+//go:linkname Mallocgc runtime.mallocgc
+//goland:noinspection GoUnusedParameter
+func Mallocgc(size uintptr, typ *GoType, needzero bool) unsafe.Pointer
+
+//go:linkname Makemap reflect.makemap
+func Makemap(*GoType, int) unsafe.Pointer
+
+//go:linkname Mapassign runtime.mapassign
+//goland:noinspection GoUnusedParameter
+func Mapassign(t *GoMapType, h unsafe.Pointer, k unsafe.Pointer) unsafe.Pointer
+
+//go:linkname Mapassign_fast32 runtime.mapassign_fast32
+//goland:noinspection GoUnusedParameter
+func Mapassign_fast32(t *GoMapType, h unsafe.Pointer, k uint32) unsafe.Pointer
+
+//go:linkname Mapassign_fast64 runtime.mapassign_fast64
+//goland:noinspection GoUnusedParameter
+func Mapassign_fast64(t *GoMapType, h unsafe.Pointer, k uint64) unsafe.Pointer
+
+//go:linkname Mapassign_faststr runtime.mapassign_faststr
+//goland:noinspection GoUnusedParameter
+func Mapassign_faststr(t *GoMapType, h unsafe.Pointer, s string) unsafe.Pointer
+
+type MapStrAssign func (t *GoMapType, h unsafe.Pointer, s string) unsafe.Pointer
+
+func GetMapStrAssign(vt reflect.Type) MapStrAssign {
+ if IsMapfast(vt) {
+ return Mapassign_faststr
+ } else {
+ return func (t *GoMapType, h unsafe.Pointer, s string) unsafe.Pointer {
+ return Mapassign(t, h, unsafe.Pointer(&s))
+ }
+ }
+}
+
+type Map32Assign func(t *GoMapType, h unsafe.Pointer, k uint32) unsafe.Pointer
+
+func GetMap32Assign(vt reflect.Type) Map32Assign {
+ if IsMapfast(vt) {
+ return Mapassign_fast32
+ } else {
+ return func (t *GoMapType, h unsafe.Pointer, s uint32) unsafe.Pointer {
+ return Mapassign(t, h, unsafe.Pointer(&s))
+ }
+ }
+}
+
+type Map64Assign func(t *GoMapType, h unsafe.Pointer, k uint64) unsafe.Pointer
+
+func GetMap64Assign(vt reflect.Type) Map64Assign {
+ if IsMapfast(vt) {
+ return Mapassign_fast64
+ } else {
+ return func (t *GoMapType, h unsafe.Pointer, s uint64) unsafe.Pointer {
+ return Mapassign(t, h, unsafe.Pointer(&s))
+ }
+ }
+}
+
+
+var emptyBytes = make([]byte, 0, 0)
+var EmptySlice = *(*GoSlice)(unsafe.Pointer(&emptyBytes))
+
+//go:linkname makeslice runtime.makeslice
+//goland:noinspection GoUnusedParameter
+func makeslice(et *GoType, len int, cap int) unsafe.Pointer
+
+func MakeSlice(oldPtr unsafe.Pointer, et *GoType, newLen int) *GoSlice {
+ if newLen == 0 {
+ return &EmptySlice
+ }
+
+ if *(*unsafe.Pointer)(oldPtr) == nil {
+ return &GoSlice{
+ Ptr: makeslice(et, newLen, newLen),
+ Len: newLen,
+ Cap: newLen,
+ }
+ }
+
+ old := (*GoSlice)(oldPtr)
+ if old.Cap >= newLen {
+ old.Len = newLen
+ return old
+ }
+
+ new := GrowSlice(et, *old, newLen)
+
+ // we sould clear the memory from [oldLen:newLen]
+ if et.PtrData == 0 {
+ oldlenmem := uintptr(old.Len) * et.Size
+ newlenmem := uintptr(newLen) * et.Size
+ MemclrNoHeapPointers(add(new.Ptr, oldlenmem), newlenmem-oldlenmem)
+ }
+
+ new.Len = newLen
+ return &new
+}
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/table.go b/vendor/github.com/bytedance/sonic/internal/rt/table.go
new file mode 100644
index 000000000..7d49f90e4
--- /dev/null
+++ b/vendor/github.com/bytedance/sonic/internal/rt/table.go
@@ -0,0 +1,118 @@
+// Copyright 2024 CloudWeGo Authors
+//
+// 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
+//
+// https://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 rt
+
+import "unicode/utf8"
+
+var SafeSet = [utf8.RuneSelf]bool{
+ ' ': true,
+ '!': true,
+ '"': false,
+ '#': true,
+ '$': true,
+ '%': true,
+ '&': true,
+ '\'': true,
+ '(': true,
+ ')': true,
+ '*': true,
+ '+': true,
+ ',': true,
+ '-': true,
+ '.': true,
+ '/': true,
+ '0': true,
+ '1': true,
+ '2': true,
+ '3': true,
+ '4': true,
+ '5': true,
+ '6': true,
+ '7': true,
+ '8': true,
+ '9': true,
+ ':': true,
+ ';': true,
+ '<': true,
+ '=': true,
+ '>': true,
+ '?': true,
+ '@': true,
+ 'A': true,
+ 'B': true,
+ 'C': true,
+ 'D': true,
+ 'E': true,
+ 'F': true,
+ 'G': true,
+ 'H': true,
+ 'I': true,
+ 'J': true,
+ 'K': true,
+ 'L': true,
+ 'M': true,
+ 'N': true,
+ 'O': true,
+ 'P': true,
+ 'Q': true,
+ 'R': true,
+ 'S': true,
+ 'T': true,
+ 'U': true,
+ 'V': true,
+ 'W': true,
+ 'X': true,
+ 'Y': true,
+ 'Z': true,
+ '[': true,
+ '\\': false,
+ ']': true,
+ '^': true,
+ '_': true,
+ '`': true,
+ 'a': true,
+ 'b': true,
+ 'c': true,
+ 'd': true,
+ 'e': true,
+ 'f': true,
+ 'g': true,
+ 'h': true,
+ 'i': true,
+ 'j': true,
+ 'k': true,
+ 'l': true,
+ 'm': true,
+ 'n': true,
+ 'o': true,
+ 'p': true,
+ 'q': true,
+ 'r': true,
+ 's': true,
+ 't': true,
+ 'u': true,
+ 'v': true,
+ 'w': true,
+ 'x': true,
+ 'y': true,
+ 'z': true,
+ '{': true,
+ '|': true,
+ '}': true,
+ '~': true,
+ '\u007f': true,
+}
+
+var Hex = "0123456789abcdef"
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/types.go b/vendor/github.com/bytedance/sonic/internal/rt/types.go
new file mode 100644
index 000000000..2c9aaa583
--- /dev/null
+++ b/vendor/github.com/bytedance/sonic/internal/rt/types.go
@@ -0,0 +1,45 @@
+package rt
+
+import (
+ "reflect"
+ "unsafe"
+ "encoding/json"
+)
+
+func AsGoType(t uintptr) *GoType {
+ return (*GoType)(unsafe.Pointer(t))
+}
+
+var (
+ BoolType = UnpackType(reflect.TypeOf(false))
+ ByteType = UnpackType(reflect.TypeOf(byte(0)))
+ IncntType = UnpackType(reflect.TypeOf(int(0)))
+ Int8Type = UnpackType(reflect.TypeOf(int8(0)))
+ Int16Type = UnpackType(reflect.TypeOf(int16(0)))
+ Int32Type = UnpackType(reflect.TypeOf(int32(0)))
+ Int64Type = UnpackType(reflect.TypeOf(int64(0)))
+ UintType = UnpackType(reflect.TypeOf(uint(0)))
+ Uint8Type = UnpackType(reflect.TypeOf(uint8(0)))
+ Uint16Type = UnpackType(reflect.TypeOf(uint16(0)))
+ Uint32Type = UnpackType(reflect.TypeOf(uint32(0)))
+ Uint64Type = UnpackType(reflect.TypeOf(uint64(0)))
+ Float32Type = UnpackType(reflect.TypeOf(float32(0)))
+ Float64Type = UnpackType(reflect.TypeOf(float64(0)))
+
+ StringType = UnpackType(reflect.TypeOf(""))
+ BytesType = UnpackType(reflect.TypeOf([]byte(nil)))
+ JsonNumberType = UnpackType(reflect.TypeOf(json.Number("")))
+
+ SliceEfaceType = UnpackType(reflect.TypeOf([]interface{}(nil)))
+ SliceStringType = UnpackType(reflect.TypeOf([]string(nil)))
+ SliceI32Type = UnpackType(reflect.TypeOf([]int32(nil)))
+ SliceI64Type = UnpackType(reflect.TypeOf([]int64(nil)))
+ SliceU32Type = UnpackType(reflect.TypeOf([]uint32(nil)))
+ SliceU64Type = UnpackType(reflect.TypeOf([]uint64(nil)))
+
+ AnyType = UnpackType(reflect.TypeOf((*interface{})(nil)).Elem())
+ MapEfaceType = UnpackType(reflect.TypeOf(map[string]interface{}(nil)))
+ MapStringType = UnpackType(reflect.TypeOf(map[string]string(nil)))
+
+ MapEfaceMapType = MapType(UnpackType(reflect.TypeOf(map[string]interface{}(nil))))
+)