Skip to content

Commit

Permalink
Declare all internal functions in private headers instead of .c files
Browse files Browse the repository at this point in the history
(code refactoring)

Issue #206 (bdwgc).

* include/private/darwin_stop_world.h [MPROTECT_VDB
&& !GC_NO_THREADS_DISCOVERY] (GC_darwin_register_mach_handler_thread):
Declare function.
* include/private/gc_priv.h [WRAP_MARK_SOME && PARALLEL_MARK]
(GC_push_conditional_eager): Likewise.
* include/private/gc_priv.h [!THREADS && TRACE_BUF]
(GC_add_trace_entry): Likewise.
* include/private/gc_priv.h (GC_collect_or_expand): Likewise.
* include/private/gc_priv.h [MPROTECT_VDB && USE_MUNMAP]
(GC_mprotect_dirty_init, GC_has_unmapped_memory): Likewise.
* include/private/gc_priv.h [CHECKSUMS && MPROTECT_VDB && !DARWIN]
(GC_record_fault): Likewise.
* include/private/gc_priv.h [CHECKSUMS] (GC_check_dirty): Likewise.
* include/private/gc_priv.h [GC_WIN32_THREADS && WRAP_MARK_SOME
&& !GC_PTHREADS] (GC_started_thread_while_stopped): Likewise.
* include/private/gc_priv.h [SEARCH_FOR_DATA_START
|| NETBSD && __ELF__] (GC_find_limit): Likewise.
* include/private/gc_priv.h [NEED_PROC_MAPS && (IA64
|| INCLUDE_LINUX_THREAD_DESCR)] (GC_enclosing_mapping): Likewise.
* include/private/pthread_support.h (GC_inner_start_routine): Likewise.
* include/private/thread_local_alloc.h [GC_ASSERTIONS]
(GC_is_thread_tsd_valid, GC_check_tls_for): Likewise.
* include/private/thread_local_alloc.h [GC_ASSERTIONS
&& USE_CUSTOM_SPECIFIC] (GC_check_tsd_marks): Likewise.
* include/private/gc_priv.h [HEURISTIC2 || SEARCH_FOR_DATA_START
|| !STACKBOTTOM && HEURISTIC2 || (SVR4 || AIX || DGUX
|| LINUX && SPARC) && !PCR] (NEED_FIND_LIMIT): Collapse multiple
definitions.
* malloc.c (GC_collect_or_expand): Remove prototype.
* mark.c [CHECKSUMS] (GC_check_dirty): Likewise.
* mark.c [GC_WIN32_THREADS && !GC_PTHREADS]
(GC_started_thread_while_stopped): Likewise.
* mark_rts.c [WRAP_MARK_SOME && PARALLEL_MARK]
(GC_push_conditional_eager): Likewise.
* mark_rts.c [!THREADS && TRACE_BUF] (GC_add_trace_entry): Likewise.
* os_dep.c [SEARCH_FOR_DATA_START || NETBSD && __ELF__]
(GC_find_limit): Likewise.
* os_dep.c [CHECKSUMS && MPROTECT_VDB && !DARWIN] (GC_record_fault):
Likewise.
* os_dep.c [MPROTECT_VDB && USE_MUNMAP] (GC_has_unmapped_memory,
GC_mprotect_dirty_init): Likewise.
* os_dep.c [MPROTECT_VDB && !GC_NO_THREADS_DISCOVERY]
(GC_darwin_register_mach_handler_thread): Likewise.
* pthread_support.c [GC_ASSERTIONS] (GC_check_tls_for): Likewise.
* pthread_support.c [GC_ASSERTIONS && USE_CUSTOM_SPECIFIC]
(GC_check_tsd_marks): Likewise.
* pthread_support.c [INCLUDE_LINUX_THREAD_DESCR]
(GC_enclosing_mapping): Likewise.
* pthread_support.c [!SN_TARGET_ORBIS && !SN_TARGET_PSP2]
(GC_inner_start_routine): Likewise.
* thread_local_alloc.c [GC_ASSERTIONS] (GC_is_thread_tsd_valid):
Likewise.
* win32_threads.c [GC_ASSERTIONS] (GC_check_tls_for): Likewise.
* win32_threads.c [GC_ASSERTIONS && USE_CUSTOM_SPECIFIC]
(GC_check_tsd_marks): Likewise.
  • Loading branch information
ivmai committed Feb 28, 2018
1 parent 4ec44cf commit 8a1f78a
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 73 deletions.
3 changes: 3 additions & 0 deletions include/private/darwin_stop_world.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ struct thread_stop_info {
#ifdef MPROTECT_VDB
GC_INNER void GC_mprotect_stop(void);
GC_INNER void GC_mprotect_resume(void);
# ifndef GC_NO_THREADS_DISCOVERY
GC_INNER void GC_darwin_register_mach_handler_thread(mach_port_t thread);
# endif
#endif

#if defined(PARALLEL_MARK) && !defined(GC_NO_THREADS_DISCOVERY)
Expand Down
62 changes: 46 additions & 16 deletions include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,13 @@ GC_INNER void GC_push_all_stack(ptr_t b, ptr_t t);
/* As GC_push_all but consider */
/* interior pointers as valid. */

#if defined(WRAP_MARK_SOME) && defined(PARALLEL_MARK)
/* GC_mark_local does not handle memory protection faults yet. So, */
/* the static data regions are scanned immediately by GC_push_roots. */
GC_INNER void GC_push_conditional_eager(void *bottom, void *top,
GC_bool all);
#endif

/* In the threads case, we push part of the current thread stack */
/* with GC_push_all_eager when we push the registers. This gets the */
/* callee-save registers that may disappear. The remainder of the */
Expand Down Expand Up @@ -1836,7 +1843,10 @@ void GC_register_data_segments(void);
GC_INNER GC_bool GC_is_static_root(void *p);
/* Is the address p in one of the registered static */
/* root sections? */
#endif
# ifdef TRACE_BUF
void GC_add_trace_entry(char *kind, word arg1, word arg2);
# endif
#endif /* !THREADS */

/* Black listing: */
#ifdef PRINT_BLACK_LIST
Expand Down Expand Up @@ -1993,6 +2003,9 @@ GC_INNER void * GC_generic_malloc_inner(size_t lb, int k);
/* object is live. */
#endif

GC_INNER GC_bool GC_collect_or_expand(word needed_blocks,
GC_bool ignore_off_page, GC_bool retry);

GC_INNER ptr_t GC_allocobj(size_t sz, int kind);
/* Make the indicated */
/* free list nonempty, and return its */
Expand Down Expand Up @@ -2357,17 +2370,30 @@ GC_EXTERN signed_word GC_bytes_found;
GC_EXTERN ptr_t * GC_gcjobjfreelist;
#endif

#if defined(GWW_VDB) && defined(MPROTECT_VDB)
GC_INNER GC_bool GC_gww_dirty_init(void);
/* Defined in os_dep.c. Returns TRUE if GetWriteWatch is available. */
/* May be called repeatedly. */
#endif
#ifdef MPROTECT_VDB
# ifdef GWW_VDB
GC_INNER GC_bool GC_gww_dirty_init(void);
/* Returns TRUE if GetWriteWatch is available. */
/* May be called repeatedly. */
# endif
# ifdef USE_MUNMAP
GC_INNER GC_bool GC_mprotect_dirty_init(void);
GC_INNER GC_bool GC_has_unmapped_memory(void);
# endif
#endif /* MPROTECT_VDB */

#if defined(CHECKSUMS) || defined(PROC_VDB)
GC_INNER GC_bool GC_page_was_ever_dirty(struct hblk * h);
/* Could the page contain valid heap pointers? */
#endif

#ifdef CHECKSUMS
# if defined(MPROTECT_VDB) && !defined(DARWIN)
void GC_record_fault(struct hblk * h);
# endif
void GC_check_dirty(void);
#endif

GC_INNER void GC_default_print_heap_obj_proc(ptr_t p);

GC_INNER void GC_setpagesize(void);
Expand Down Expand Up @@ -2415,6 +2441,10 @@ GC_INNER ptr_t GC_store_debug_info(ptr_t p, word sz, const char *str,
# ifdef MPROTECT_VDB
GC_INNER void GC_set_write_fault_handler(void);
# endif
# if defined(WRAP_MARK_SOME) && !defined(GC_PTHREADS)
GC_INNER GC_bool GC_started_thread_while_stopped(void);
/* Did we invalidate mark phase with an unexpected thread start? */
# endif
#endif /* GC_WIN32_THREADS */

#ifdef THREADS
Expand All @@ -2439,10 +2469,12 @@ GC_INNER ptr_t GC_store_debug_info(ptr_t p, word sz, const char *str,

#ifdef SEARCH_FOR_DATA_START
GC_INNER void GC_init_linux_data_start(void);
ptr_t GC_find_limit(ptr_t, GC_bool);
#endif

#if defined(NETBSD) && defined(__ELF__)
GC_INNER void GC_init_netbsd_elf(void);
ptr_t GC_find_limit(ptr_t, GC_bool);
#endif

#ifdef UNIX_LIKE
Expand All @@ -2454,6 +2486,10 @@ GC_INNER ptr_t GC_store_debug_info(ptr_t p, word sz, const char *str,
GC_INNER char *GC_parse_map_entry(char *buf_ptr, ptr_t *start, ptr_t *end,
char **prot, unsigned int *maj_dev,
char **mapping_name);
# endif
# if defined(IA64) || defined(INCLUDE_LINUX_THREAD_DESCR)
GC_INNER GC_bool GC_enclosing_mapping(ptr_t addr,
ptr_t *startp, ptr_t *endp);
# endif
GC_INNER char *GC_get_maps(void); /* from os_dep.c */
#endif /* NEED_PROC_MAPS */
Expand Down Expand Up @@ -2616,16 +2652,10 @@ GC_INNER ptr_t GC_store_debug_info(ptr_t p, word sz, const char *str,

/* Do we need the GC_find_limit machinery to find the end of a */
/* data segment. */
#if defined(HEURISTIC2) || defined(SEARCH_FOR_DATA_START)
# define NEED_FIND_LIMIT
#endif

#if !defined(STACKBOTTOM) && defined(HEURISTIC2)
# define NEED_FIND_LIMIT
#endif

#if (defined(SVR4) || defined(AIX) || defined(DGUX) \
|| (defined(LINUX) && defined(SPARC))) && !defined(PCR)
#if defined(HEURISTIC2) || defined(SEARCH_FOR_DATA_START) \
|| (!defined(STACKBOTTOM) && defined(HEURISTIC2)) \
|| ((defined(SVR4) || defined(AIX) || defined(DGUX) \
|| (defined(LINUX) && defined(SPARC))) && !defined(PCR))
# define NEED_FIND_LIMIT
#endif

Expand Down
3 changes: 3 additions & 0 deletions include/private/pthread_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ GC_EXTERN GC_bool GC_in_thread_creation;
# define GC_INNER_PTHRSTART GC_INNER
#endif

GC_INNER_PTHRSTART void * GC_CALLBACK GC_inner_start_routine(
struct GC_stack_base *sb, void *arg);

GC_INNER_PTHRSTART GC_thread GC_start_rtn_prepare_thread(
void *(**pstart)(void *),
void **pstart_arg,
Expand Down
8 changes: 8 additions & 0 deletions include/private/thread_local_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ GC_INNER void GC_destroy_thread_local(GC_tlfs p);
/* we take care of an individual thread freelist structure. */
GC_INNER void GC_mark_thread_local_fls_for(GC_tlfs p);

#ifdef GC_ASSERTIONS
GC_bool GC_is_thread_tsd_valid(void *tsd);
void GC_check_tls_for(GC_tlfs p);
# if defined(USE_CUSTOM_SPECIFIC)
void GC_check_tsd_marks(tsd *key);
# endif
#endif /* GC_ASSERTIONS */

#ifndef GC_ATTR_TLS_FAST
# define GC_ATTR_TLS_FAST /* empty */
#endif
Expand Down
4 changes: 0 additions & 4 deletions malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ STATIC GC_bool GC_alloc_reclaim_list(struct obj_kind *kind)
return(TRUE);
}

GC_INNER GC_bool GC_collect_or_expand(word needed_blocks,
GC_bool ignore_off_page,
GC_bool retry); /* from alloc.c */

/* Allocate a large block of size lb bytes. */
/* The block is not cleared. */
/* Flags is 0 or IGNORE_OFF_PAGE. */
Expand Down
10 changes: 0 additions & 10 deletions mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,6 @@ GC_INNER void GC_clear_marks(void)
scan_ptr = 0;
}

#ifdef CHECKSUMS
void GC_check_dirty(void);
#endif

/* Initiate a garbage collection. Initiates a full collection if the */
/* mark state is invalid. */
GC_INNER void GC_initiate_gc(void)
Expand Down Expand Up @@ -486,12 +482,6 @@ static void alloc_mark_stack(size_t);
}
# endif /* __GNUC__ && MSWIN32 */

#if defined(GC_WIN32_THREADS) && !defined(GC_PTHREADS)
GC_INNER GC_bool GC_started_thread_while_stopped(void);
/* In win32_threads.c. Did we invalidate mark phase with an */
/* unexpected thread start? */
#endif

GC_INNER GC_bool GC_mark_some(ptr_t cold_gc_frame)
{
GC_bool ret_val;
Expand Down
9 changes: 0 additions & 9 deletions mark_rts.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,6 @@ GC_API void GC_CALL GC_exclude_static_roots(void *b, void *e)
}

#if defined(WRAP_MARK_SOME) && defined(PARALLEL_MARK)
/* GC_mark_local does not handle memory protection faults yet. So, */
/* the static data regions are scanned immediately by GC_push_roots. */
GC_INNER void GC_push_conditional_eager(void *bottom, void *top,
GC_bool all);
# define GC_PUSH_CONDITIONAL(b, t, all) \
(GC_parallel \
? GC_push_conditional_eager(b, t, all) \
Expand Down Expand Up @@ -586,11 +582,6 @@ GC_INNER void GC_push_all_stack_sections(ptr_t lo, ptr_t hi,

#else /* !THREADS */

# ifdef TRACE_BUF
/* Defined in mark.c. */
void GC_add_trace_entry(char *kind, word arg1, word arg2);
# endif

/* Similar to GC_push_all_eager, but only the */
/* part hotter than cold_gc_frame is scanned */
/* immediately. Needed to ensure that callee- */
Expand Down
14 changes: 0 additions & 14 deletions os_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,6 @@ GC_INNER char * GC_get_maps(void)

ptr_t GC_data_start = NULL;

ptr_t GC_find_limit(ptr_t, GC_bool);

GC_INNER void GC_init_linux_data_start(void)
{
ptr_t data_end = DATAEND;
Expand Down Expand Up @@ -498,7 +496,6 @@ GC_INNER char * GC_get_maps(void)

#if defined(NETBSD) && defined(__ELF__)
ptr_t GC_data_start = NULL;
ptr_t GC_find_limit(ptr_t, GC_bool);

extern char **environ;

Expand Down Expand Up @@ -3231,10 +3228,6 @@ GC_API GC_push_other_roots_proc GC_CALL GC_get_push_other_roots(void)

#ifndef DARWIN

# ifdef CHECKSUMS
void GC_record_fault(struct hblk * h); /* from checksums.c */
# endif

# if !defined(MSWIN32) && !defined(MSWINCE)
# include <errno.h>
# if defined(FREEBSD) || defined(HURD) || defined(HPUX)
Expand Down Expand Up @@ -3446,9 +3439,6 @@ GC_INNER void GC_remove_protection(struct hblk *h, word nblocks,
}

#ifdef USE_MUNMAP
GC_INNER GC_bool GC_has_unmapped_memory(void); /* from allchblk.c */
GC_INNER GC_bool GC_mprotect_dirty_init(void);

/* MPROTECT_VDB cannot deal with address space holes (for now), */
/* so if the collector is configured with both MPROTECT_VDB and */
/* USE_MUNMAP then, as a work around, select only one of them */
Expand Down Expand Up @@ -4104,10 +4094,6 @@ typedef enum {
GC_mprotect_thread_notify(ID_RESUME);
}

# ifndef GC_NO_THREADS_DISCOVERY
GC_INNER void GC_darwin_register_mach_handler_thread(mach_port_t thread);
# endif

#else
/* The compiler should optimize away any GC_mprotect_state computations */
# define GC_mprotect_state GC_MP_NORMAL
Expand Down
11 changes: 0 additions & 11 deletions pthread_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,6 @@ STATIC int GC_nprocs = 1;
}

# if defined(GC_ASSERTIONS)
void GC_check_tls_for(GC_tlfs p);
# if defined(USE_CUSTOM_SPECIFIC)
void GC_check_tsd_marks(tsd *key);
# endif

/* Check that all thread-local free-lists are completely marked. */
/* Also check that thread-specific-data structures are marked. */
void GC_check_tls(void)
Expand Down Expand Up @@ -1170,8 +1165,6 @@ static void fork_child_proc(void)

#ifdef INCLUDE_LINUX_THREAD_DESCR
__thread int GC_dummy_thread_local;
GC_INNER GC_bool GC_enclosing_mapping(ptr_t addr,
ptr_t *startp, ptr_t *endp);
#endif

#ifdef PARALLEL_MARK
Expand Down Expand Up @@ -1787,10 +1780,6 @@ GC_INNER_PTHRSTART GC_thread GC_start_rtn_prepare_thread(
}

#if !defined(SN_TARGET_ORBIS) && !defined(SN_TARGET_PSP2)
GC_INNER_PTHRSTART void * GC_CALLBACK GC_inner_start_routine(
struct GC_stack_base *sb, void *arg);
/* defined in pthread_start.c */

STATIC void * GC_start_routine(void * arg)
{
# ifdef INCLUDE_LINUX_THREAD_DESCR
Expand Down
5 changes: 0 additions & 5 deletions thread_local_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ GC_INNER void GC_destroy_thread_local(GC_tlfs p)
# endif
}

#ifdef GC_ASSERTIONS
/* Defined in pthread_support.c or win32_threads.c. */
GC_bool GC_is_thread_tsd_valid(void *tsd);
#endif

GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_kind(size_t bytes, int knd)
{
size_t granules;
Expand Down
4 changes: 0 additions & 4 deletions win32_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -2897,10 +2897,6 @@ GC_INNER void GC_init_parallel(void)
}

# if defined(GC_ASSERTIONS)
void GC_check_tls_for(GC_tlfs p);
# if defined(USE_CUSTOM_SPECIFIC)
void GC_check_tsd_marks(tsd *key);
# endif
/* Check that all thread-local free-lists are completely marked. */
/* also check that thread-specific-data structures are marked. */
void GC_check_tls(void)
Expand Down

0 comments on commit 8a1f78a

Please sign in to comment.