Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(8)

Side by Side Diff: src/pkg/runtime/gc_test.go

Issue 7913043: code review 7913043: runtime: prevent garbage collection during hashmap insertion (Closed)
Patch Set: diff -r 657df9ab8e4d https://code.google.com/p/go/ Created 12 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/pkg/runtime/hashmap.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package runtime_test 5 package runtime_test
6 6
7 import ( 7 import (
8 "os" 8 "os"
9 "runtime" 9 "runtime"
10 "runtime/debug"
10 "testing" 11 "testing"
11 ) 12 )
12 13
13 func TestGcSys(t *testing.T) { 14 func TestGcSys(t *testing.T) {
14 if os.Getenv("GOGC") == "off" { 15 if os.Getenv("GOGC") == "off" {
15 t.Fatalf("GOGC=off in environment; test cannot pass") 16 t.Fatalf("GOGC=off in environment; test cannot pass")
16 } 17 }
17 data := struct{ Short bool }{testing.Short()} 18 data := struct{ Short bool }{testing.Short()}
18 got := executeTest(t, testGCSysSource, &data) 19 got := executeTest(t, testGCSysSource, &data)
19 want := "OK\n" 20 want := "OK\n"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // This makes sure new(T) is allocated on heap, not on the stack. 76 // This makes sure new(T) is allocated on heap, not on the stack.
76 t.Logf("%p", a) 77 t.Logf("%p", a)
77 78
78 a[0][0][0][0][0][0][0][0][0][0] = new(int) 79 a[0][0][0][0][0][0][0][0][0][0] = new(int)
79 *a[0][0][0][0][0][0][0][0][0][0] = 13 80 *a[0][0][0][0][0][0][0][0][0][0] = 13
80 runtime.GC() 81 runtime.GC()
81 if *a[0][0][0][0][0][0][0][0][0][0] != 13 { 82 if *a[0][0][0][0][0][0][0][0][0][0] != 13 {
82 t.Fail() 83 t.Fail()
83 } 84 }
84 } 85 }
86
87 func TestGcHashmapIndirection(t *testing.T) {
88 defer debug.SetGCPercent(debug.SetGCPercent(1))
89 runtime.GC()
90 type T struct {
91 a [256]int
92 }
93 m := make(map[T]T)
94 for i := 0; i < 2000; i++ {
95 var a T
96 a.a[0] = i
97 m[a] = T{}
98 }
99 }
OLDNEW
« no previous file with comments | « no previous file | src/pkg/runtime/hashmap.c » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b