OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [mallocrep.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $G $D/$F.go && $L $F.$A && ./$A.out
2
 
3
// Copyright 2009 The Go Authors. All rights reserved.
4
// Use of this source code is governed by a BSD-style
5
// license that can be found in the LICENSE file.
6
 
7
// Repeated malloc test.
8
 
9
package main
10
 
11
import (
12
        "flag"
13
        "runtime"
14
)
15
 
16
var chatty = flag.Bool("v", false, "chatty")
17
 
18
var oldsys uint64
19
var memstats runtime.MemStats
20
 
21
func bigger() {
22
        st := &memstats
23
        runtime.ReadMemStats(st)
24
        if oldsys < st.Sys {
25
                oldsys = st.Sys
26
                if *chatty {
27
                        println(st.Sys, " system bytes for ", st.Alloc, " Go bytes")
28
                }
29
                if st.Sys > 1e9 {
30
                        println("too big")
31
                        panic("fail")
32
                }
33
        }
34
}
35
 
36
func main() {
37
        runtime.GC()                    // clean up garbage from init
38
        runtime.ReadMemStats(&memstats) // first call can do some allocations
39
        runtime.MemProfileRate = 0      // disable profiler
40
        stacks := memstats.Alloc        // ignore stacks
41
        flag.Parse()
42
        for i := 0; i < 1<<7; i++ {
43
                for j := 1; j <= 1<<22; j <<= 1 {
44
                        if i == 0 && *chatty {
45
                                println("First alloc:", j)
46
                        }
47
                        if a := memstats.Alloc - stacks; a != 0 {
48
                                println("no allocations but stats report", a, "bytes allocated")
49
                                panic("fail")
50
                        }
51
                        b := runtime.Alloc(uintptr(j))
52
                        runtime.ReadMemStats(&memstats)
53
                        during := memstats.Alloc - stacks
54
                        runtime.Free(b)
55
                        runtime.ReadMemStats(&memstats)
56
                        if a := memstats.Alloc - stacks; a != 0 {
57
                                println("allocated ", j, ": wrong stats: during=", during, " after=", a, " (want 0)")
58
                                panic("fail")
59
                        }
60
                        bigger()
61
                }
62
                if i%(1<<10) == 0 && *chatty {
63
                        println(i)
64
                }
65
                if i == 0 {
66
                        if *chatty {
67
                                println("Primed", i)
68
                        }
69
                        //      runtime.frozen = true
70
                }
71
        }
72
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.