Skip to content

Commit

Permalink
move the 16-byte realignment offset to the start of the type pool rat…
Browse files Browse the repository at this point in the history
…her than every object (fix #10898)
  • Loading branch information
vtjnash committed Apr 24, 2015
1 parent 3961eed commit 8b8b261
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
extern "C" {
#endif

#define JL_ARRAY_ALIGN(jl_value, nbytes) (LLT_ALIGN((jl_value)+sizeof(jl_taggedvalue_t), nbytes)-sizeof(jl_taggedvalue_t))
#define JL_ARRAY_ALIGN(jl_value, nbytes) LLT_ALIGN(jl_value, nbytes)


// array constructors ---------------------------------------------------------
Expand Down
49 changes: 25 additions & 24 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ typedef struct _gcval_t {

#define GC_PAGE_LG2 14 // log2(size of a page)
#define GC_PAGE_SZ (1 << GC_PAGE_LG2) // 16k
#define GC_PAGE_OFFSET (16 - (sizeof(jl_taggedvalue_t) % 16))

// pool page metadata
typedef struct _gcpage_t {
Expand Down Expand Up @@ -219,7 +220,7 @@ typedef struct {
char pages[REGION_PG_COUNT][GC_PAGE_SZ]; // must be first, to preserve page alignment
uint32_t freemap[REGION_PG_COUNT/32];
gcpage_t meta[REGION_PG_COUNT];
} region_t;
} region_t __attribute__((aligned(GC_PAGE_SZ)));

This comment has been minimized.

Copy link
@tkelman

tkelman May 3, 2015

Contributor

Any idea how to do this for MSVC? I get segfaults in jl_setjmp on starting the repl ever since this commit (applying https://gist.github.com/ab1d03d18a51e2acc874 to get it to build and finish bootstrapping)

This comment has been minimized.

Copy link
@vtjnash

vtjnash May 3, 2015

Author Member

this is basically a no-op, so i wouldn't worry about it

This comment has been minimized.

Copy link
@vtjnash

vtjnash May 3, 2015

Author Member

can you check whether the object sizes are correct (such as buff_t, gcval_t, and bigval_t)? i don't see why they wouldn't be, but it would cause some issues if they diverged.

any idea if the segfault is a misaligned jmp_buf? i wonder if MS doesn't mark their jmp_buf as aligned(16), even though MinGW does

This comment has been minimized.

Copy link
@tkelman

tkelman May 3, 2015

Contributor

Well something in this commit is making jl_setjmp segfault. I also have a newer freeze during bootstrap that I'm still bisecting on.

This comment has been minimized.

Copy link
@tkelman

tkelman May 3, 2015

Contributor

can you check whether the object sizes are correct (such as buff_t, gcval_t, and bigval_t)?

Sure, if I knew how to check those.

There is

julia/src/gc.c

Lines 181 to 183 in dfac7d9

#if !defined(_COMPILER_MICROSOFT_)
int _dummy[0];
#endif
which may be making a difference?

This comment has been minimized.

Copy link
@vtjnash

vtjnash May 3, 2015

Author Member

gdb can manage it by calling p sizeof(buff_t). perhaps msvc can do the same? otherwise, you have to write a stub function that returns that value and call it in the debugger at runtime.

i just checked setjmp.h in my local msvc crt folder and see that the specification _CRT_ALIGN(16) is present

that's a 0-byte array, it shouldn't make any difference.

This comment has been minimized.

Copy link
@tkelman

tkelman May 3, 2015

Contributor
(29dc.1b80): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
*** WARNING: Unable to verify checksum for d:\code\msys64\home\Tony\julia\usr\bin\libjulia.dll
libjulia!jl_setjmp+0x3b:
000007fe`e0bd4f1b 0f297160        movaps  xmmword ptr [rcx+60h],xmm6 ds:00000000`0f0500c8=00000000000000000000000000000000
0:000> ?? sizeof(buff_t)
unsigned int64 8
0:000> ?? sizeof(gcval_t)
unsigned int64 8
0:000> ?? sizeof(bigval_t)
unsigned int64 0x20

This comment has been minimized.

Copy link
@vtjnash

vtjnash May 3, 2015

Author Member

Can you walk up the stack frames and determine why that element is misaligned?

This comment has been minimized.

Copy link
@tkelman

tkelman May 3, 2015

Contributor

With sufficient guidance, maybe. Will you be on IRC in about an hour?

This comment has been minimized.

Copy link
@tkelman

tkelman May 4, 2015

Contributor

this useful at all?

(3ac.1d80): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
*** WARNING: Unable to verify checksum for d:\code\msys64\home\Tony\julia\usr\bin\libjulia.dll
libjulia!jl_setjmp+0x3b:
000007fe`e22952bb 0f297160        movaps  xmmword ptr [rcx+60h],xmm6 ds:00000000`0f0500c8=00000000000000000000000000000000
0:000> k
Child-SP          RetAddr           Call Site
00000000`009ced28 000007fe`e22575a4 libjulia!jl_setjmp+0x3b
00000000`009ced30 000007fe`e2256777 libjulia!ctx_switch+0x34 [d:\code\msys64\home\tony\julia\src\task.c @ 295]
00000000`009ced70 00000000`00c4f9ab libjulia!jl_switchto+0x97 [d:\code\msys64\home\tony\julia\src\task.c @ 372]
00000000`009cedb0 000007fe`e2174ab9 0xc4f9ab
00000000`009cede0 000007fe`e2174e84 libjulia!jl_apply+0x29 [d:\code\msys64\home\tony\julia\src\julia.h @ 1277]
00000000`009cee10 000007fe`e2167b49 libjulia!jl_trampoline+0x44 [d:\code\msys64\home\tony\julia\src\builtins.c @ 1027]
00000000`009cee50 000007fe`e2167ede libjulia!jl_apply+0x29 [d:\code\msys64\home\tony\julia\src\julia.h @ 1277]
00000000`009cee80 00000000`00c3f09f libjulia!jl_apply_generic+0x21e [d:\code\msys64\home\tony\julia\src\gf.c @ 1720]
00000000`009cef00 00000000`00c4ec70 0xc3f09f
00000000`009cefc0 00000000`00c4f793 0xc4ec70
00000000`009cf140 00000000`00c4e556 0xc4f793
00000000`009cf2e0 00000000`00c4e46e 0xc4e556
00000000`009cf360 00000000`00c4e3c0 0xc4e46e
00000000`009cf3d0 00000000`00c4e30b 0xc4e3c0
00000000`009cf430 000007fe`e2174ab9 0xc4e30b
00000000`009cf460 000007fe`e2174e84 libjulia!jl_apply+0x29 [d:\code\msys64\home\tony\julia\src\julia.h @ 1277]
00000000`009cf490 000007fe`e2167b49 libjulia!jl_trampoline+0x44 [d:\code\msys64\home\tony\julia\src\builtins.c @ 1027]
00000000`009cf4d0 000007fe`e2167e13 libjulia!jl_apply+0x29 [d:\code\msys64\home\tony\julia\src\julia.h @ 1277]
00000000`009cf500 00000000`00c3c091 libjulia!jl_apply_generic+0x153 [d:\code\msys64\home\tony\julia\src\gf.c @ 1696]
00000000`009cf580 00000000`00c3ad7f 0xc3c091
0:000> .f+
01 00000000`009ced30 000007fe`e2256777 libjulia!ctx_switch+0x34 [d:\code\msys64\home\tony\julia\src\task.c @ 295]
0:000> .f-
00 00000000`009ced28 000007fe`e22575a4 libjulia!jl_setjmp+0x3b
0:000> u
libjulia!jl_setjmp+0x3b:
000007fe`e22952bb 0f297160        movaps  xmmword ptr [rcx+60h],xmm6
000007fe`e22952bf 0f297970        movaps  xmmword ptr [rcx+70h],xmm7
000007fe`e22952c3 440f298180000000 movaps  xmmword ptr [rcx+80h],xmm8
000007fe`e22952cb 440f298990000000 movaps  xmmword ptr [rcx+90h],xmm9
000007fe`e22952d3 440f2991a0000000 movaps  xmmword ptr [rcx+0A0h],xmm10
000007fe`e22952db 440f2999b0000000 movaps  xmmword ptr [rcx+0B0h],xmm11
000007fe`e22952e3 440f29a1c0000000 movaps  xmmword ptr [rcx+0C0h],xmm12
000007fe`e22952eb 440f29a9d0000000 movaps  xmmword ptr [rcx+0D0h],xmm13

This comment has been minimized.

Copy link
@vtjnash

vtjnash May 4, 2015

Author Member

not much. i'm interested in why the GC might have been handing out an unaligned address, since nothing about this change should have been compiler-specific. what is the address of the jl_task_t that contained the jl_jmp_buf and what is offsetof(jl_task_t, ctx)?

This comment has been minimized.

Copy link
@tkelman

tkelman May 4, 2015

Contributor
0:000> ?? jl_current_task
struct _jl_task_t * 0x00000000`0f050018
   +0x000 parent           : 0x00000000`0f050018 _jl_task_t
   +0x008 last             : 0x00000000`0f050018 _jl_task_t
   +0x010 tls              : 0x00000000`11636438 _jl_value_t
   +0x018 state            : 0x00000000`00db4c60 _jl_sym_t
   +0x020 consumers        : 0x00000000`0f028018 _jl_value_t
   +0x028 donenotify       : 0x00000000`0f028018 _jl_value_t
   +0x030 result           : 0x00000000`0f028018 _jl_value_t
   +0x038 exception        : 0x00000000`0f028018 _jl_value_t
   +0x040 start            : (null) 
   +0x050 ctx              : [16] _SETJMP_FLOAT128
   +0x150 bufsz            : 0
   +0x158 stkbuf           : (null) 
   +0x160 ssize            : 0
   +0x168 eh               : 0x00000000`009cefe0 _jl_handler_t
   +0x170 gcstack          : (null) 
   +0x178 current_module   : 0x00000000`0f058018 _jl_module_t

This comment has been minimized.

Copy link
@tkelman

tkelman May 4, 2015

Contributor
0:000> ?? ((size_t)(&((jl_task_t *)0)->ctx))
size_t 0x50

This comment has been minimized.

Copy link
@tkelman

tkelman May 4, 2015

Contributor

I might not have 634c9ac applied locally, will rebuild again

edit: no change

This comment has been minimized.

Copy link
@vtjnash

vtjnash May 4, 2015

Author Member

that patch is not correct (https://msdn.microsoft.com/en-us/library/6ewkz86d.aspx). but also not relevant here

This comment has been minimized.

Copy link
@tkelman

tkelman May 4, 2015

Contributor

where does the jl_task_t get allocated in the first place?

This comment has been minimized.

Copy link
@vtjnash

vtjnash May 4, 2015

Author Member

DLLEXPORT jl_task_t *jl_new_task(jl_function_t *start, size_t ssize)

This comment has been minimized.

Copy link
@tkelman

tkelman May 4, 2015

Contributor

side note: should allocobj probably be named jl_allocobj, considering it's exported?

It looks like it's the removal of the realign16 element from the jl_taggedvalue_t struct that causes the issue, and either this alignment of region_t is really critical or there's some other compiler-dependent alignment behavior that this change is relying on.

https://gist.github.com/tkelman/01bc8b7e4d42796c9810

This comment has been minimized.

Copy link
@tkelman

tkelman May 4, 2015

Contributor

Might also be a consequence of 4c06a18

I guess I could try putting back the realign16 element only for msvc

This comment has been minimized.

Copy link
@tkelman

tkelman May 13, 2015

Contributor

Any ideas on the alignment issue? If I try to add back the padding fields only in the MSVC case, but without selectively reverting any other parts of this commit, I get a gc access violation while compiling inference (probably not surprising?)

osutils.jl

Please submit a bug report with steps to reproduce this fault, and any error mes
sages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x7fedf1c3dd8 -- gc_setmark_pool at d:\
code\msys64\home\tony\julia\src\gc.c:601
gc_setmark_pool at d:\code\msys64\home\tony\julia\src\gc.c:601
push_root at d:\code\msys64\home\tony\julia\src\gc.c:1653
gc_push_root at d:\code\msys64\home\tony\julia\src\gc.c:1470
push_root at d:\code\msys64\home\tony\julia\src\gc.c:1739
gc_push_root at d:\code\msys64\home\tony\julia\src\gc.c:1470
push_root at d:\code\msys64\home\tony\julia\src\gc.c:1689
gc_push_root at d:\code\msys64\home\tony\julia\src\gc.c:1470
push_root at d:\code\msys64\home\tony\julia\src\gc.c:1739
gc_push_root at d:\code\msys64\home\tony\julia\src\gc.c:1470
gc_mark_stack at d:\code\msys64\home\tony\julia\src\gc.c:1509
gc_mark_task_stack at d:\code\msys64\home\tony\julia\src\gc.c:1563
gc_mark_task at d:\code\msys64\home\tony\julia\src\gc.c:1584
push_root at d:\code\msys64\home\tony\julia\src\gc.c:1706
gc_push_root at d:\code\msys64\home\tony\julia\src\gc.c:1470
pre_mark at d:\code\msys64\home\tony\julia\src\gc.c:1818
jl_gc_collect at d:\code\msys64\home\tony\julia\src\gc.c:2212
__pool_alloc at d:\code\msys64\home\tony\julia\src\gc.c:1040
_pool_alloc at d:\code\msys64\home\tony\julia\src\gc.c:1086
alloc_3w at d:\code\msys64\home\tony\julia\src\gc.c:2469
newobj at d:\code\msys64\home\tony\julia\src\julia_internal.h:26
jl_alloc_svec_uninit at d:\code\msys64\home\tony\julia\src\simplevector.c:56
inst_datatype at d:\code\msys64\home\tony\julia\src\jltypes.c:1962
inst_type_w_ at d:\code\msys64\home\tony\julia\src\jltypes.c:2212
jl_instantiate_type_with at d:\code\msys64\home\tony\julia\src\jltypes.c:2220
jl_apply_type_ at d:\code\msys64\home\tony\julia\src\jltypes.c:1699
jl_f_instantiate_type at d:\code\msys64\home\tony\julia\src\builtins.c:973
call at base.jl:294
jl_apply at d:\code\msys64\home\tony\julia\src\julia.h:1288
jl_apply_generic at d:\code\msys64\home\tony\julia\src\gf.c:1743
f_argnames at inference.jl:1242
jl_apply at d:\code\msys64\home\tony\julia\src\julia.h:1288
jl_apply_unspecialized at d:\code\msys64\home\tony\julia\src\gf.c:29
jl_apply_generic at d:\code\msys64\home\tony\julia\src\gf.c:1740
typeinf_uncached at inference.jl:1396
jl_apply at d:\code\msys64\home\tony\julia\src\julia.h:1288
jl_apply_unspecialized at d:\code\msys64\home\tony\julia\src\gf.c:29
jl_apply_generic at d:\code\msys64\home\tony\julia\src\gf.c:1740
typeinf at inference.jl:1307
jl_apply at d:\code\msys64\home\tony\julia\src\julia.h:1288
jl_apply_unspecialized at d:\code\msys64\home\tony\julia\src\gf.c:29
jl_apply_generic at d:\code\msys64\home\tony\julia\src\gf.c:1740
typeinf at inference.jl:1257
jl_apply at d:\code\msys64\home\tony\julia\src\julia.h:1288
jl_apply_unspecialized at d:\code\msys64\home\tony\julia\src\gf.c:29
jl_apply_generic at d:\code\msys64\home\tony\julia\src\gf.c:1740
abstract_call_gf at inference.jl:696
jl_apply at d:\code\msys64\home\tony\julia\src\julia.h:1288
jl_apply_generic at d:\code\msys64\home\tony\julia\src\gf.c:1743
abstract_call at inference.jl:823
jl_apply at d:\code\msys64\home\tony\julia\src\julia.h:1288
jl_apply_unspecialized at d:\code\msys64\home\tony\julia\src\gf.c:29
jl_apply_generic at d:\code\msys64\home\tony\julia\src\gf.c:1740
abstract_eval_call at inference.jl:904
jl_apply at d:\code\msys64\home\tony\julia\src\julia.h:1288
jl_apply_unspecialized at d:\code\msys64\home\tony\julia\src\gf.c:29
jl_apply_generic at d:\code\msys64\home\tony\julia\src\gf.c:1740
abstract_eval at inference.jl:961
jl_apply at d:\code\msys64\home\tony\julia\src\julia.h:1288
jl_apply_unspecialized at d:\code\msys64\home\tony\julia\src\gf.c:29
jl_apply_generic at d:\code\msys64\home\tony\julia\src\gf.c:1740
abstract_eval_call at inference.jl:881
jl_apply at d:\code\msys64\home\tony\julia\src\julia.h:1288
jl_apply_unspecialized at d:\code\msys64\home\tony\julia\src\gf.c:29
jl_apply_generic at d:\code\msys64\home\tony\julia\src\gf.c:1740
abstract_eval at inference.jl:961

This comment has been minimized.

Copy link
@vtjnash

vtjnash May 13, 2015

Author Member

you'll perhaps need to put equivalent padding on the bigval_t struct and gcval_t struct to keep them all in sync. i'm pretty sure this isn't the right approach however and you'll need to track down exactly why msvc is not compiling this code the same as gcc/clang.

This comment has been minimized.

Copy link
@tkelman

tkelman May 13, 2015

Contributor

Did the offsets look right? If I had to guess it might be the bit fields not playing correctly with uintptr_t? https://msdn.microsoft.com/en-us/library/yszfawxh.aspx

This comment has been minimized.

Copy link
@vtjnash

vtjnash Jun 19, 2015

Author Member

what is sizeof(jl_taggedvalue_t) (expected value: 8) and sizeof(jl_value_t) (expected value: 0)? perhaps msvc is does not like that zero?

This comment has been minimized.

Copy link
@tkelman

tkelman Jun 19, 2015

Contributor
0:000> ?? sizeof(jl_taggedvalue_t)
unsigned int64 0x10
0:000> ?? sizeof(jl_value_t)
unsigned int64 8

This comment has been minimized.

Copy link
@vtjnash

vtjnash Jun 19, 2015

Author Member

THAT'S IT! both of those have been computed wrong. most of the system should still hold together in that case, except that the jmpbuf struct will get misaligned, and when you hit a task switch ... SEGFAULT

This comment has been minimized.

Copy link
@tkelman

tkelman Jun 19, 2015

Contributor

It's highly likely that I did something hacky and wrong somewhere (4c06a18 maybe?) to satisfy the compilation, that broke these assumptions. It's pretty easy to test any fixes you may have, master has been building and bootstrapping (with one tiny int128 patch below, compiler-rt may fix this for us eventually) fine with msvc for a few weeks now.

diff --git a/base/string.jl b/base/string.jl
index 1542296..7b1f9ce 100644
--- a/base/string.jl
+++ b/base/string.jl
@@ -1562,7 +1562,7 @@ function tryparse_internal{T<:Integer}(::Type{T}, s::AbstractString, startpos::I
     end

     base = convert(T,base)
-    m::T = div(typemax(T)-base+1,base)
+    m::T = T===UInt128 || T===Int128 ? typemax(T) : div(typemax(T)-base+1,base)
     n::T = 0
     while n <= m
         d::T = '0' <= c <= '9' ? c-'0'    :

This comment has been minimized.

Copy link
@vtjnash

vtjnash Jun 19, 2015

Author Member

strictly speaking, the result was undefined (http://stackoverflow.com/questions/1626446/what-is-the-size-of-an-empty-struct-in-c). GCC just gave a good answer.

This comment has been minimized.

Copy link
@tkelman

tkelman Jun 19, 2015

Contributor

Hrm. Well if there's any hope of achieving the same end result without requiring a GCC extension, I'm all ears.

This comment has been minimized.

Copy link
@vtjnash

vtjnash Jun 19, 2015

Author Member

i think it's safe enough to just go through and replace them with a constant #define sizeof_jl_taggedvalue_t (8) statement

This comment has been minimized.

Copy link
@tkelman

tkelman Jun 19, 2015

Contributor

Good man! That did it, we have an MSVC-built REPL again! That doesn't seem like the most portable of hardcodings though, is it 2x pointer size? I don't have a 32 bit MSVC 2013 build of LLVM to try there.

This comment has been minimized.

Copy link
@tkelman

tkelman Jun 19, 2015

Contributor

All the tests up to numbers pass. That kind of amazes me.

This comment has been minimized.

Copy link
@vtjnash

vtjnash Jun 19, 2015

Author Member

i guess numbers test fails because it's missing int128 support?

sizeof_jl_tagged_value_t = sizeof(void*)
sizeof_jl_value_t = 0 (or #undef)

This comment has been minimized.

Copy link
@tkelman

tkelman Jun 19, 2015

Contributor

I didn't seem to need the latter? I'll open a PR shortly, should I make that second change too?

This comment has been minimized.

Copy link
@vtjnash

vtjnash Jun 19, 2015

Author Member

it's not much necessary. it looks like it is just used where we try to describe the jl_value_t to DWARF.

static region_t *regions[REGION_COUNT] = {NULL};
// store a lower bound of the first free page in each region
static int regions_lb[REGION_COUNT] = {0};
Expand All @@ -234,12 +235,12 @@ typedef struct _pool_t {
uint16_t nfree; // number of free objects in page pointed into by free_list
} pool_t;

#define PAGE_INDEX(region, data) ((GC_PAGE_DATA(data) - &(region)->pages[0][0])/GC_PAGE_SZ)
#define PAGE_INDEX(region, data) ((GC_PAGE_DATA((data) - GC_PAGE_OFFSET) - &(region)->pages[0][0])/GC_PAGE_SZ)
static region_t *find_region(void *ptr)
{
// on 64bit systems we could probably use a single region and remove this loop
for (int i = 0; i < REGION_COUNT && regions[i]; i++) {
if (regions[i] && (char*)ptr >= (char*)regions[i] && (char*)ptr <= (char*)regions[i] + sizeof(region_t))
if ((char*)ptr >= (char*)regions[i] && (char*)ptr <= (char*)regions[i] + sizeof(region_t))
return regions[i];
}
assert(0 && "find_region failed");
Expand All @@ -257,7 +258,7 @@ static uint8_t *page_age(gcpage_t *pg)
return pg->ages;
}

#define GC_POOL_END_OFS(osize) (((GC_PAGE_SZ/osize) - 1)*osize)
#define GC_POOL_END_OFS(osize) ((((GC_PAGE_SZ - GC_PAGE_OFFSET)/(osize)) - 1)*(osize) + GC_PAGE_OFFSET)


// layout for big (>2k) objects
Expand Down Expand Up @@ -701,7 +702,7 @@ static void free_page(void *p)
int pg_idx = -1;
int i;
for(i = 0; i < REGION_COUNT && regions[i] != NULL; i++) {
pg_idx = PAGE_INDEX(regions[i], p);
pg_idx = PAGE_INDEX(regions[i], (char*)p+GC_PAGE_OFFSET);
if (pg_idx >= 0 && pg_idx < REGION_PG_COUNT) break;
}
assert(i < REGION_COUNT && regions[i] != NULL);
Expand All @@ -717,7 +718,7 @@ static void free_page(void *p)
size_t n_pages = (GC_PAGE_SZ + system_page_size - 1) / GC_PAGE_SZ;
decommit_size = system_page_size;
p = (void*)((uintptr_t)&region->pages[pg_idx][0] & ~(system_page_size - 1)); // round down to the nearest page
pg_idx = PAGE_INDEX(region, p);
pg_idx = PAGE_INDEX(region, (char*)p+GC_PAGE_OFFSET);
if (pg_idx + n_pages > REGION_PG_COUNT) goto no_decommit;
for (; n_pages--; pg_idx++) {
msk = (uint32_t)(1 << ((pg_idx % 32)));
Expand Down Expand Up @@ -985,15 +986,15 @@ static void sweep_malloced_arrays(void)
static inline gcval_t *reset_page(pool_t *p, gcpage_t *pg, gcval_t *fl)
{
pg->gc_bits = 0;
pg->nfree = GC_PAGE_SZ/p->osize;
pg->nfree = (GC_PAGE_SZ - GC_PAGE_OFFSET) / p->osize;
pg->pool_n = p - norm_pools;
memset(page_age(pg), 0, (GC_PAGE_SZ/p->osize + 7)/8);
gcval_t *beg = (gcval_t*)pg->data;
memset(page_age(pg), 0, LLT_ALIGN(GC_PAGE_SZ / p->osize, 8));
gcval_t *beg = (gcval_t*)(pg->data + GC_PAGE_OFFSET);
gcval_t *end = (gcval_t*)((char*)beg + (pg->nfree - 1)*p->osize);
end->next = fl;
pg->allocd = 0;
pg->fl_begin_offset = 0;
pg->fl_end_offset = (char*)end - (char*)beg;
pg->fl_begin_offset = GC_PAGE_OFFSET;
pg->fl_end_offset = (char*)end - (char*)beg + GC_PAGE_OFFSET;
return beg;
}

Expand All @@ -1002,10 +1003,10 @@ static NOINLINE void add_page(pool_t *p)
char *data = (char*)malloc_page();
if (data == NULL)
jl_throw(jl_memory_exception);
gcpage_t *pg = page_metadata(data);
gcpage_t *pg = page_metadata(data + GC_PAGE_OFFSET);
pg->data = data;
pg->osize = p->osize;
pg->ages = (uint8_t*)malloc((GC_PAGE_SZ/p->osize + 7)/8);
pg->ages = (uint8_t*)malloc(LLT_ALIGN(GC_PAGE_SZ / p->osize, 8));
gcval_t *fl = reset_page(p, pg, p->newpages);
p->newpages = fl;
}
Expand Down Expand Up @@ -1132,7 +1133,7 @@ static void sweep_pool_region(int region_i, int sweep_mask)
last = p->newpages;
if (last) {
gcpage_t* pg = page_metadata(last);
pg->nfree = (GC_PAGE_SZ - ((char*)last - GC_PAGE_DATA(last)))/p->osize;
pg->nfree = (GC_PAGE_SZ - ((char*)last - GC_PAGE_DATA(last))) / p->osize;
pg->allocd = 1;
}
p->newpages = NULL;
Expand Down Expand Up @@ -1187,11 +1188,11 @@ static gcval_t** sweep_page(pool_t* p, gcpage_t* pg, gcval_t **pfl, int sweep_ma
gcval_t *v;
size_t old_nfree = 0, nfree = 0;
int pg_freedall = 0, pg_total = 0, pg_skpd = 0;
int obj_per_page = GC_PAGE_SZ/osize;
int obj_per_page = (GC_PAGE_SZ - GC_PAGE_OFFSET)/osize;
char *data = pg->data;
uint8_t *ages = page_age(pg);
v = (gcval_t*)data;
char *lim = (char*)v + GC_PAGE_SZ - osize;
v = (gcval_t*)(data + GC_PAGE_OFFSET);
char *lim = (char*)v + GC_PAGE_SZ - GC_PAGE_OFFSET - osize;
freedall = 1;
old_nfree += pg->nfree;

Expand Down Expand Up @@ -1909,10 +1910,10 @@ static void clear_mark(int bits)
if (!!~line) {
for (int j = 0; j < 32; j++) {
if (!((line >> j) & 1)) {
gcpage_t *pg = page_metadata(region->pages[pg_i*32 + j]);
gcpage_t *pg = page_metadata(&region->pages[pg_i*32 + j][0] + GC_PAGE_OFFSET);
pool_t *pool = &norm_pools[pg->pool_n];
pv = (gcval_t*)pg->data;
char *lim = (char*)pv + GC_PAGE_SZ - pool->osize;
pv = (gcval_t*)(pg->data + GC_PAGE_OFFSET);
char *lim = (char*)pv + GC_PAGE_SZ - GC_PAGE_OFFSET - pool->osize;
while ((char*)pv <= lim) {
if (!verifying) arraylist_push(&bits_save[gc_bits(pv)], pv);
gc_bits(pv) = bits;
Expand Down Expand Up @@ -2439,7 +2440,7 @@ static void jl_mk_thread_heap(void) {
p[i].osize = szc[i];
p[i].freelist = NULL;
p[i].newpages = NULL;
p[i].end_offset = ((GC_PAGE_SZ/szc[i]) - 1)*szc[i];
p[i].end_offset = GC_POOL_END_OFS(szc[i]);
}
arraylist_new(&preserved_values, 0);
arraylist_new(&weak_refs, 0);
Expand Down Expand Up @@ -2504,8 +2505,8 @@ static size_t pool_stats(pool_t *p, size_t *pwaste, size_t *np, size_t *pnold)

while (pg != NULL) {
npgs++;
v = (gcval_t*)pg->data;
char *lim = (char*)v + GC_PAGE_SZ - osize;
v = (gcval_t*)(pg->data + GC_PAGE_OFFSET);
char *lim = (char*)v + GC_PAGE_SZ - GC_PAGE_OFFSET - osize;
int i = 0;
while ((char*)v <= lim) {
if (!gc_marked(v)) {
Expand All @@ -2523,7 +2524,7 @@ static size_t pool_stats(pool_t *p, size_t *pwaste, size_t *np, size_t *pnold)
gcpage_t *nextpg = NULL;
pg = nextpg;
}
*pwaste = npgs*GC_PAGE_SZ - (nused*p->osize);
*pwaste = npgs * GC_PAGE_SZ - (nused * p->osize);
*np = npgs;
*pnold = nold;
if (npgs != 0) {
Expand Down
6 changes: 0 additions & 6 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ typedef struct {
#endif
};
};
#ifdef _P64
uintptr_t realign16;
#endif
jl_value_t value;
} jl_taggedvalue_t;

Expand All @@ -115,9 +112,6 @@ typedef struct {
static inline void jl_set_typeof(void *v, void *t)
{
jl_taggedvalue_t *tag = jl_astaggedvalue(v);
#ifdef _P64
tag->realign16 = 0xA1164A1164A11640ull;
#endif
tag->type = (jl_value_t*)t;
}
#define jl_typeis(v,t) (jl_typeof(v)==(jl_value_t*)(t))
Expand Down

1 comment on commit 8b8b261

@JeffBezanson
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎆

Please sign in to comment.