Skip to content

Commit 2bf582f

Browse files
committed
Do not access runtime function for size calculation
Fixes #64
1 parent 0696445 commit 2bf582f

File tree

11 files changed

+612
-19
lines changed

11 files changed

+612
-19
lines changed

.github/workflows/go.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
- uses: actions/checkout@v2
1515
- uses: actions/setup-go@v2
1616
with:
17-
go-version: 1.20.x
17+
go-version: 1.23.x
1818
- name: Cache
19-
uses: actions/cache@v2
19+
uses: actions/cache@v4
2020
with:
2121
path: |
2222
~/go/bin
@@ -35,7 +35,7 @@ jobs:
3535
- uses: actions/checkout@v2
3636
- uses: actions/setup-go@v2
3737
with:
38-
go-version: 1.20.x
38+
go-version: 1.23.x
3939
- run: go install golang.org/dl/gotip@latest
4040
- run: gotip download
4141
- run: gotip version

go.mod

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
module github.com/orijtech/structslop
22

3-
go 1.20
3+
go 1.23.0
4+
5+
toolchain go1.24.6
46

57
require (
68
github.com/dave/dst v0.27.2
7-
golang.org/x/tools v0.8.0
9+
golang.org/x/tools v0.36.0
810
)
911

1012
require (
11-
golang.org/x/mod v0.10.0 // indirect
12-
golang.org/x/sys v0.7.0 // indirect
13+
golang.org/x/mod v0.27.0 // indirect
14+
golang.org/x/sync v0.16.0 // indirect
1315
)

go.sum

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
github.com/dave/dst v0.27.2 h1:4Y5VFTkhGLC1oddtNwuxxe36pnyLxMFXT51FOzH8Ekc=
22
github.com/dave/dst v0.27.2/go.mod h1:jHh6EOibnHgcUW3WjKHisiooEkYwqpHLBSX1iOBhEyc=
33
github.com/dave/jennifer v1.5.0 h1:HmgPN93bVDpkQyYbqhCHj5QlgvUkvEOzMyEvKLgCRrg=
4+
github.com/dave/jennifer v1.5.0/go.mod h1:4MnyiFIlZS3l5tSDn8VnzE6ffAhYBMB2SZntBsZGUok=
5+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
6+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
47
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
5-
golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
6-
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
7-
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
8-
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
9-
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
10-
golang.org/x/tools v0.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y=
11-
golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4=
8+
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
9+
golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ=
10+
golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc=
11+
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
12+
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
13+
golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg=
14+
golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s=

internal/runtime/gc/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2009 The Go Authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following disclaimer
11+
in the documentation and/or other materials provided with the
12+
distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived from
15+
this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

internal/runtime/gc/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Original Source
2+
This code is a fork of the internal/runtime/gc package from the official Go programming language repository.
3+
4+
Original Repository: https://go.googlesource.com/go
5+
6+
# License
7+
The original source code of the Go project is licensed under a BSD-style license. The terms of this license permit redistribution and use in source and binary forms, with or without modification, provided that certain conditions are met, including retaining the copyright notice and disclaimer.
8+
9+
All modifications and additions made in this repository are also subject to the same BSD-style license.
10+
11+
A copy of the full license text can be found in the LICENSE file within this repository.
12+
13+
# Disclaimer
14+
This project is provided "as is," without warranty of any kind. Use at your own risk.

internal/runtime/gc/malloc.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package gc
6+
7+
const (
8+
ptrBits = 8 * PtrSize
9+
10+
// A malloc header is functionally a single type pointer, but
11+
// we need to use 8 here to ensure 8-byte alignment of allocations
12+
// on 32-bit platforms. It's wasteful, but a lot of code relies on
13+
// 8-byte alignment for 8-byte atomics.
14+
MallocHeaderSize = 8
15+
16+
// The minimum object size that has a malloc header, exclusive.
17+
//
18+
// The size of this value controls overheads from the malloc header.
19+
// The minimum size is bound by writeHeapBitsSmall, which assumes that the
20+
// pointer bitmap for objects of a size smaller than this doesn't cross
21+
// more than one pointer-word boundary. This sets an upper-bound on this
22+
// value at the number of bits in a uintptr, multiplied by the pointer
23+
// size in bytes.
24+
//
25+
// We choose a value here that has a natural cutover point in terms of memory
26+
// overheads. This value just happens to be the maximum possible value this
27+
// can be.
28+
//
29+
// A span with heap bits in it will have 128 bytes of heap bits on 64-bit
30+
// platforms, and 256 bytes of heap bits on 32-bit platforms. The first size
31+
// class where malloc headers match this overhead for 64-bit platforms is
32+
// 512 bytes (8 KiB / 512 bytes * 8 bytes-per-header = 128 bytes of overhead).
33+
// On 32-bit platforms, this same point is the 256 byte size class
34+
// (8 KiB / 256 bytes * 8 bytes-per-header = 256 bytes of overhead).
35+
//
36+
// Guaranteed to be exactly at a size class boundary. The reason this value is
37+
// an exclusive minimum is subtle. Suppose we're allocating a 504-byte object
38+
// and its rounded up to 512 bytes for the size class. If minSizeForMallocHeader
39+
// is 512 and an inclusive minimum, then a comparison against minSizeForMallocHeader
40+
// by the two values would produce different results. In other words, the comparison
41+
// would not be invariant to size-class rounding. Eschewing this property means a
42+
// more complex check or possibly storing additional state to determine whether a
43+
// span has malloc headers.
44+
MinSizeForMallocHeader = PtrSize * ptrBits
45+
46+
// PageSize is the increment in which spans are managed.
47+
PageSize = 1 << PageShift
48+
49+
PtrSize = 4 << (^uintptr(0) >> 63)
50+
)

0 commit comments

Comments
 (0)