OLD | NEW |
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 Loading... |
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 } |
OLD | NEW |