Created
January 29, 2014 16:56
-
-
Save mrkn/8692143 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GC_DEBUG = false | |
CHAR_BIT = 8 | |
BITS_SIZE = 8 | |
BITS_BITLENGTH = BITS_SIZE * CHAR_BIT | |
SIZEOF_RVALUE = GC_DEBUG ? 56 : 40 | |
SIZEOF_SIZE_T = 8 | |
SIZEOF_STRUCT_HEAP_PAGE_HEADER = 8 | |
def ceildiv(i, mod) | |
((i + mod - 1) / mod).to_i | |
end | |
HEAP_ALIGN_LOG = 14 | |
HEAP_ALIGN = 1 << HEAP_ALIGN_LOG | |
HEAP_ALIGN_MASK = ~(~0 << HEAP_ALIGN_LOG) | |
REQUIRED_SIZE_BY_MALLOC = SIZEOF_SIZE_T * 5 | |
HEAP_SIZE = HEAP_ALIGN - REQUIRED_SIZE_BY_MALLOC | |
HEAP_OBJ_LIMIT = ((HEAP_SIZE - SIZEOF_STRUCT_HEAP_PAGE_HEADER)/SIZEOF_RVALUE).to_i | |
HEAP_BITMAP_LIMIT = ceildiv(ceildiv(HEAP_SIZE, SIZEOF_RVALUE), BITS_BITLENGTH) | |
HEAP_BITMAP_SIZE = (BITS_SIZE * HEAP_BITMAP_LIMIT) | |
HEAP_BITMAP_PLANES = 3 | |
def num_in_page(p) | |
((p & HEAP_ALIGN_MASK) / SIZEOF_RVALUE).to_i | |
end | |
def bitmap_index(p) | |
num_in_page(p) / BITS_BITLENGTH | |
end | |
def page_start_limit(page_body) | |
start = page_body + SIZEOF_STRUCT_HEAP_PAGE_HEADER | |
limit = HEAP_OBJ_LIMIT | |
if start % SIZEOF_RVALUE != 0 | |
delta = SIZEOF_RVALUE - (start % SIZEOF_RVALUE) | |
start = start + delta | |
limit = ((HEAP_SIZE - (start - page_body))/SIZEOF_RVALUE).to_i | |
end | |
[ start, limit ] | |
end | |
0.step(HEAP_ALIGN, SIZEOF_SIZE_T) do |addr| | |
start, limit = page_start_limit(addr) | |
nip = num_in_page(start) | |
offset = start - nip | |
bi = bitmap_index(start) | |
sub = start - addr | |
p body: addr, start: start, limit: limit, offset: offset if sub == nip | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment