Home | History | Annotate | Download | only in runtime
      1 // Copyright 2010 The Go Authors.  All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 // Export guts for testing.
      6 
      7 package runtime
      8 
      9 import "unsafe"
     10 
     11 var Fadd64 = fadd64
     12 var Fsub64 = fsub64
     13 var Fmul64 = fmul64
     14 var Fdiv64 = fdiv64
     15 var F64to32 = f64to32
     16 var F32to64 = f32to64
     17 var Fcmp64 = fcmp64
     18 var Fintto64 = fintto64
     19 var F64toint = f64toint
     20 var Sqrt = sqrt
     21 
     22 var Entersyscall = entersyscall
     23 var Exitsyscall = exitsyscall
     24 var LockedOSThread = lockedOSThread
     25 var Xadduintptr = xadduintptr
     26 
     27 var FuncPC = funcPC
     28 
     29 type LFNode struct {
     30 	Next    uint64
     31 	Pushcnt uintptr
     32 }
     33 
     34 func LFStackPush(head *uint64, node *LFNode) {
     35 	lfstackpush(head, (*lfnode)(unsafe.Pointer(node)))
     36 }
     37 
     38 func LFStackPop(head *uint64) *LFNode {
     39 	return (*LFNode)(unsafe.Pointer(lfstackpop(head)))
     40 }
     41 
     42 type ParFor struct {
     43 	body   func(*ParFor, uint32)
     44 	done   uint32
     45 	Nthr   uint32
     46 	thrseq uint32
     47 	Cnt    uint32
     48 	wait   bool
     49 }
     50 
     51 func NewParFor(nthrmax uint32) *ParFor {
     52 	var desc *ParFor
     53 	systemstack(func() {
     54 		desc = (*ParFor)(unsafe.Pointer(parforalloc(nthrmax)))
     55 	})
     56 	return desc
     57 }
     58 
     59 func ParForSetup(desc *ParFor, nthr, n uint32, wait bool, body func(*ParFor, uint32)) {
     60 	systemstack(func() {
     61 		parforsetup((*parfor)(unsafe.Pointer(desc)), nthr, n, wait,
     62 			*(*func(*parfor, uint32))(unsafe.Pointer(&body)))
     63 	})
     64 }
     65 
     66 func ParForDo(desc *ParFor) {
     67 	systemstack(func() {
     68 		parfordo((*parfor)(unsafe.Pointer(desc)))
     69 	})
     70 }
     71 
     72 func ParForIters(desc *ParFor, tid uint32) (uint32, uint32) {
     73 	desc1 := (*parfor)(unsafe.Pointer(desc))
     74 	pos := desc1.thr[tid].pos
     75 	return uint32(pos), uint32(pos >> 32)
     76 }
     77 
     78 func GCMask(x interface{}) (ret []byte) {
     79 	systemstack(func() {
     80 		ret = getgcmask(x)
     81 	})
     82 	return
     83 }
     84 
     85 func RunSchedLocalQueueTest() {
     86 	testSchedLocalQueue()
     87 }
     88 func RunSchedLocalQueueStealTest() {
     89 	testSchedLocalQueueSteal()
     90 }
     91 
     92 var StringHash = stringHash
     93 var BytesHash = bytesHash
     94 var Int32Hash = int32Hash
     95 var Int64Hash = int64Hash
     96 var EfaceHash = efaceHash
     97 var IfaceHash = ifaceHash
     98 var MemclrBytes = memclrBytes
     99 
    100 var HashLoad = &hashLoad
    101 
    102 // entry point for testing
    103 func GostringW(w []uint16) (s string) {
    104 	systemstack(func() {
    105 		s = gostringw(&w[0])
    106 	})
    107 	return
    108 }
    109 
    110 var Gostringnocopy = gostringnocopy
    111 var Maxstring = &maxstring
    112 
    113 type Uintreg uintreg
    114 
    115 var Open = open
    116 var Close = closefd
    117 var Read = read
    118 var Write = write
    119 
    120 func Envs() []string     { return envs }
    121 func SetEnvs(e []string) { envs = e }
    122 
    123 var BigEndian = _BigEndian
    124 
    125 // For benchmarking.
    126 
    127 func BenchSetType(n int, x interface{}) {
    128 	e := *(*eface)(unsafe.Pointer(&x))
    129 	t := e._type
    130 	var size uintptr
    131 	var p unsafe.Pointer
    132 	switch t.kind & kindMask {
    133 	case _KindPtr:
    134 		t = (*ptrtype)(unsafe.Pointer(t)).elem
    135 		size = t.size
    136 		p = e.data
    137 	case _KindSlice:
    138 		slice := *(*struct {
    139 			ptr      unsafe.Pointer
    140 			len, cap uintptr
    141 		})(e.data)
    142 		t = (*slicetype)(unsafe.Pointer(t)).elem
    143 		size = t.size * slice.len
    144 		p = slice.ptr
    145 	}
    146 	allocSize := roundupsize(size)
    147 	systemstack(func() {
    148 		for i := 0; i < n; i++ {
    149 			heapBitsSetType(uintptr(p), allocSize, size, t)
    150 		}
    151 	})
    152 }
    153 
    154 const PtrSize = ptrSize
    155 
    156 var TestingAssertE2I2GC = &testingAssertE2I2GC
    157 var TestingAssertE2T2GC = &testingAssertE2T2GC
    158