File: writebarrier.go

package info (click to toggle)
golang-1.24 1.24.2-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 168,184 kB
  • sloc: asm: 154,896; ansic: 7,009; sh: 2,226; javascript: 1,705; perl: 1,052; python: 421; makefile: 103; cpp: 39; f90: 8; awk: 7; objc: 4
file content (90 lines) | stat: -rw-r--r-- 2,328 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// asmcheck

// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package codegen

func combine2string(p *[2]string, a, b string) {
	// amd64:`.*runtime[.]gcWriteBarrier4\(SB\)`
	// arm64:`.*runtime[.]gcWriteBarrier4\(SB\)`
	p[0] = a
	// amd64:-`.*runtime[.]gcWriteBarrier`
	// arm64:-`.*runtime[.]gcWriteBarrier`
	p[1] = b
}

func combine4string(p *[4]string, a, b, c, d string) {
	// amd64:`.*runtime[.]gcWriteBarrier8\(SB\)`
	// arm64:`.*runtime[.]gcWriteBarrier8\(SB\)`
	p[0] = a
	// amd64:-`.*runtime[.]gcWriteBarrier`
	// arm64:-`.*runtime[.]gcWriteBarrier`
	p[1] = b
	// amd64:-`.*runtime[.]gcWriteBarrier`
	// arm64:-`.*runtime[.]gcWriteBarrier`
	p[2] = c
	// amd64:-`.*runtime[.]gcWriteBarrier`
	// arm64:-`.*runtime[.]gcWriteBarrier`
	p[3] = d
}

func combine2slice(p *[2][]byte, a, b []byte) {
	// amd64:`.*runtime[.]gcWriteBarrier4\(SB\)`
	// arm64:`.*runtime[.]gcWriteBarrier4\(SB\)`
	p[0] = a
	// amd64:-`.*runtime[.]gcWriteBarrier`
	// arm64:-`.*runtime[.]gcWriteBarrier`
	p[1] = b
}

func combine4slice(p *[4][]byte, a, b, c, d []byte) {
	// amd64:`.*runtime[.]gcWriteBarrier8\(SB\)`
	// arm64:`.*runtime[.]gcWriteBarrier8\(SB\)`
	p[0] = a
	// amd64:-`.*runtime[.]gcWriteBarrier`
	// arm64:-`.*runtime[.]gcWriteBarrier`
	p[1] = b
	// amd64:-`.*runtime[.]gcWriteBarrier`
	// arm64:-`.*runtime[.]gcWriteBarrier`
	p[2] = c
	// amd64:-`.*runtime[.]gcWriteBarrier`
	// arm64:-`.*runtime[.]gcWriteBarrier`
	p[3] = d
}

func trickyWriteNil(p *int, q **int) {
	if p == nil {
		// We change "= p" to "= 0" in the prove pass, which
		// means we have one less pointer that needs to go
		// into the write barrier buffer.
		// amd64:`.*runtime[.]gcWriteBarrier1`
		*q = p
	}
}

type S struct {
	a, b string
	c    *int
}

var g1, g2 *int

func issue71228(dst *S, ptr *int) {
	// Make sure that the non-write-barrier write.
	// "sp.c = ptr" happens before the large write
	// barrier "*dst = *sp". We approximate testing
	// that by ensuring that two global variable write
	// barriers aren't combined.
	_ = *dst
	var s S
	sp := &s
	//amd64:`.*runtime[.]gcWriteBarrier1`
	g1 = nil
	sp.c = ptr // outside of any write barrier
	//amd64:`.*runtime[.]gcWriteBarrier1`
	g2 = nil
	//amd64:`.*runtime[.]wbMove`
	*dst = *sp
}