added mmap/munmap check to configure.ac
This commit is contained in:
@ -93,6 +93,12 @@
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the `mmap' function. */
|
||||
#undef HAVE_MMAP
|
||||
|
||||
/* Define to 1 if you have the `munmap' function. */
|
||||
#undef HAVE_MUNMAP
|
||||
|
||||
/* Define to 1 if you have the `nanosleep' function. */
|
||||
#undef HAVE_NANOSLEEP
|
||||
|
||||
@ -156,6 +162,9 @@
|
||||
/* Define to 1 if you have the `swapcontext' function. */
|
||||
#undef HAVE_SWAPCONTEXT
|
||||
|
||||
/* Define to 1 if you have the <sys/mman.h> header file. */
|
||||
#undef HAVE_SYS_MMAN_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
|
16
lib/hcl.c
16
lib/hcl.c
@ -128,13 +128,6 @@ int hcl_init (hcl_t* hcl, hcl_mmgr_t* mmgr, hcl_oow_t heapsz, const hcl_vmprim_t
|
||||
hcl->log.ptr = (hcl_ooch_t*)hcl_allocmem(hcl, (hcl->log.capa + 1) * HCL_SIZEOF(*hcl->log.ptr));
|
||||
if (!hcl->log.ptr) goto oops;
|
||||
|
||||
/*hcl->permheap = hcl_makeheap (hcl, what is the best size???);
|
||||
if (!hcl->curheap) goto oops; */
|
||||
hcl->curheap = hcl_makeheap(hcl, heapsz);
|
||||
if (!hcl->curheap) goto oops;
|
||||
hcl->newheap = hcl_makeheap(hcl, heapsz);
|
||||
if (!hcl->newheap) goto oops;
|
||||
|
||||
if (hcl_rbt_init(&hcl->modtab, hcl, HCL_SIZEOF(hcl_ooch_t), 1) <= -1) goto oops;
|
||||
modtab_inited = 1;
|
||||
hcl_rbt_setstyle(&hcl->modtab, hcl_getrbtstyle(HCL_RBT_STYLE_INLINE_COPIERS));
|
||||
@ -149,13 +142,20 @@ int hcl_init (hcl_t* hcl, hcl_mmgr_t* mmgr, hcl_oow_t heapsz, const hcl_vmprim_t
|
||||
hcl->proc_map_free_first = -1;
|
||||
hcl->proc_map_free_last = -1;
|
||||
|
||||
/*hcl->permheap = hcl_makeheap (hcl, what is the best size???);
|
||||
if (!hcl->curheap) goto oops; */
|
||||
hcl->curheap = hcl_makeheap(hcl, heapsz);
|
||||
if (!hcl->curheap) goto oops;
|
||||
hcl->newheap = hcl_makeheap(hcl, heapsz);
|
||||
if (!hcl->newheap) goto oops;
|
||||
|
||||
return 0;
|
||||
|
||||
oops:
|
||||
if (modtab_inited) hcl_rbt_fini (&hcl->modtab);
|
||||
if (hcl->newheap) hcl_killheap (hcl, hcl->newheap);
|
||||
if (hcl->curheap) hcl_killheap (hcl, hcl->curheap);
|
||||
if (hcl->permheap) hcl_killheap (hcl, hcl->permheap);
|
||||
if (modtab_inited) hcl_rbt_fini (&hcl->modtab);
|
||||
if (hcl->log.ptr) hcl_freemem (hcl, hcl->log.ptr);
|
||||
hcl->log.capa = 0;
|
||||
return -1;
|
||||
|
48
lib/main.c
48
lib/main.c
@ -83,12 +83,15 @@
|
||||
# if defined(HAVE_SIGNAL_H)
|
||||
# include <signal.h>
|
||||
# endif
|
||||
# if defined(HAVE_SYS_MMAN_H)
|
||||
# include <sys/mman.h>
|
||||
# endif
|
||||
|
||||
# include <errno.h>
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
|
||||
# include <sys/mman.h>
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(HCL_DEFAULT_PFMODPREFIX)
|
||||
@ -447,47 +450,62 @@ static hcl_ooi_t print_handler (hcl_t* hcl, hcl_iocmd_t cmd, void* arg)
|
||||
|
||||
static void* alloc_heap (hcl_t* hcl, hcl_oow_t size)
|
||||
{
|
||||
/* It's called when HCL creates a GC heap.
|
||||
#if defined(HAVE_MMAP) && defined(HAVE_MUNMAP)
|
||||
/* It's called via hcl_makeheap() when HCL creates a GC heap.
|
||||
* The heap is large in size. I can use a different memory allocation
|
||||
* function instead of an ordinary malloc */
|
||||
* function instead of an ordinary malloc.
|
||||
* upon failure, it doesn't require to set error information as hcl_makeheap()
|
||||
* set the error number to HCL_EOOMEM. */
|
||||
|
||||
#if !defined(MAP_HUGETLB) && (defined(__amd64__) || defined(__x86_64__))
|
||||
# define MAP_HUGETLB 0x40000
|
||||
#endif
|
||||
|
||||
hcl_oow_t* ptr;
|
||||
int flags;
|
||||
hcl_oow_t actual_size;
|
||||
|
||||
flags = MAP_PRIVATE | MAP_ANONYMOUS;
|
||||
#if defined(MAP_HUGETLB)
|
||||
flags |= MAP_HUGETLB;
|
||||
#endif
|
||||
#if defined(MAP_UNINITIALIZED)
|
||||
flags |= MAP_UNINITIALIZED;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(MAP_HUGETLB)
|
||||
flags |= MAP_HUGETLB;
|
||||
#endif
|
||||
|
||||
#if defined(MAP_UNINITIALIZED)
|
||||
flags |= MAP_UNINITIALIZED;
|
||||
#endif
|
||||
|
||||
actual_size = HCL_SIZEOF(hcl_oow_t) + size;
|
||||
actual_size = HCL_ALIGN_POW2(actual_size, 2 * 1024 * 1024);
|
||||
ptr = (hcl_oow_t*)mmap(NULL, actual_size, PROT_READ | PROT_WRITE, flags, -1, 0);
|
||||
if (ptr == MAP_FAILED)
|
||||
{
|
||||
#if defined(MAP_HUGETLB)
|
||||
#if defined(MAP_HUGETLB)
|
||||
flags &= ~MAP_HUGETLB;
|
||||
ptr = (hcl_oow_t*)mmap(NULL, actual_size, PROT_READ | PROT_WRITE, flags, -1, 0);
|
||||
if (ptr == MAP_FAILED) return HCL_NULL;
|
||||
#else
|
||||
#else
|
||||
return HCL_NULL;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
*ptr = actual_size;
|
||||
|
||||
return (void*)(ptr + 1);
|
||||
/*return HCL_MMGR_ALLOC(hcl->mmgr, size);*/
|
||||
|
||||
#else
|
||||
return HCL_MMGR_ALLOC(hcl->mmgr, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void free_heap (hcl_t* hcl, void* ptr)
|
||||
{
|
||||
#if defined(HAVE_MMAP) && defined(HAVE_MUNMAP)
|
||||
hcl_oow_t* actual_ptr;
|
||||
actual_ptr = (hcl_oow_t*)ptr - 1;
|
||||
munmap (actual_ptr, *actual_ptr);
|
||||
/*return HCL_MMGR_FREE(hcl->mmgr, ptr);*/
|
||||
#else
|
||||
return HCL_MMGR_FREE(hcl->mmgr, ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int write_all (int fd, const char* ptr, hcl_oow_t len)
|
||||
|
Reference in New Issue
Block a user