Skip to content

Commit

Permalink
making new GC the default
Browse files Browse the repository at this point in the history
fixing making symbols from non-0-terminated strings
changing IntSet to use a proper array
  • Loading branch information
JeffBezanson committed Oct 28, 2010
1 parent 0f32595 commit 89ec3f0
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 59 deletions.
4 changes: 2 additions & 2 deletions Make.inc.Linux
@@ -1,14 +1,14 @@
CC = gcc
CXX = g++
CFLAGS =
CFLAGS = -std=gnu99

PFX = /usr/local
#PFX = /afs/csail.mit.edu/u/b/bezanson
HFILEDIRS = $(PFX)/include
LIBDIRS = $(PFX)/lib

# BOEHM or MARKSWEEP
JULIAGC = BOEHM
JULIAGC = MARKSWEEP

ifeq ($(JULIAGC),BOEHM)
GCLIBS = -l:libgc.a
Expand Down
10 changes: 9 additions & 1 deletion alloc.c
Expand Up @@ -262,7 +262,7 @@ static jl_sym_t **symtab_lookup(jl_sym_t **ptree, const char *str)
return ptree;
}

DLLEXPORT jl_sym_t *jl_symbol(const char *str)
jl_sym_t *jl_symbol(const char *str)
{
jl_sym_t **pnode;

Expand All @@ -272,6 +272,14 @@ DLLEXPORT jl_sym_t *jl_symbol(const char *str)
return *pnode;
}

DLLEXPORT jl_sym_t *jl_symbol_n(const char *str, int32_t len)
{
char name[len+1];
memcpy(name, str, len);
name[len] = '\0';
return jl_symbol(name);
}

DLLEXPORT jl_sym_t *jl_gensym()
{
static uint32_t gs_ctr = 0; // TODO: per-thread
Expand Down
6 changes: 5 additions & 1 deletion doc/todo
Expand Up @@ -556,6 +556,10 @@ promote_type: promote_type(Type{T},Type{T}) first
ref: ref(Array{Any,1},Int32) before ref(Array{T,1},Int32)

convert files for new GC:
*alloc.c codegen.cpp *gf.c *intrinsics.cpp
*alloc.c *codegen.cpp *gf.c *intrinsics.cpp
*ast.c *init.c *io.c *task.c
*builtins.c *interpreter.c *jltypes.c *repl.c

startup time, mem0, mem after tests.j, exe size:
marksweep: 7.8s, 58356 43m, 69792 55m, 8285616
boehm: 7.8s, 50236 35m, 78320 63m, 8376416
3 changes: 2 additions & 1 deletion expr.j
Expand Up @@ -3,7 +3,8 @@
symbol(s::Latin1String) = symbol(s.data)
symbol(s::UTF8String) = symbol(s.data)
symbol(a::Array{Uint8,1}) =
ccall(dlsym(JuliaDLHandle,"jl_symbol"), Any, (Ptr{Uint8},), a)::Symbol
ccall(dlsym(JuliaDLHandle,"jl_symbol_n"), Any,
(Ptr{Uint8}, Int32), a, int32(length(a)))::Symbol
gensym() = ccall(dlsym(JuliaDLHandle,"jl_gensym"), Any, ())::Symbol

(==)(x::Symbol, y::Symbol) = is(x, y)
Expand Down
44 changes: 20 additions & 24 deletions gc.c
Expand Up @@ -21,11 +21,11 @@
/*
integration steps:
* convert idtable to use an Array
- give GC access to relevant C local variables
* give GC access to relevant C local variables
- allocate ios objects with malloc, use finalizer
*/

#define GC_PAGE_SZ 16384//bytes
#define GC_PAGE_SZ (4096*sizeof(void*))//bytes

typedef struct _gcpage_t {
struct _gcpage_t *next;
Expand Down Expand Up @@ -83,46 +83,42 @@ typedef struct _bigval_t {

static bigval_t *big_objects = NULL;

#define N_POOLS 16
#define N_POOLS 19
static pool_t pools[N_POOLS];

static size_t allocd_bytes = 0;
static size_t collect_interval = 8192*1024;

// size classes:
// <=8, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// <=8, 12, 16, 20, 24, 28, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15, 16, 17, 18

static int szclass(size_t sz)
{
if (sz <= 8) return 0;
if (sz <= 32) return ((sz+3)>>2) - 2;
if (sz <= 128) {
if (sz <= 16) return 1;
if (sz <= 32) {
if (sz <= 24) return 2;
return 3;
}
if (sz <= 64) {
if (sz <= 48) return 4;
return 5;
if (sz <= 48) return 7;
return 8;
}
if (sz <= 96) return 6;
return 7;
if (sz <= 96) return 9;
return 10;
}
if (sz <= 512) {
if (sz <= 256) {
if (sz <= 192) return 8;
return 9;
if (sz <= 192) return 11;
return 12;
}
if (sz <= 384) return 10;
return 11;
if (sz <= 384) return 13;
return 14;
}
if (sz <= 1024) {
if (sz <= 768) return 12;
return 13;
if (sz <= 768) return 15;
return 16;
}
if (sz <= 1536) return 14;
return 15;
if (sz <= 1536) return 17;
return 18;
}

static void *alloc_big(size_t sz)
Expand Down Expand Up @@ -489,8 +485,8 @@ void *alloc_permanent(size_t sz)

void jl_gc_init()
{
int szc[N_POOLS] = { 8, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512,
768, 1024, 1536, 2048 };
int szc[N_POOLS] = { 8, 12, 16, 20, 24, 28, 32, 48, 64, 96, 128, 192, 256,
384, 512, 768, 1024, 1536, 2048 };
int i;
for(i=0; i < N_POOLS; i++) {
pools[i].osize = szc[i]+sizeof(void*);
Expand Down
4 changes: 2 additions & 2 deletions inference.j
Expand Up @@ -642,8 +642,8 @@ function typeinf(linfo::LambdaStaticData, atypes::Tuple, sparams::Tuple, cop)

n = length(body)
s = { idtable() | i=1:n }
recpts = intset(n+1) # statements that depend recursively on our value
W = intset(n+1)
recpts = IntSet(n+1) # statements that depend recursively on our value
W = IntSet(n+1)
# initial set of pc
adjoin(W,1)
# initial types
Expand Down
34 changes: 13 additions & 21 deletions intset.j
@@ -1,35 +1,29 @@
struct IntSet
bits::Ptr{Uint32}
bits::Array{Uint32,1}
limit::Int32 # todo: should be Int64

IntSet() = IntSet(1024)
IntSet(max::Int32) = (lim = (max+31) & -32;
new(zeros(Uint32,lim>>5), lim))
end

intset(max::Int32) =
IntSet(ccall(dlsym(JuliaDLHandle,"bitvector_new"), Ptr{Uint32},
(Uint64, Int32),
uint64(max), 1),
max)

intset() = intset(1024)

function adjoin(s::IntSet, n::Int)
if n >= s.limit
lim = int32(n + div(n,2))
s.bits = ccall(dlsym(JuliaDLHandle,"bitvector_resize"), Ptr{Uint32},
(Ptr{Uint32}, Uint64, Uint64, Int32),
s.bits, uint64(s.limit), uint64(lim), 1)
olsz = length(s.bits)
newbits = Array(Uint32,(lim+31)>>5)
newbits[1:olsz] = s.bits
for i=(olsz+1):length(newbits); newbits[i] = 0; end
s.bits = newbits
s.limit = lim
end
ccall(dlsym(JuliaDLHandle,"bitvector_set"), Void,
(Ptr{Uint32}, Uint64, Int32),
s.bits, uint64(n), 1)
s.bits[n>>5 + 1] |= (1<<(n&31))
s
end

function remove(s::IntSet, n::Int)
if n < s.limit
ccall(dlsym(JuliaDLHandle,"bitvector_set"), Void,
(Ptr{Uint32}, Uint64, Int32),
s.bits, uint64(n), 0)
s.bits[n>>5 + 1] &= ~(1<<(n&31))
end
s
end
Expand All @@ -40,9 +34,7 @@ function contains(s::IntSet, n::Int)
if n >= s.limit
false
else
(ccall(dlsym(JuliaDLHandle,"bitvector_get"), Int32,
(Ptr{Uint32}, Uint64),
s.bits, uint64(n)) != 0)
(s.bits[n>>5 + 1] & (1<<(n&31))) != 0
end
end

Expand Down
3 changes: 2 additions & 1 deletion io.j
Expand Up @@ -213,8 +213,9 @@ function serialize(s, x)
for n = t.names
serialize(s, getfield(x, n))
end
else
error("not serializable")
end
error("not serializable")
end

## deserializing values ##
Expand Down
2 changes: 1 addition & 1 deletion julia.expmap
Expand Up @@ -22,7 +22,7 @@
jl_new_structt;
jl_word_size;
jl_enable_inference;
jl_symbol;
jl_symbol_n;
jl_matching_methods;
jl_is_builtin;
jl_is_genericfunc;
Expand Down
3 changes: 2 additions & 1 deletion julia.h
Expand Up @@ -451,7 +451,8 @@ jl_tuple_t *jl_alloc_tuple_uninit(size_t n);
jl_tuple_t *jl_tuple_append(jl_tuple_t *a, jl_tuple_t *b);
jl_tuple_t *jl_flatten_pairs(jl_tuple_t *t);
jl_tuple_t *jl_pair(jl_value_t *a, jl_value_t *b);
DLLEXPORT jl_sym_t *jl_symbol(const char *str);
jl_sym_t *jl_symbol(const char *str);
DLLEXPORT jl_sym_t *jl_symbol_n(const char *str, int32_t len);
DLLEXPORT jl_sym_t *jl_gensym();
jl_array_t *jl_alloc_array_1d(jl_type_t *atype, size_t nr);
DLLEXPORT jl_array_t *jl_cstr_to_array(char *str);
Expand Down
2 changes: 1 addition & 1 deletion lib/bitvector.c
Expand Up @@ -102,7 +102,7 @@ uint32_t bitvector_next(uint32_t *b, uint64_t n0, uint64_t n)
uint32_t nw = (n+31)>>5;
uint32_t w;

if (i < nw-1)
if (i < nw-1 || (n&31)==0)
w = b[i]>>nb;
else
w = (b[i]&lomask(n&31))>>nb;
Expand Down
5 changes: 3 additions & 2 deletions multi.j
Expand Up @@ -248,9 +248,10 @@ function pmap_s(wpool, fname, lst)
fut
end

# fv(a)=eig(a)[2][2]
# A=randn(800,800);A=A*A';
# wp=WorkPool(3)
# pmap_d(wp, `eig, {A,A,A})
# pmap_d(wp, `fv, {A,A,A})
# p={Worker(),Worker()}
# pmap_s(p,`eig,{A,A})
# pmap_s(p,`fv,{A,A})
2 changes: 1 addition & 1 deletion task.c
@@ -1,6 +1,6 @@
/*
task.c
lightweight processes (or asymmetric coroutines)
lightweight processes (symmetric coroutines)
*/
#include <stdlib.h>
#include <stdio.h>
Expand Down

0 comments on commit 89ec3f0

Please sign in to comment.