12
12
#define FREE_PAGES_EAGER
13
13
#include <stdlib.h>
14
14
#include <string.h>
15
+ #ifndef _MSC_VER
15
16
#include <strings.h>
17
+ #endif
16
18
#include <assert.h>
17
19
#include "julia.h"
18
20
#include "julia_internal.h"
@@ -41,7 +43,9 @@ typedef struct {
41
43
};
42
44
// Work around a bug affecting gcc up to (at least) version 4.4.7
43
45
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36839
46
+ #if !defined(_COMPILER_MICROSOFT_ )
44
47
int _dummy [0 ];
48
+ #endif
45
49
char data [];
46
50
} buff_t ;
47
51
@@ -80,7 +84,7 @@ typedef struct _gcpage_t {
80
84
81
85
// contiguous storage for up to REGION_PG_COUNT naturally aligned GC_PAGE_SZ blocks
82
86
// uses a very naive allocator (see malloc_page & free_page)
83
- #ifdef _P64
87
+ #if defined( _P64 ) && !defined( _COMPILER_MICROSOFT_ )
84
88
#define REGION_PG_COUNT 16*8*4096 // 8G because virtual memory is cheap
85
89
#else
86
90
#define REGION_PG_COUNT 8*4096 // 512M
@@ -302,9 +306,13 @@ static void add_lostval_parent(jl_value_t* parent)
302
306
} \
303
307
} while(0);
304
308
309
+ #define verify_parent1 (ty ,obj ,slot ,arg1 ) verify_parent(ty,obj,slot,arg1)
310
+ #define verify_parent2 (ty ,obj ,slot ,arg1 ,arg2 ) verify_parent(ty,obj,slot,arg1,arg2)
311
+
305
312
#else
306
313
#define verify_val (v )
307
- #define verify_parent (ty ,obj ,slot ,args ...)
314
+ #define verify_parent1 (ty ,obj ,slot ,arg1 )
315
+ #define verify_parent2 (ty ,obj ,slot ,arg1 ,arg2 )
308
316
#endif
309
317
310
318
#ifdef OBJPROFILE
@@ -461,7 +469,7 @@ static inline void *malloc_a16(size_t sz)
461
469
462
470
#endif
463
471
464
- static __attribute__(( noinline )) void * malloc_page (void )
472
+ static NOINLINE void * malloc_page (void )
465
473
{
466
474
void * ptr = (void * )0 ;
467
475
int i ;
@@ -471,7 +479,7 @@ static __attribute__((noinline)) void *malloc_page(void)
471
479
heap = heaps [heap_i ];
472
480
if (heap == NULL ) {
473
481
#ifdef _OS_WINDOWS_
474
- char * mem = VirtualAlloc (NULL , sizeof (region_t ) + GC_PAGE_SZ , MEM_RESERVE , PAGE_READWRITE );
482
+ char * mem = ( char * ) VirtualAlloc (NULL , sizeof (region_t ) + GC_PAGE_SZ , MEM_RESERVE , PAGE_READWRITE );
475
483
#else
476
484
char * mem = (char * )mmap (0 , sizeof (region_t ) + GC_PAGE_SZ , PROT_READ | PROT_WRITE , MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS , -1 , 0 );
477
485
mem = mem == MAP_FAILED ? NULL : mem ;
@@ -507,10 +515,10 @@ static __attribute__((noinline)) void *malloc_page(void)
507
515
if (heaps_ub [heap_i ] < i )
508
516
heaps_ub [heap_i ] = i ;
509
517
510
- #ifdef __MINGW32__
518
+ #if defined( _COMPILER_MINGW_ )
511
519
int j = __builtin_ffs (heap -> freemap [i ]) - 1 ;
512
- #elif _MSC_VER
513
- int j ;
520
+ #elif defined( _COMPILER_MICROSOFT_ )
521
+ unsigned long j ;
514
522
_BitScanForward (& j , heap -> freemap [i ]);
515
523
#else
516
524
int j = ffs (heap -> freemap [i ]) - 1 ;
@@ -780,7 +788,7 @@ void jl_finalize(jl_value_t *o)
780
788
781
789
// big value list
782
790
783
- static __attribute__(( noinline )) void * alloc_big (size_t sz )
791
+ static NOINLINE void * alloc_big (size_t sz )
784
792
{
785
793
maybe_collect ();
786
794
size_t offs = BVOFFS * sizeof (void * );
@@ -964,7 +972,7 @@ static inline gcval_t *reset_page(pool_t *p, gcpage_t *pg, gcval_t *fl)
964
972
return beg ;
965
973
}
966
974
967
- static __attribute__(( noinline )) void add_page (pool_t * p )
975
+ static NOINLINE void add_page (pool_t * p )
968
976
{
969
977
char * data = (char * )malloc_page ();
970
978
if (data == NULL )
@@ -1404,7 +1412,7 @@ static void gc_mark_stack(jl_value_t* ta, jl_gcframe_t *s, ptrint_t offset, int
1404
1412
else {
1405
1413
for (size_t i = 0 ; i < nr ; i ++ ) {
1406
1414
if (rts [i ] != NULL ) {
1407
- verify_parent ("task" , ta , & rts [i ], "stack(%d)" , i );
1415
+ verify_parent2 ("task" , ta , & rts [i ], "stack(%d)" , i );
1408
1416
gc_push_root (rts [i ], d );
1409
1417
}
1410
1418
}
@@ -1413,7 +1421,7 @@ static void gc_mark_stack(jl_value_t* ta, jl_gcframe_t *s, ptrint_t offset, int
1413
1421
}
1414
1422
}
1415
1423
1416
- __attribute__(( noinline )) static int gc_mark_module (jl_module_t * m , int d )
1424
+ NOINLINE static int gc_mark_module (jl_module_t * m , int d )
1417
1425
{
1418
1426
size_t i ;
1419
1427
int refyoung = 0 ;
@@ -1424,10 +1432,10 @@ __attribute__((noinline)) static int gc_mark_module(jl_module_t *m, int d)
1424
1432
gc_setmark_buf (b , gc_bits (m ));
1425
1433
#ifdef GC_VERIFY
1426
1434
void * vb = gc_val_buf (b );
1427
- verify_parent ("module" , m , & vb , "binding_buff" );
1435
+ verify_parent1 ("module" , m , & vb , "binding_buff" );
1428
1436
#endif
1429
1437
if (b -> value != NULL ) {
1430
- verify_parent ("module" , m , & b -> value , "binding(%s)" , b -> name -> name );
1438
+ verify_parent2 ("module" , m , & b -> value , "binding(%s)" , b -> name -> name );
1431
1439
refyoung |= gc_push_root (b -> value , d );
1432
1440
}
1433
1441
if (b -> type != (jl_value_t * )jl_any_type ) {
@@ -1443,7 +1451,7 @@ __attribute__((noinline)) static int gc_mark_module(jl_module_t *m, int d)
1443
1451
refyoung |= gc_push_root (m -> usings .items [i ], d );
1444
1452
}
1445
1453
if (m -> constant_table ) {
1446
- verify_parent ("module" , m , & m -> constant_table , "constant_table" );
1454
+ verify_parent1 ("module" , m , & m -> constant_table , "constant_table" );
1447
1455
refyoung |= gc_push_root (m -> constant_table , d );
1448
1456
}
1449
1457
return refyoung ;
@@ -1479,7 +1487,7 @@ static void mark_task_stacks(void) {
1479
1487
}
1480
1488
#endif
1481
1489
1482
- __attribute__(( noinline )) static void gc_mark_task (jl_task_t * ta , int d )
1490
+ NOINLINE static void gc_mark_task (jl_task_t * ta , int d )
1483
1491
{
1484
1492
if (ta -> parent ) gc_push_root (ta -> parent , d );
1485
1493
if (ta -> last ) gc_push_root (ta -> last , d );
@@ -1536,7 +1544,7 @@ static int push_root(jl_value_t *v, int d, int bits)
1536
1544
for (size_t i = 0 ; i < l ; i ++ ) {
1537
1545
jl_value_t * elt = data [i ];
1538
1546
if (elt != NULL ) {
1539
- verify_parent ("tuple" , v , & data [i ], "elem(%d)" , i );
1547
+ verify_parent2 ("tuple" , v , & data [i ], "elem(%d)" , i );
1540
1548
refyoung |= gc_push_root (elt , d );
1541
1549
}
1542
1550
}
@@ -1545,12 +1553,13 @@ static int push_root(jl_value_t *v, int d, int bits)
1545
1553
jl_array_t * a = (jl_array_t * )v ;
1546
1554
int todo = !(bits & GC_MARKED );
1547
1555
if (a -> pooled )
1548
- MARK (a ,
1549
1556
#ifdef MEMDEBUG
1550
- bits = gc_setmark_big ( a , GC_MARKED_NOESC );
1557
+ #define _gc_setmark_pool gc_setmark_big
1551
1558
#else
1552
- bits = gc_setmark_pool ( a , GC_MARKED_NOESC );
1559
+ #define _gc_setmark_pool gc_setmark_pool
1553
1560
#endif
1561
+ MARK (a ,
1562
+ bits = _gc_setmark_pool (a , GC_MARKED_NOESC );
1554
1563
if (a -> how == 2 && todo ) {
1555
1564
objprofile_count (MATY , gc_bits (a ) == GC_MARKED , array_nbytes (a ));
1556
1565
if (gc_bits (a ) == GC_MARKED )
@@ -1576,7 +1585,7 @@ static int push_root(jl_value_t *v, int d, int bits)
1576
1585
else if (a -> how == 1 ) {
1577
1586
#ifdef GC_VERIFY
1578
1587
void * val_buf = gc_val_buf ((char * )a -> data - a -> offset * a -> elsize );
1579
- verify_parent ("array" , v , & val_buf , "buffer ('loc' addr is meaningless)" );
1588
+ verify_parent1 ("array" , v , & val_buf , "buffer ('loc' addr is meaningless)" );
1580
1589
#endif
1581
1590
gc_setmark_buf ((char * )a -> data - a -> offset * a -> elsize , gc_bits (v ));
1582
1591
}
@@ -1592,7 +1601,7 @@ static int push_root(jl_value_t *v, int d, int bits)
1592
1601
for (size_t i = 0 ; i < l ; i ++ ) {
1593
1602
jl_value_t * elt = ((jl_value_t * * )data )[i ];
1594
1603
if (elt != NULL ) {
1595
- verify_parent ("array" , v , & ((jl_value_t * * )data )[i ], "elem(%d)" , i );
1604
+ verify_parent2 ("array" , v , & ((jl_value_t * * )data )[i ], "elem(%d)" , i );
1596
1605
refyoung |= gc_push_root (elt , d );
1597
1606
}
1598
1607
// try to split large array marking (incremental mark TODO)
@@ -1636,7 +1645,7 @@ static int push_root(jl_value_t *v, int d, int bits)
1636
1645
jl_value_t * * slot = (jl_value_t * * )((char * )v + fields [i ].offset + sizeof (void * ));
1637
1646
jl_value_t * fld = * slot ;
1638
1647
if (fld ) {
1639
- verify_parent ("object" , v , slot , "field(%d)" , i );
1648
+ verify_parent2 ("object" , v , slot , "field(%d)" , i );
1640
1649
//children[ci++] = fld;
1641
1650
refyoung |= gc_push_root (fld , d );
1642
1651
}
0 commit comments