1
0
mirror of https://github.com/golang/go synced 2024-11-25 05:27:57 -07:00

fix 386 malloc tests,

detect 386 darwin breakpoint line.

R=r
DELTA=22  (4 added, 0 deleted, 18 changed)
OCL=29929
CL=29944
This commit is contained in:
Russ Cox 2009-06-05 10:59:37 -07:00
parent 4f30ec7fcb
commit b014be75d2
6 changed files with 22 additions and 18 deletions

View File

@ -17,7 +17,7 @@ type Stats struct {
EnableGC bool; EnableGC bool;
} }
func Alloc(uint64) *byte func Alloc(uintptr) *byte
func Free(*byte) func Free(*byte)
func GetStats() *Stats func GetStats() *Stats
func Lookup(*byte) (*byte, uintptr) func Lookup(*byte) (*byte, uintptr)

View File

@ -212,7 +212,7 @@ gc(int32 force)
else else
gcpercent = atoi(p); gcpercent = atoi(p);
} }
if(gcpercent < 0 || sizeof(void*) == 4) // TODO(rsc): broken on 32-bit right now if(gcpercent < 0)
return; return;
semacquire(&gcsema); semacquire(&gcsema);

View File

@ -39,13 +39,13 @@ func prime() {
b := malloc.Alloc(1<<uint(i)); b := malloc.Alloc(1<<uint(i));
malloc.Free(b); malloc.Free(b);
} }
for i := uint64(0); i < 256; i++ { for i := uintptr(0); i < 256; i++ {
b := malloc.Alloc(i<<12); b := malloc.Alloc(i<<12);
malloc.Free(b); malloc.Free(b);
} }
} }
func memset(b *byte, c byte, n uint64) { func memset(b *byte, c byte, n uintptr) {
np := uintptr(n); np := uintptr(n);
for i := uintptr(0); i < np; i++ { for i := uintptr(0); i < np; i++ {
*(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(b))+i)) = c; *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(b))+i)) = c;
@ -55,7 +55,7 @@ func memset(b *byte, c byte, n uint64) {
func main() { func main() {
flag.Parse(); flag.Parse();
// prime(); // prime();
var blocks [1] struct { base *byte; siz uint64; }; var blocks [1] struct { base *byte; siz uintptr; };
for i := 0; i < 1<<12; i++ { for i := 0; i < 1<<12; i++ {
if i%(1<<10) == 0 && *chatty { if i%(1<<10) == 0 && *chatty {
println(i); println(i);
@ -65,19 +65,19 @@ func main() {
// println("Free", blocks[b].siz, blocks[b].base); // println("Free", blocks[b].siz, blocks[b].base);
malloc.Free(blocks[b].base); malloc.Free(blocks[b].base);
blocks[b].base = nil; blocks[b].base = nil;
allocated -= blocks[b].siz; allocated -= uint64(blocks[b].siz);
continue continue
} }
siz := uint64(rand.Int() >> (11 + rand.Uint32() % 20)); siz := uintptr(rand.Int() >> (11 + rand.Uint32() % 20));
base := malloc.Alloc(siz); base := malloc.Alloc(siz);
// ptr := uint64(syscall.BytePtr(base))+uint64(siz/2); // ptr := uintptr(syscall.BytePtr(base))+uintptr(siz/2);
// obj, size, ref, ok := allocator.find(ptr); // obj, size, ref, ok := allocator.find(ptr);
// if obj != base || *ref != 0 || !ok { // if obj != base || *ref != 0 || !ok {
// panicln("find", siz, obj, ref, ok); // panicln("find", siz, obj, ref, ok);
// } // }
blocks[b].base = base; blocks[b].base = base;
blocks[b].siz = siz; blocks[b].siz = siz;
allocated += siz; allocated += uint64(siz);
// println("Alloc", siz, base); // println("Alloc", siz, base);
memset(base, 0xbb, siz); memset(base, 0xbb, siz);
bigger(); bigger();

View File

@ -36,11 +36,14 @@ func main() {
if i == 0 && *chatty { if i == 0 && *chatty {
println("First alloc:", j); println("First alloc:", j);
} }
b := malloc.Alloc(uint64(j)); if a := malloc.GetStats().Alloc; a != 0 {
panicln("no allocations but stats report", a, "bytes allocated");
}
b := malloc.Alloc(uintptr(j));
during := malloc.GetStats().Alloc; during := malloc.GetStats().Alloc;
malloc.Free(b); malloc.Free(b);
if a := malloc.GetStats().Alloc; a != 0 { if a := malloc.GetStats().Alloc; a != 0 {
panicln("malloc wrong count", a, "after", j, "during", during); panic("allocated ", j, ": wrong stats: during=", during, " after=", a, " (want 0)");
} }
bigger(); bigger();
} }

View File

@ -44,7 +44,7 @@ func AllocAndFree(size, count int) {
} }
n1 := stats.Alloc; n1 := stats.Alloc;
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
b[i] = malloc.Alloc(uint64(size)); b[i] = malloc.Alloc(uintptr(size));
base, n := malloc.Lookup(b[i]); base, n := malloc.Lookup(b[i]);
if base != b[i] || !OkAmount(uintptr(size), n) { if base != b[i] || !OkAmount(uintptr(size), n) {
panicln("lookup failed: got", base, n, "for", b[i]); panicln("lookup failed: got", base, n, "for", b[i]);
@ -63,14 +63,14 @@ func AllocAndFree(size, count int) {
if *reverse { if *reverse {
i = count - 1 - j; i = count - 1 - j;
} }
alloc := stats.Alloc; alloc := uintptr(stats.Alloc);
base, n := malloc.Lookup(b[i]); base, n := malloc.Lookup(b[i]);
if base != b[i] || !OkAmount(uintptr(size), n) { if base != b[i] || !OkAmount(uintptr(size), n) {
panicln("lookup failed: got", base, n, "for", b[i]); panicln("lookup failed: got", base, n, "for", b[i]);
} }
malloc.Free(b[i]); malloc.Free(b[i]);
if stats.Alloc != alloc - uint64(n) { if stats.Alloc != uint64(alloc - n) {
panicln("free alloc got", stats.Alloc, "expected", alloc - uint64(n), "after free of", n); panicln("free alloc got", stats.Alloc, "expected", alloc - n, "after free of", n);
} }
if malloc.GetStats().Sys > 1e9 { if malloc.GetStats().Sys > 1e9 {
panicln("too much memory allocated"); panicln("too much memory allocated");
@ -100,12 +100,12 @@ func main() {
} }
for j := 1; j <= 1<<22; j<<=1 { for j := 1; j <= 1<<22; j<<=1 {
n := len(b); n := len(b);
max := uint64(1<<28); max := uintptr(1<<28);
if !*longtest { if !*longtest {
max = 1<<22; max = 1<<22;
} }
if uint64(j)*uint64(n) > max { if uintptr(j)*uintptr(n) > max {
n = int(max / uint64(j)); n = int(max / uintptr(j));
} }
if n < 10 { if n < 10 {
n = 10; n = 10;

View File

@ -67,6 +67,7 @@ done | # clean up some stack noise
s/ PC=0x[0-9a-f]*/ PC=xxx/ s/ PC=0x[0-9a-f]*/ PC=xxx/
s/^pc: 0x[0-9a-f]*/pc: xxx/ s/^pc: 0x[0-9a-f]*/pc: xxx/
/^Trace\/breakpoint trap/d /^Trace\/breakpoint trap/d
/^Trace\/BPT trap/d
/RUNFILE/ s/line 1: *[0-9]*/line 1: PID/ /RUNFILE/ s/line 1: *[0-9]*/line 1: PID/
/^\$RUNFILE: line 1: PID Trace\/breakpoint trap/d' > run.out /^\$RUNFILE: line 1: PID Trace\/breakpoint trap/d' > run.out