Skip to content

Commit

Permalink
code formatting cleanup and added tests for Sys.dl functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Mar 15, 2015
1 parent 8cb0c50 commit 6f63659
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function show(io::IO, x::ANY)
else
nb = t.size
print(io, "0x")
p = pointer_from_objref(x) + sizeof(Ptr{Void})
p = data_pointer_from_objref(x)
for i=nb-1:-1:0
print(io, hex(unsafe_load(convert(Ptr{UInt8}, p+i)), 2))
end
Expand Down
21 changes: 9 additions & 12 deletions base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function cpu_info()
cpus[i] = CPUinfo(unsafe_load(UVcpus[1],i))
end
ccall(:uv_free_cpu_info, Void, (Ptr{UV_cpu_info_t}, Int32), UVcpus[1], count[1])
cpus
return cpus
end

function uptime()
Expand Down Expand Up @@ -165,16 +165,13 @@ const shlib_ext = dlext
end

# This callback function called by dl_iterate_phdr() on Linux
function dl_phdr_info_callback( di_ptr::Ptr{dl_phdr_info}, size::Csize_t, dynamic_libraries_ptr::Ptr{Array{AbstractString,1}} )
di = unsafe_load(di_ptr)

function dl_phdr_info_callback(di::dl_phdr_info, size::Csize_t, dynamic_libraries::Array{AbstractString,1})
# Skip over objects without a path (as they represent this own object)
name = bytestring(di.name)
if !isempty(name)
dynamic_libraries = unsafe_pointer_to_objref( dynamic_libraries_ptr )
push!(dynamic_libraries, name )
push!(dynamic_libraries, name)
end
convert(Cint, 0)::Cint
return convert(Cint, 0)::Cint
end
end #@linux_only

Expand All @@ -183,8 +180,8 @@ function dllist()

@linux_only begin
const callback = cfunction(dl_phdr_info_callback, Cint,
(Ptr{dl_phdr_info}, Csize_t, Ptr{Array{AbstractString,1}} ))
ccall(:dl_iterate_phdr, Cint, (Ptr{Void}, Ptr{Void}), callback, pointer_from_objref(dynamic_libraries))
(Ref{dl_phdr_info}, Csize_t, Ref{Array{AbstractString,1}} ))
ccall(:dl_iterate_phdr, Cint, (Ptr{Void}, Any), callback, dynamic_libraries)

This comment has been minimized.

Copy link
@vtjnash

vtjnash Mar 15, 2015

Author Member

oops, i forgot Any isn't valid here until after I merge #2818. either that needs to be merged or the following patch needs to be applied:

diff --git a/base/sysinfo.jl b/base/sysinfo.jl
index d5991df..ca27006 100644
--- a/base/sysinfo.jl
+++ b/base/sysinfo.jl
@@ -181,7 +181,7 @@ function dllist()
     @linux_only begin
         const callback = cfunction(dl_phdr_info_callback, Cint,
                                    (Ref{dl_phdr_info}, Csize_t, Ref{Array{AbstractString,1}} ))
-        ccall(:dl_iterate_phdr, Cint, (Ptr{Void}, Any), callback, dynamic_libraries)
+        ccall(:dl_iterate_phdr, Cint, (Ptr{Void}, Ref{Array{AbstractString,1}}), callback, dynamic_libraries)
     end

     @osx_only begin
end

@osx_only begin
Expand All @@ -201,7 +198,7 @@ function dllist()
ccall(:jl_dllist, Cint, (Any,), dynamic_libraries)
end

dynamic_libraries
return dynamic_libraries
end

function dlpath( handle::Ptr{Void} )
Expand All @@ -211,7 +208,7 @@ function dlpath( handle::Ptr{Void} )
return s
end

function dlpath{T<:Union(AbstractString, Symbol)}(libname::T)
function dlpath(libname::Union(AbstractString,Symbol))
handle = dlopen(libname)
path = dlpath(handle)
dlclose(handle)
Expand All @@ -222,7 +219,7 @@ function get_process_title()
buf = zeros(Uint8, 512)
err = ccall(:uv_get_process_title, Cint, (Ptr{Uint8}, Cint), buf, 512)
uv_error("get_process_title", err)
bytestring(pointer(buf))
return bytestring(pointer(buf))
end
function set_process_title(title::AbstractString)
err = ccall(:uv_set_process_title, Cint, (Ptr{UInt8},), bytestring(title))
Expand Down
36 changes: 17 additions & 19 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ void jl_(void *jl_value);
extern "C" {
#endif

#pragma pack(push, 1)

typedef struct {
union {
uintptr_t header;
Expand Down Expand Up @@ -153,8 +151,6 @@ typedef struct _bigval_t {
#define BVOFFS (offsetof(bigval_t, _data)/sizeof(void*))
#define bigval_header(data) ((bigval_t*)((char*)(data) - BVOFFS*sizeof(void*)))

#pragma pack(pop)

// GC knobs and self-measurement variables
static int64_t last_gc_total_bytes = 0;

Expand All @@ -170,7 +166,7 @@ static size_t collect_interval;
static int64_t allocd_bytes;

#define N_POOLS 42
static __attribute__((aligned (64))) pool_t norm_pools[N_POOLS];
static pool_t norm_pools[N_POOLS];
#define pools norm_pools

static bigval_t *big_objects = NULL;
Expand Down Expand Up @@ -337,11 +333,12 @@ static inline void objprofile_count(void* ty, int old, int sz)
#endif
}

static inline void gc_setmark_other(void *o, int mark_mode)
{
_gc_setmark(o, mark_mode);
verify_val(o);
}
//static inline void gc_setmark_other(jl_value_t *v, int mark_mode) // unused function
//{
// jl_typetag_t *o = jl_typetagof(v);
// _gc_setmark(o, mark_mode);
// verify_val(o);
//}

#define inc_sat(v,s) v = (v) >= s ? s : (v)+1

Expand Down Expand Up @@ -747,8 +744,7 @@ static void run_finalizers(void)
while (to_finalize.len > 0) {
f = arraylist_pop(&to_finalize);
o = arraylist_pop(&to_finalize);
int ok = 1;run_finalizer((jl_value_t*)o, (jl_value_t*)f);
assert(ok); (void)ok;
run_finalizer((jl_value_t*)o, (jl_value_t*)f);
}
JL_GC_POP();
}
Expand Down Expand Up @@ -968,7 +964,7 @@ static inline gcval_t *reset_page(pool_t *p, gcpage_t *pg, gcval_t *fl)
return beg;
}

static __attribute__((noinline)) void add_page(pool_t *p)
static __attribute__((noinline)) void add_page(pool_t *p)
{
char *data = (char*)malloc_page();
if (data == NULL)
Expand All @@ -981,7 +977,7 @@ static __attribute__((noinline)) void add_page(pool_t *p)
p->newpages = fl;
}

static inline void *__pool_alloc(pool_t* p, int osize, int end_offset)
static inline void *__pool_alloc(pool_t* p, int osize, int end_offset)
{
gcval_t *v, *end;
if (__unlikely((allocd_bytes += osize) >= 0)) {
Expand All @@ -1000,6 +996,7 @@ static inline void *__pool_alloc(pool_t* p, int osize, int end_offset)
// we only update pg's fields when the freelist changes page
// since pg's metadata is likely not in cache
gcpage_t* pg = page_metadata(v);
assert(pg->osize == p->osize);
pg->nfree = 0;
pg->allocd = 1;
if (next)
Expand All @@ -1019,6 +1016,7 @@ static inline void *__pool_alloc(pool_t* p, int osize, int end_offset)
} else {
// like in the freelist case, only update the page metadata when it is full
gcpage_t* pg = page_metadata(v);
assert(pg->osize == p->osize);
pg->nfree = 0;
pg->allocd = 1;
p->newpages = v->next;
Expand Down Expand Up @@ -1259,7 +1257,7 @@ static gcval_t** sweep_page(pool_t* p, gcpage_t* pg, gcval_t **pfl, int sweep_ma
return pfl;
}

extern void jl_unmark_symbols(void);
//extern void jl_unmark_symbols(void);

static void gc_sweep_once(int sweep_mask)
{
Expand All @@ -1281,8 +1279,8 @@ static void gc_sweep_once(int sweep_mask)
jl_printf(JL_STDOUT, "GC sweep big %.2f (freed %d/%d with %d rst)\n", (clock_now() - t0)*1000, big_freed, big_total, big_reset);
t0 = clock_now();
#endif
if (sweep_mask == GC_MARKED)
jl_unmark_symbols();
//if (sweep_mask == GC_MARKED)
// jl_unmark_symbols();
#ifdef GC_TIME
jl_printf(JL_STDOUT, "GC sweep symbols %.2f\n", (clock_now() - t0)*1000);
#endif
Expand Down Expand Up @@ -1340,7 +1338,7 @@ int max_msp = 0;

static arraylist_t tasks;
static arraylist_t rem_bindings;
static arraylist_t _remset[2];
static arraylist_t _remset[2]; // contains jl_value_t*
static arraylist_t *remset = &_remset[0];
static arraylist_t *last_remset = &_remset[1];
void reset_remset(void)
Expand Down Expand Up @@ -1615,7 +1613,7 @@ static int push_root(jl_value_t *v, int d, int bits)
refyoung = GC_MARKED_NOESC;
}
else if(vt == (jl_value_t*)jl_symbol_type) {
gc_setmark_other(v, GC_MARKED); // symbols have their own allocator
//gc_setmark_other(v, GC_MARKED); // symbols have their own allocator and are never freed
}
else if(
#ifdef GC_VERIFY
Expand Down
11 changes: 11 additions & 0 deletions test/backtrace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,14 @@ for l in bt
end

@test have_backtrace

# these could fail on an embedded installation
# but for now, we don't handle that case
dlls = Sys.dllist()
@test !isempty(dlls)
@test length(dlls) > 3 # at a bare minimum, probably have some version of libstdc, libgcc, libjulia, ...
@test Base.samefile(Sys.dlpath(dlls[1]), dlls[1])
@test Base.samefile(Sys.dlpath(dlls[end]), dlls[end])
@test length(filter(dlls) do dl
return ismatch(Regex("^libjulia(?:.*)\.$(Sys.dlext)(?:\..+)?\$"), basename(dl))
end) == 1 # look for something libjulia-like (but only one)
1 change: 1 addition & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2247,4 +2247,5 @@ let x,y,f
y = f() # invoke llvm constant folding
@test Int(0x468ace) === Int(y)
@test x !== y
@test string(y) == "Int24(0x468ace)"
end

0 comments on commit 6f63659

Please sign in to comment.