Skip to content

Commit

Permalink
debug [av skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Jun 6, 2016
1 parent 93ac0ab commit b9a83ae
Show file tree
Hide file tree
Showing 3 changed files with 307 additions and 303 deletions.
38 changes: 20 additions & 18 deletions src/cgmemmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace {

static void print_to_tty(const char *fmt, ...)
{
char *env = getenv("JULIA_DEBUG_CGMEMMGR");
if (!env || !*env)
return;
va_list args;
va_start(args, fmt);
static int fd = -1;
Expand All @@ -62,17 +65,15 @@ static void *map_anon_page(size_t size)
#else
void *mem = mmap(nullptr, size, PROT_READ | PROT_WRITE,
MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (mem == MAP_FAILED)
print_to_tty("%s: %p, %lld\n", __func__, mem, (long long)size);
print_to_tty("%s: %p, %lld\n", __func__, mem, (long long)size);
assert(mem != MAP_FAILED);
#endif
// jl_safe_printf("%s: %p, %lld\n", __func__, mem, (long long)size);
return mem;
}

static void unmap_page(void *ptr, size_t size)
{
// jl_safe_printf("%s: %p, %lld\n", __func__, ptr, (long long)size);
print_to_tty("%s: %p, %lld\n", __func__, ptr, (long long)size);
#ifdef _OS_WINDOWS_
VirtualFree(ptr, size, MEM_DECOMMIT);
#else
Expand Down Expand Up @@ -105,13 +106,11 @@ static void protect_page(void *ptr, size_t size, Prot flags)
{
int ret = mprotect(ptr, size, (int)flags);
if (ret != 0) {
print_to_tty("%s: %p, %lld, %d, %d\n",
__func__, ptr, (long long)size, (int)flags, ret);
perror(__func__);
abort();
}
// jl_safe_printf("%s: %p, %lld, %d, %d\n",
// __func__, ptr, (long long)size, (int)flags, ret);
print_to_tty("%s: %p, %lld, %d, %d\n",
__func__, ptr, (long long)size, (int)flags, ret);
}
#endif

Expand Down Expand Up @@ -145,7 +144,7 @@ static intptr_t get_anon_hdl(void)
// file system.
# ifdef __NR_memfd_create
fd = syscall(__NR_memfd_create, "julia-codegen", MFD_CLOEXEC);
// jl_safe_print(f"%s: memfd %d\n", __func__, fd);
print_to_tty("%s: memfd %d\n", __func__, fd);
if (check_fd_or_close(fd))
return fd;
# endif
Expand All @@ -162,7 +161,7 @@ static intptr_t get_anon_hdl(void)
snprintf(shm_name, sizeof(shm_name),
"julia-codegen-%d-%d", (int)pid, rand());
fd = shm_open(shm_name, O_RDWR | O_CREAT | O_EXCL, S_IRWXU);
// jl_safe_printf("%s: shm %d\n", __func__, fd);
print_to_tty("%s: shm %d\n", __func__, fd);
if (check_fd_or_close(fd)) {
shm_unlink(shm_name);
return fd;
Expand All @@ -171,7 +170,7 @@ static intptr_t get_anon_hdl(void)
# endif
snprintf(shm_name, sizeof(shm_name), "julia-codegen-%d-XXXXXX", (int)pid);
fd = mkstemp(shm_name);
// jl_safe_printf("%s: mkstemp %d\n", __func__, fd);
print_to_tty("%s: mkstemp %d\n", __func__, fd);
if (check_fd_or_close(fd)) {
unlink(shm_name);
return fd;
Expand Down Expand Up @@ -277,9 +276,7 @@ static void *create_shared_map(size_t size, size_t offset)
{
void *addr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED,
anon_hdl, offset);
if (addr == MAP_FAILED)
print_to_tty("%s: %p, %lld\n", __func__, addr, (long long)size);
// jl_safe_printf("%s: %p, %lld\n", __func__, addr, (long long)size);
print_to_tty("%s: %p, %lld\n", __func__, addr, (long long)size);
assert(addr != MAP_FAILED);
return addr;
}
Expand All @@ -292,12 +289,11 @@ static intptr_t init_shared_map()
map_offset = 0;
map_size = 512 * 1024 * 1024;
int ret = ftruncate(anon_hdl, map_size);
print_to_tty("%s: %d, %lld\n", __func__, ret, (long long)map_size);
if (ret != 0) {
print_to_tty("%s: %d, %lld\n", __func__, ret, (long long)map_size);
perror(__func__);
abort();
}
// jl_safe_printf("%s: %d, %lld\n", __func__, ret, (long long)map_size);
return anon_hdl;
}

Expand All @@ -313,12 +309,11 @@ static void *alloc_shared_page(size_t size, size_t *offset, bool exec)
map_size += 512 * 1024 * 1024;
if (old_size != map_size) {
int ret = ftruncate(anon_hdl, map_size);
print_to_tty("%s: %d, %lld\n", __func__, ret, (long long)map_size);
if (ret != 0) {
print_to_tty("%s: %d, %lld\n", __func__, ret, (long long)map_size);
perror(__func__);
abort();
}
// jl_safe_printf("%s: %d, %lld\n", __func__, ret, (long long)map_size);
}
JL_UNLOCK_NOGC(&shared_map_lock);
}
Expand Down Expand Up @@ -544,6 +539,8 @@ class ROAllocator {
wr_ptr = get_wr_ptr(block, ptr, size, align);
}
block.state |= ROBlock::Alloc;
print_to_tty("%s: %p, %p, %lld\n",
__func__, wr_ptr, ptr, (long long)size);
allocations.push_back(Allocation{wr_ptr, ptr, size, false});
return wr_ptr;
}
Expand All @@ -570,6 +567,8 @@ class ROAllocator {
ptr = wr_ptr;
#else
block.state = ROBlock::Alloc | ROBlock::InitAlloc;
print_to_tty("%s: %p, %p, %lld\n",
__func__, ptr, ptr, (long long)size);
allocations.push_back(Allocation{ptr, ptr, size, false});
#endif
return ptr;
Expand Down Expand Up @@ -631,6 +630,7 @@ class DualMapAllocator : public ROAllocator<exec> {
public:
DualMapAllocator()
{
print_to_tty("%s, %d\n", __func__, anon_hdl);
assert(anon_hdl != -1);
}
void finalize() override
Expand Down Expand Up @@ -789,6 +789,8 @@ class RTDyldMemoryManagerJL : public SectionMemoryManager {
template <typename DL>
void mapAddresses(DL &Dyld)
{
if (!ro_alloc)
return;
mapAddresses(Dyld, ro_alloc);
mapAddresses(Dyld, exe_alloc);
}
Expand Down
36 changes: 18 additions & 18 deletions test/choosetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ Upon return, `tests` is a vector of fully-expanded test names, and
""" ->
function choosetests(choices = [])
testnames = [
"linalg", "subarray", "core", "inference", "keywordargs", "numbers",
"printf", "char", "string", "triplequote", "unicode",
"dates", "dict", "hashing", "iobuffer", "staged",
"arrayops", "tuple", "reduce", "reducedim", "random", "abstractarray",
"intfuncs", "simdloop", "vecelement", "blas", "sparse",
"bitarray", "copy", "math", "fastmath", "functional",
"operators", "path", "ccall", "parse", "loading", "bigint",
"bigfloat", "sorting", "statistics", "spawn", "backtrace",
"priorityqueue", "file", "read", "mmap", "version", "resolve",
"pollfd", "mpfr", "broadcast", "complex", "socket",
"floatapprox", "datafmt", "reflection", "regex", "float16",
"combinatorics", "sysinfo", "rounding", "ranges", "mod2pi",
"euler", "show", "lineedit", "replcompletions", "repl",
"replutil", "sets", "test", "goto", "llvmcall", "grisu",
"nullable", "meta", "stacktraces", "profile", "libgit2", "docs",
"markdown", "base64", "serialize", "misc", "threads",
# "linalg", "subarray", "core", "inference", "keywordargs", "numbers",
# "printf", "char", "string", "triplequote", "unicode",
# "dates", "dict", "hashing", "iobuffer", "staged",
# "arrayops", "tuple", "reduce", "reducedim", "random", "abstractarray",
# "intfuncs", "simdloop", "vecelement", "blas", "sparse",
# "bitarray", "copy", "math", "fastmath", "functional",
# "operators", "path", "ccall", "parse", "loading", "bigint",
# "bigfloat", "sorting", "statistics", "spawn", "backtrace",
# "priorityqueue", "file", "read", "mmap", "version", "resolve",
# "pollfd", "mpfr", "broadcast", "complex", "socket",
# "floatapprox", "datafmt", "reflection", "regex", "float16",
# "combinatorics", "sysinfo", "rounding", "ranges", "mod2pi",
# "euler", "show", "lineedit", "replcompletions", "repl",
# "replutil", "sets", "test", "goto", "llvmcall", "grisu",
# "nullable", "meta", "stacktraces", "profile", "libgit2", "docs",
# "markdown", "base64", "serialize", "misc", "threads",
"enums", "cmdlineargs", "i18n", "workspace", "libdl", "int",
"checked", "intset", "floatfuncs", "compile", "parallel", "inline",
"boundscheck", "error", "ambiguous"
# "checked", "intset", "floatfuncs", "compile", "parallel", "inline",
# "boundscheck", "error", "ambiguous"
]

if Base.USE_GPL_LIBS
Expand Down
Loading

0 comments on commit b9a83ae

Please sign in to comment.