处理AI胡乱生成的乱摊子
This commit is contained in:
42
vendor/github.com/bytedance/sonic/internal/rt/asm_amd64.s
generated
vendored
42
vendor/github.com/bytedance/sonic/internal/rt/asm_amd64.s
generated
vendored
@@ -1,4 +1,4 @@
|
||||
// +build !noasm !appengine
|
||||
// +build !noasm,amd64 !appengine,amd64
|
||||
// Code generated by asm2asm, DO NOT EDIT·
|
||||
|
||||
#include "go_asm.h"
|
||||
@@ -18,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
|
||||
|
||||
10
vendor/github.com/bytedance/sonic/internal/rt/asm_arm64.s
generated
vendored
10
vendor/github.com/bytedance/sonic/internal/rt/asm_arm64.s
generated
vendored
@@ -1,10 +0,0 @@
|
||||
// +build !noasm !appengine
|
||||
// Code generated by asm2asm, DO NOT EDIT.
|
||||
|
||||
#include "go_asm.h"
|
||||
#include "funcdata.h"
|
||||
#include "textflag.h"
|
||||
|
||||
TEXT ·MoreStack(SB), NOSPLIT, $0 - 8
|
||||
NO_LOCAL_POINTERS
|
||||
RET
|
||||
39
vendor/github.com/bytedance/sonic/internal/rt/fastmem.go
generated
vendored
39
vendor/github.com/bytedance/sonic/internal/rt/fastmem.go
generated
vendored
@@ -17,8 +17,10 @@
|
||||
package rt
|
||||
|
||||
import (
|
||||
`unsafe`
|
||||
`reflect`
|
||||
"reflect"
|
||||
"unsafe"
|
||||
|
||||
"github.com/bytedance/sonic/option"
|
||||
)
|
||||
|
||||
//go:nosplit
|
||||
@@ -66,15 +68,16 @@ func FuncAddr(f interface{}) unsafe.Pointer {
|
||||
}
|
||||
}
|
||||
|
||||
//go:nocheckptr
|
||||
func IndexChar(src string, index int) unsafe.Pointer {
|
||||
return unsafe.Pointer(uintptr((*GoString)(unsafe.Pointer(&src)).Ptr) + uintptr(index))
|
||||
}
|
||||
|
||||
//go:nocheckptr
|
||||
func IndexByte(ptr []byte, index int) unsafe.Pointer {
|
||||
return unsafe.Pointer(uintptr((*GoSlice)(unsafe.Pointer(&ptr)).Ptr) + uintptr(index))
|
||||
}
|
||||
|
||||
//go:nosplit
|
||||
func GuardSlice(buf *[]byte, n int) {
|
||||
c := cap(*buf)
|
||||
l := len(*buf)
|
||||
@@ -89,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{
|
||||
@@ -121,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)
|
||||
}
|
||||
}
|
||||
|
||||
//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)
|
||||
}
|
||||
|
||||
226
vendor/github.com/bytedance/sonic/internal/rt/fastvalue.go
generated
vendored
226
vendor/github.com/bytedance/sonic/internal/rt/fastvalue.go
generated
vendored
@@ -17,197 +17,215 @@
|
||||
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
|
||||
}
|
||||
|
||||
type GoMap struct {
|
||||
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
|
||||
return self.KindFlags&F_direct == 0
|
||||
}
|
||||
|
||||
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)
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
55
vendor/github.com/bytedance/sonic/internal/rt/gcwb.go
generated
vendored
55
vendor/github.com/bytedance/sonic/internal/rt/gcwb.go
generated
vendored
@@ -1,3 +1,5 @@
|
||||
// +build go1.21,!go1.26
|
||||
|
||||
/*
|
||||
* 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
|
||||
// }
|
||||
// }
|
||||
|
||||
6
vendor/github.com/bytedance/sonic/internal/rt/int48.go
generated
vendored
6
vendor/github.com/bytedance/sonic/internal/rt/int48.go
generated
vendored
@@ -17,12 +17,12 @@
|
||||
package rt
|
||||
|
||||
const (
|
||||
MinInt48 = -(1 << 47)
|
||||
MaxInt48 = +(1 << 47) - 1
|
||||
MinInt48 int64 = -(1 << 47)
|
||||
MaxInt48 int64 = +(1 << 47) - 1
|
||||
)
|
||||
|
||||
func PackInt(v int) uint64 {
|
||||
if u := uint64(v); v < MinInt48 || v > MaxInt48 {
|
||||
if u := uint64(v); int64(v) < MinInt48 || int64(v) > MaxInt48 {
|
||||
panic("int48 out of range")
|
||||
} else {
|
||||
return ((u >> 63) << 47) | (u & 0x00007fffffffffff)
|
||||
|
||||
181
vendor/github.com/bytedance/sonic/internal/rt/stackmap.go
generated
vendored
181
vendor/github.com/bytedance/sonic/internal/rt/stackmap.go
generated
vendored
@@ -1,181 +0,0 @@
|
||||
/**
|
||||
* Copyright 2023 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 (
|
||||
`fmt`
|
||||
`strings`
|
||||
`unsafe`
|
||||
|
||||
)
|
||||
|
||||
type Bitmap struct {
|
||||
N int
|
||||
B []byte
|
||||
}
|
||||
|
||||
func (self *Bitmap) grow() {
|
||||
if self.N >= len(self.B) * 8 {
|
||||
self.B = append(self.B, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Bitmap) mark(i int, bv int) {
|
||||
if bv != 0 {
|
||||
self.B[i / 8] |= 1 << (i % 8)
|
||||
} else {
|
||||
self.B[i / 8] &^= 1 << (i % 8)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Bitmap) Set(i int, bv int) {
|
||||
if i >= self.N {
|
||||
panic("bitmap: invalid bit position")
|
||||
} else {
|
||||
self.mark(i, bv)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Bitmap) Append(bv int) {
|
||||
self.grow()
|
||||
self.mark(self.N, bv)
|
||||
self.N++
|
||||
}
|
||||
|
||||
func (self *Bitmap) AppendMany(n int, bv int) {
|
||||
for i := 0; i < n; i++ {
|
||||
self.Append(bv)
|
||||
}
|
||||
}
|
||||
|
||||
// var (
|
||||
// _stackMapLock = sync.Mutex{}
|
||||
// _stackMapCache = make(map[*StackMap]struct{})
|
||||
// )
|
||||
|
||||
type BitVec struct {
|
||||
N uintptr
|
||||
B unsafe.Pointer
|
||||
}
|
||||
|
||||
func (self BitVec) Bit(i uintptr) byte {
|
||||
return (*(*byte)(unsafe.Pointer(uintptr(self.B) + i / 8)) >> (i % 8)) & 1
|
||||
}
|
||||
|
||||
func (self BitVec) String() string {
|
||||
var i uintptr
|
||||
var v []string
|
||||
|
||||
/* add each bit */
|
||||
for i = 0; i < self.N; i++ {
|
||||
v = append(v, fmt.Sprintf("%d", self.Bit(i)))
|
||||
}
|
||||
|
||||
/* join them together */
|
||||
return fmt.Sprintf(
|
||||
"BitVec { %s }",
|
||||
strings.Join(v, ", "),
|
||||
)
|
||||
}
|
||||
|
||||
type StackMap struct {
|
||||
N int32
|
||||
L int32
|
||||
B [1]byte
|
||||
}
|
||||
|
||||
// func (self *StackMap) add() {
|
||||
// _stackMapLock.Lock()
|
||||
// _stackMapCache[self] = struct{}{}
|
||||
// _stackMapLock.Unlock()
|
||||
// }
|
||||
|
||||
func (self *StackMap) Pin() uintptr {
|
||||
// self.add()
|
||||
return uintptr(unsafe.Pointer(self))
|
||||
}
|
||||
|
||||
func (self *StackMap) Get(i int32) BitVec {
|
||||
return BitVec {
|
||||
N: uintptr(self.L),
|
||||
B: unsafe.Pointer(uintptr(unsafe.Pointer(&self.B)) + uintptr(i * ((self.L + 7) >> 3))),
|
||||
}
|
||||
}
|
||||
|
||||
func (self *StackMap) String() string {
|
||||
sb := strings.Builder{}
|
||||
sb.WriteString("StackMap {")
|
||||
|
||||
/* dump every stack map */
|
||||
for i := int32(0); i < self.N; i++ {
|
||||
sb.WriteRune('\n')
|
||||
sb.WriteString(" " + self.Get(i).String())
|
||||
}
|
||||
|
||||
/* close the stackmap */
|
||||
sb.WriteString("\n}")
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func (self *StackMap) MarshalBinary() ([]byte, error) {
|
||||
size := int(self.N) * int(self.L) + int(unsafe.Sizeof(self.L)) + int(unsafe.Sizeof(self.N))
|
||||
return BytesFrom(unsafe.Pointer(self), size, size), nil
|
||||
}
|
||||
|
||||
var (
|
||||
byteType = UnpackEface(byte(0)).Type
|
||||
)
|
||||
|
||||
const (
|
||||
_StackMapSize = unsafe.Sizeof(StackMap{})
|
||||
)
|
||||
|
||||
//go:linkname mallocgc runtime.mallocgc
|
||||
//goland:noinspection GoUnusedParameter
|
||||
func mallocgc(nb uintptr, vt *GoType, zero bool) unsafe.Pointer
|
||||
|
||||
type StackMapBuilder struct {
|
||||
b Bitmap
|
||||
}
|
||||
|
||||
//go:nocheckptr
|
||||
func (self *StackMapBuilder) Build() (p *StackMap) {
|
||||
nb := len(self.b.B)
|
||||
bm := mallocgc(_StackMapSize + uintptr(nb) - 1, byteType, false)
|
||||
|
||||
/* initialize as 1 bitmap of N bits */
|
||||
p = (*StackMap)(bm)
|
||||
p.N, p.L = 1, int32(self.b.N)
|
||||
copy(BytesFrom(unsafe.Pointer(&p.B), nb, nb), self.b.B)
|
||||
return
|
||||
}
|
||||
|
||||
func (self *StackMapBuilder) AddField(ptr bool) {
|
||||
if ptr {
|
||||
self.b.Append(1)
|
||||
} else {
|
||||
self.b.Append(0)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *StackMapBuilder) AddFields(n int, ptr bool) {
|
||||
if ptr {
|
||||
self.b.AppendMany(n, 1)
|
||||
} else {
|
||||
self.b.AppendMany(n, 0)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user