Skip to content

Commit 266d350

Browse files
committed
runtime: fix MemStats on 32-bits
Int64's do not fit into uintptr's. LGTM=khr R=golang-codereviews, khr, rsc CC=golang-codereviews, rlh https://golang.org/cl/128380043
1 parent 5d40742 commit 266d350

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/pkg/runtime/gc_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ func TestGcLastTime(t *testing.T) {
164164
if t0 > last || last > t1 {
165165
t.Fatalf("bad last GC time: got %v, want [%v, %v]", last, t0, t1)
166166
}
167+
pause := ms.PauseNs[(ms.NumGC+255)%256]
168+
if pause == 0 || pause > 10e9 {
169+
t.Fatalf("bad last GC pause: got %v, want [0, 10e9]", pause)
170+
}
167171
}
168172

169173
var hugeSink interface{}

src/pkg/runtime/malloc.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,12 @@ func gogc(force int32) {
477477
startTime = gonanotime()
478478
}
479479
// switch to g0, call gc, then switch back
480-
mp.scalararg[0] = uint(startTime)
480+
mp.scalararg[0] = uint(uint32(startTime)) // low 32 bits
481+
mp.scalararg[1] = uint(startTime >> 32) // high 32 bits
481482
if force >= 2 {
482-
mp.scalararg[1] = 1 // eagersweep
483+
mp.scalararg[2] = 1 // eagersweep
483484
} else {
484-
mp.scalararg[1] = 0
485+
mp.scalararg[2] = 0
485486
}
486487
onM(&gc_m)
487488
}

src/pkg/runtime/mgc0.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,8 +1401,8 @@ runtime·gc_m(void)
14011401
gp->status = Gwaiting;
14021402
gp->waitreason = "garbage collection";
14031403

1404-
a.start_time = g->m->scalararg[0];
1405-
a.eagersweep = g->m->scalararg[1];
1404+
a.start_time = (uint64)(g->m->scalararg[0]) | ((uint64)(g->m->scalararg[1]) << 32);
1405+
a.eagersweep = g->m->scalararg[2];
14061406
gc(&a);
14071407

14081408
gp->status = Grunning;

0 commit comments

Comments
 (0)