summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--alloc.c4
-rw-r--r--darwin_stop_world.c2
-rw-r--r--dyn_load.c2
-rw-r--r--gcj_mlc.c4
-rw-r--r--include/private/gc_priv.h2
-rw-r--r--malloc.c11
-rw-r--r--mallocx.c8
-rw-r--r--mark_rts.c4
-rw-r--r--misc.c4
-rw-r--r--os_dep.c2
-rw-r--r--pthread_stop_world.c5
-rw-r--r--pthread_support.c13
-rw-r--r--ptr_chck.c6
-rw-r--r--thread_local_alloc.c2
-rw-r--r--typd_mlc.c4
-rw-r--r--win32_threads.c20
16 files changed, 54 insertions, 39 deletions
diff --git a/alloc.c b/alloc.c
index 609fae0d..e182af2e 100644
--- a/alloc.c
+++ b/alloc.c
@@ -936,7 +936,7 @@ STATIC GC_bool GC_try_to_collect_general(GC_stop_func stop_func,
IF_CANCEL(int cancel_state;)
DCL_LOCK_STATE;
- if (!GC_is_initialized) GC_init();
+ if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
if (GC_debugging_started) GC_print_all_smashed();
GC_INVOKE_FINALIZERS();
LOCK();
@@ -1183,7 +1183,7 @@ GC_API int GC_CALL GC_expand_hp(size_t bytes)
DCL_LOCK_STATE;
LOCK();
- if (!GC_is_initialized) GC_init();
+ if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
result = (int)GC_expand_hp_inner(divHBLKSZ((word)bytes));
if (result) GC_requested_heapsize += bytes;
UNLOCK();
diff --git a/darwin_stop_world.c b/darwin_stop_world.c
index f05dc685..16e24a96 100644
--- a/darwin_stop_world.c
+++ b/darwin_stop_world.c
@@ -271,7 +271,7 @@ GC_INNER void GC_push_all_stacks(void)
int nthreads = 0;
word total_size = 0;
mach_msg_type_number_t listcount = (mach_msg_type_number_t)THREAD_TABLE_SZ;
- if (!GC_thr_initialized)
+ if (!EXPECT(GC_thr_initialized, TRUE))
GC_thr_init();
# ifndef DARWIN_DONT_PARSE_STACK
diff --git a/dyn_load.c b/dyn_load.c
index 8532d285..80dfbc82 100644
--- a/dyn_load.c
+++ b/dyn_load.c
@@ -532,7 +532,7 @@ STATIC GC_bool GC_register_dynamic_libraries_dl_iterate_phdr(void)
{
static GC_bool excluded_segs = FALSE;
n_load_segs = 0;
- if (!excluded_segs) {
+ if (!EXPECT(excluded_segs, TRUE)) {
GC_exclude_static_roots_inner((ptr_t)load_segs,
(ptr_t)load_segs + sizeof(load_segs));
excluded_segs = TRUE;
diff --git a/gcj_mlc.c b/gcj_mlc.c
index 7b189b5f..a7fefd9d 100644
--- a/gcj_mlc.c
+++ b/gcj_mlc.c
@@ -144,8 +144,8 @@ static void maybe_finalize(void)
static word last_finalized_no = 0;
DCL_LOCK_STATE;
- if (GC_gc_no == last_finalized_no) return;
- if (!GC_is_initialized) return;
+ if (GC_gc_no == last_finalized_no ||
+ !EXPECT(GC_is_initialized, TRUE)) return;
UNLOCK();
GC_INVOKE_FINALIZERS();
LOCK();
diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h
index 17703040..d28d8078 100644
--- a/include/private/gc_priv.h
+++ b/include/private/gc_priv.h
@@ -1855,7 +1855,7 @@ GC_EXTERN GC_bool GC_have_errors; /* We saw a smashed or leaked object. */
#ifndef NO_DEBUGGING
GC_EXTERN GC_bool GC_dump_regularly;
/* Generate regular debugging dumps. */
-# define COND_DUMP if (GC_dump_regularly) GC_dump()
+# define COND_DUMP if (EXPECT(GC_dump_regularly, FALSE)) GC_dump()
#else
# define COND_DUMP /* empty */
#endif
diff --git a/malloc.c b/malloc.c
index aeda6936..75c9e0e4 100644
--- a/malloc.c
+++ b/malloc.c
@@ -49,7 +49,7 @@ GC_INNER ptr_t GC_alloc_large(size_t lb, int k, unsigned flags)
/* Round up to a multiple of a granule. */
lb = (lb + GRANULE_BYTES - 1) & ~(GRANULE_BYTES - 1);
n_blocks = OBJ_SZ_TO_BLOCKS(lb);
- if (!GC_is_initialized) GC_init();
+ if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
/* Do our share of marking work */
if (GC_incremental && !GC_dont_gc)
GC_collect_a_little_inner((int)n_blocks);
@@ -111,7 +111,7 @@ GC_INNER void * GC_generic_malloc_inner(size_t lb, int k)
if( (op = *opp) == 0 ) {
if (GC_size_map[lb] == 0) {
- if (!GC_is_initialized) GC_init();
+ if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
if (GC_size_map[lb] == 0) GC_extend_size_map(lb);
return(GC_generic_malloc_inner(lb, k));
}
@@ -154,7 +154,8 @@ GC_API void * GC_CALL GC_generic_malloc(size_t lb, int k)
void * result;
DCL_LOCK_STATE;
- if (GC_have_errors) GC_print_all_errors();
+ if (EXPECT(GC_have_errors, FALSE))
+ GC_print_all_errors();
GC_INVOKE_FINALIZERS();
if (SMALL_OBJ(lb)) {
LOCK();
@@ -340,7 +341,7 @@ void * malloc(size_t lb)
* The thread implementation may well call malloc at other
* inopportune times.
*/
- if (!GC_is_initialized) return sbrk(lb);
+ if (!EXPECT(GC_is_initialized, TRUE)) return sbrk(lb);
# endif /* I386 && GC_SOLARIS_THREADS */
return((void *)REDIRECT_MALLOC(lb));
}
@@ -379,7 +380,7 @@ void * calloc(size_t n, size_t lb)
ptr_t caller = (ptr_t)__builtin_return_address(0);
/* This test does not need to ensure memory visibility, since */
/* the bounds will be set when/if we create another thread. */
- if (!lib_bounds_set) {
+ if (!EXPECT(lib_bounds_set, TRUE)) {
GC_init_lib_bounds();
lib_bounds_set = TRUE;
}
diff --git a/mallocx.c b/mallocx.c
index e5928358..651cbad6 100644
--- a/mallocx.c
+++ b/mallocx.c
@@ -184,7 +184,8 @@ GC_INNER void * GC_generic_malloc_ignore_off_page(size_t lb, int k)
lb_rounded = GRANULES_TO_BYTES(lg);
n_blocks = OBJ_SZ_TO_BLOCKS(lb_rounded);
init = GC_obj_kinds[k].ok_init;
- if (GC_have_errors) GC_print_all_errors();
+ if (EXPECT(GC_have_errors, FALSE))
+ GC_print_all_errors();
GC_INVOKE_FINALIZERS();
LOCK();
result = (ptr_t)GC_alloc_large(ADD_SLOP(lb), k, IGNORE_OFF_PAGE);
@@ -286,10 +287,11 @@ GC_API void GC_CALL GC_generic_malloc_many(size_t lb, int k, void **result)
}
lw = BYTES_TO_WORDS(lb);
lg = BYTES_TO_GRANULES(lb);
- if (GC_have_errors) GC_print_all_errors();
+ if (EXPECT(GC_have_errors, FALSE))
+ GC_print_all_errors();
GC_INVOKE_FINALIZERS();
LOCK();
- if (!GC_is_initialized) GC_init();
+ if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
/* Do our share of marking work */
if (GC_incremental && !GC_dont_gc) {
ENTER_GC();
diff --git a/mark_rts.c b/mark_rts.c
index 5afdab51..b7b81320 100644
--- a/mark_rts.c
+++ b/mark_rts.c
@@ -139,7 +139,7 @@ GC_API void GC_CALL GC_add_roots(void *b, void *e)
{
DCL_LOCK_STATE;
- if (!GC_is_initialized) GC_init();
+ if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
LOCK();
GC_add_roots_inner((ptr_t)b, (ptr_t)e, FALSE);
UNLOCK();
@@ -245,7 +245,7 @@ GC_API void GC_CALL GC_clear_roots(void)
{
DCL_LOCK_STATE;
- if (!GC_is_initialized) GC_init();
+ if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
LOCK();
roots_were_cleared = TRUE;
n_root_sets = 0;
diff --git a/misc.c b/misc.c
index 27f264ae..18cc44d5 100644
--- a/misc.c
+++ b/misc.c
@@ -361,7 +361,7 @@ GC_API void * GC_CALL GC_base(void * p)
ptr_t limit;
r = p;
- if (!GC_is_initialized) return 0;
+ if (!EXPECT(GC_is_initialized, TRUE)) return 0;
h = HBLKPTR(r);
GET_BI(r, bi);
candidate_hdr = HDR_FROM_BI(bi, r);
@@ -659,7 +659,7 @@ GC_API void GC_CALL GC_init(void)
word initial_heap_sz;
IF_CANCEL(int cancel_state;)
- if (GC_is_initialized) return;
+ if (EXPECT(GC_is_initialized, TRUE)) return;
# ifdef REDIRECT_MALLOC
{
static GC_bool init_started = FALSE;
diff --git a/os_dep.c b/os_dep.c
index 97d84b0d..a3f78001 100644
--- a/os_dep.c
+++ b/os_dep.c
@@ -2040,7 +2040,7 @@ STATIC ptr_t GC_unix_mmap_get_mem(word bytes)
# ifndef USE_MMAP_ANON
static GC_bool initialized = FALSE;
- if (!initialized) {
+ if (!EXPECT(initialized, TRUE)) {
zero_fd = open("/dev/zero", O_RDONLY);
fcntl(zero_fd, F_SETFD, FD_CLOEXEC);
initialized = TRUE;
diff --git a/pthread_stop_world.c b/pthread_stop_world.c
index a354a84d..af7f9b1e 100644
--- a/pthread_stop_world.c
+++ b/pthread_stop_world.c
@@ -312,7 +312,8 @@ GC_INNER void GC_push_all_stacks(void)
pthread_t self = pthread_self();
word total_size = 0;
- if (!GC_thr_initialized) GC_thr_init();
+ if (!EXPECT(GC_thr_initialized, TRUE))
+ GC_thr_init();
# ifdef DEBUG_THREADS
GC_log_printf("Pushing stacks from thread 0x%x\n", (unsigned)self);
# endif
@@ -693,7 +694,7 @@ GC_INNER void GC_stop_world(void)
{
int i;
pthread_mutex_lock(&GC_nacl_thread_alloc_lock);
- if (!GC_nacl_thread_parking_inited) {
+ if (!EXPECT(GC_nacl_thread_parking_inited, TRUE)) {
BZERO(GC_nacl_thread_parked, sizeof(GC_nacl_thread_parked));
BZERO(GC_nacl_thread_used, sizeof(GC_nacl_thread_used));
GC_nacl_thread_parking_inited = TRUE;
diff --git a/pthread_support.c b/pthread_support.c
index da53b5c0..c7df3741 100644
--- a/pthread_support.c
+++ b/pthread_support.c
@@ -275,7 +275,8 @@ GC_INNER unsigned long GC_lock_holder = NO_THREAD;
GC_syms_initialized = TRUE;
}
-# define INIT_REAL_SYMS() if (!GC_syms_initialized) GC_init_real_syms();
+# define INIT_REAL_SYMS() if (!EXPECT(GC_syms_initialized, TRUE)) \
+ GC_init_real_syms()
#else
# define INIT_REAL_SYMS()
#endif
@@ -475,7 +476,7 @@ STATIC GC_thread GC_new_thread(pthread_t id)
static GC_bool first_thread_used = FALSE;
GC_ASSERT(I_HOLD_LOCK());
- if (!first_thread_used) {
+ if (!EXPECT(first_thread_used, TRUE)) {
result = &first_thread;
first_thread_used = TRUE;
} else {
@@ -1511,8 +1512,9 @@ GC_API int WRAP_FUNC(pthread_create)(pthread_t *new_thread,
si = (struct start_info *)GC_INTERNAL_MALLOC(sizeof(struct start_info),
NORMAL);
UNLOCK();
- if (!parallel_initialized) GC_init_parallel();
- if (0 == si &&
+ if (!EXPECT(parallel_initialized, TRUE))
+ GC_init_parallel();
+ if (EXPECT(0 == si, FALSE) &&
(si = (struct start_info *)
(*GC_get_oom_fn())(sizeof(struct start_info))) == 0)
return(ENOMEM);
@@ -1522,7 +1524,8 @@ GC_API int WRAP_FUNC(pthread_create)(pthread_t *new_thread,
si -> start_routine = start_routine;
si -> arg = arg;
LOCK();
- if (!GC_thr_initialized) GC_thr_init();
+ if (!EXPECT(GC_thr_initialized, TRUE))
+ GC_thr_init();
# ifdef GC_ASSERTIONS
{
size_t stack_size = 0;
diff --git a/ptr_chck.c b/ptr_chck.c
index 5b3cc0a6..a4766339 100644
--- a/ptr_chck.c
+++ b/ptr_chck.c
@@ -43,7 +43,7 @@ GC_API void * GC_CALL GC_same_obj(void *p, void *q)
ptr_t base, limit;
word sz;
- if (!GC_is_initialized) GC_init();
+ if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
hhdr = HDR((word)p);
if (hhdr == 0) {
if (divHBLKSZ((word)p) != divHBLKSZ((word)q)
@@ -122,7 +122,7 @@ GC_API void * GC_CALL GC_is_valid_displacement(void *p)
struct hblk *h;
word sz;
- if (!GC_is_initialized) GC_init();
+ if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
hhdr = HDR((word)p);
if (hhdr == 0) return(p);
h = HBLKPTR(p);
@@ -189,7 +189,7 @@ GC_API void * GC_CALL GC_is_visible(void *p)
hdr *hhdr;
if ((word)p & (ALIGNMENT - 1)) goto fail;
- if (!GC_is_initialized) GC_init();
+ if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
# ifdef THREADS
hhdr = HDR((word)p);
if (hhdr != 0 && GC_base(p) == 0) {
diff --git a/thread_local_alloc.c b/thread_local_alloc.c
index 83211675..82523cd6 100644
--- a/thread_local_alloc.c
+++ b/thread_local_alloc.c
@@ -89,7 +89,7 @@ GC_INNER void GC_init_thread_local(GC_tlfs p)
int i;
GC_ASSERT(I_HOLD_LOCK());
- if (!keys_initialized) {
+ if (!EXPECT(keys_initialized, TRUE)) {
if (0 != GC_key_create(&GC_thread_key, 0)) {
ABORT("Failed to create key for local allocator");
}
diff --git a/typd_mlc.c b/typd_mlc.c
index 1cf9f284..e94171be 100644
--- a/typd_mlc.c
+++ b/typd_mlc.c
@@ -539,7 +539,9 @@ GC_API GC_descr GC_CALL GC_make_descriptor(GC_bitmap bm, size_t len)
signed_word i;
# define HIGH_BIT (((word)1) << (WORDSZ - 1))
- if (!GC_explicit_typing_initialized) GC_init_explicit_typing();
+ if (!EXPECT(GC_explicit_typing_initialized, TRUE))
+ GC_init_explicit_typing();
+
while (last_set_bit >= 0 && !GC_get_bit(bm, last_set_bit))
last_set_bit--;
if (last_set_bit < 0) return(0 /* no pointers */);
diff --git a/win32_threads.c b/win32_threads.c
index 414dcc50..859db67c 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -330,7 +330,7 @@ STATIC GC_thread GC_new_thread(DWORD id)
GC_thread result;
GC_ASSERT(I_HOLD_LOCK());
- if (!first_thread_used) {
+ if (!EXPECT(first_thread_used, TRUE)) {
result = &first_thread;
first_thread_used = TRUE;
} else {
@@ -2061,7 +2061,8 @@ GC_INNER void GC_get_next_stack(char *start, char *limit,
HANDLE thread_h;
thread_args *args;
- if (!parallel_initialized) GC_init_parallel();
+ if (!EXPECT(parallel_initialized, TRUE))
+ GC_init_parallel();
/* make sure GC is initialized (i.e. main thread is */
/* attached, tls initialized). */
@@ -2109,7 +2110,8 @@ GC_INNER void GC_get_next_stack(char *start, char *limit,
GC_uintptr_t thread_h;
thread_args *args;
- if (!parallel_initialized) GC_init_parallel();
+ if (!EXPECT(parallel_initialized, TRUE))
+ GC_init_parallel();
/* make sure GC is initialized (i.e. main thread is */
/* attached, tls initialized). */
# ifdef DEBUG_THREADS
@@ -2365,7 +2367,8 @@ GC_INNER void GC_thr_init(void)
(long)GetCurrentThreadId(), GC_PTHREAD_PTRVAL(pthread_id));
# endif
- if (!parallel_initialized) GC_init_parallel();
+ if (!EXPECT(parallel_initialized, TRUE))
+ GC_init_parallel();
/* Thread being joined might not have registered itself yet. */
/* After the join,thread id may have been recycled. */
@@ -2405,7 +2408,8 @@ GC_INNER void GC_thr_init(void)
GC_PTHREAD_CREATE_CONST pthread_attr_t *attr,
void *(*start_routine)(void *), void *arg)
{
- if (!parallel_initialized) GC_init_parallel();
+ if (!EXPECT(parallel_initialized, TRUE))
+ GC_init_parallel();
/* make sure GC is initialized (i.e. main thread is attached) */
if (GC_win32_dll_threads) {
return pthread_create(new_thread, attr, start_routine, arg);
@@ -2525,7 +2529,8 @@ GC_INNER void GC_thr_init(void)
GC_API int GC_pthread_sigmask(int how, const sigset_t *set,
sigset_t *oset)
{
- if (!parallel_initialized) GC_init_parallel();
+ if (!EXPECT(parallel_initialized, TRUE))
+ GC_init_parallel();
return pthread_sigmask(how, set, oset);
}
# endif /* !GC_NO_PTHREAD_SIGMASK */
@@ -2536,7 +2541,8 @@ GC_INNER void GC_thr_init(void)
GC_thread t;
DCL_LOCK_STATE;
- if (!parallel_initialized) GC_init_parallel();
+ if (!EXPECT(parallel_initialized, TRUE))
+ GC_init_parallel();
LOCK();
t = GC_lookup_pthread(thread);
UNLOCK();