[pypy-commit] stmgc default: Give a 3rd compilation mode, "release", which disables even the asserts.
arigo
noreply at buildbot.pypy.org
Tue Jun 25 11:23:59 CEST 2013
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r270:4b9a102163cd
Date: 2013-06-25 11:23 +0200
http://bitbucket.org/pypy/stmgc/changeset/4b9a102163cd/
Log: Give a 3rd compilation mode, "release", which disables even the
asserts. (The gain in speed is inconsistent.)
diff --git a/c4/Makefile b/c4/Makefile
--- a/c4/Makefile
+++ b/c4/Makefile
@@ -2,14 +2,16 @@
# Makefile for the demos.
#
+DEBUG_EXE = debug-demo1 debug-demo2 debug-demo_random
BUILD_EXE = build-demo1 build-demo2 build-demo_random
-DEBUG_EXE = debug-demo1 debug-demo2 debug-demo_random
+RELEASE_EXE = release-demo1 release-demo2 release-demo_random
-build: $(BUILD_EXE)
-debug: $(DEBUG_EXE)
+debug: $(DEBUG_EXE) # with prints and asserts
+build: $(BUILD_EXE) # without prints, but with asserts
+release: $(RELEASE_EXE) # without prints nor asserts
clean:
- rm -f $(BUILD_EXE) $(DEBUG_EXE)
+ rm -f $(BUILD_EXE) $(DEBUG_EXE) $(RELEASE_EXE)
H_FILES = atomic_ops.h stmgc.h stmimpl.h \
@@ -29,5 +31,8 @@
debug-%: %.c ${H_FILES} ${C_FILES}
gcc -lrt -pthread ${DEBUG} $< -o debug-$* -Wall ${C_FILES}
+release-%: %.c ${H_FILES} ${C_FILES} stmgc.c
+ gcc -lrt -pthread -DNDEBUG -O2 -g $< -o release-$* -Wall stmgc.c
+
test-%:
./$* 2>/dev/null | grep "check ok"
diff --git a/c4/demo1.c b/c4/demo1.c
--- a/c4/demo1.c
+++ b/c4/demo1.c
@@ -11,7 +11,11 @@
#include "fprintcolor.h"
-#define UPPER_BOUND 100
+#ifdef _GC_DEBUG
+# define UPPER_BOUND 100
+#else
+# define UPPER_BOUND 5000
+#endif
#define NUMTHREADS 4
@@ -134,7 +138,8 @@
stm_finalize();
status = sem_post(&done);
- assert(status == 0);
+ if (status != 0)
+ stm_fatalerror("status != 0\n");
return NULL;
}
@@ -158,7 +163,8 @@
{
pthread_t th;
int status = pthread_create(&th, NULL, func, arg);
- assert(status == 0);
+ if (status != 0)
+ stm_fatalerror("status != 0\n");
pthread_detach(th);
printf("started new thread\n");
}
@@ -168,7 +174,8 @@
int i, status;
status = sem_init(&done, 0, 0);
- assert(status == 0);
+ if (status != 0)
+ stm_fatalerror("status != 0\n");
for (i = 0; i < NUMTHREADS; i++)
newthread(demo1, NULL);
@@ -176,7 +183,8 @@
for (i=0; i < NUMTHREADS; i++)
{
status = sem_wait(&done);
- assert(status == 0);
+ if (status != 0)
+ stm_fatalerror("status != 0\n");
printf("thread finished\n");
}
diff --git a/c4/demo2.c b/c4/demo2.c
--- a/c4/demo2.c
+++ b/c4/demo2.c
@@ -154,7 +154,8 @@
void final_check(void)
{
long sum;
-
+
+ printf("final check\n");
stm_initialize();
sum = check_sorted();
@@ -171,7 +172,8 @@
{
pthread_t th;
int status = pthread_create(&th, NULL, func, arg);
- assert(status == 0);
+ if (status != 0)
+ stm_fatalerror("newthread: pthread_create failure\n");
pthread_detach(th);
printf("started new thread\n");
}
diff --git a/c4/demo_random.c b/c4/demo_random.c
--- a/c4/demo_random.c
+++ b/c4/demo_random.c
@@ -467,7 +467,8 @@
{
pthread_t th;
int status = pthread_create(&th, NULL, func, arg);
- assert(status == 0);
+ if (status != 0)
+ stm_fatalerror("newthread: pthread_create failure\n");
pthread_detach(th);
printf("started new thread\n");
}
diff --git a/c4/et.c b/c4/et.c
--- a/c4/et.c
+++ b/c4/et.c
@@ -305,6 +305,7 @@
static void _check_flags(gcptr P)
{
+#ifndef NDEBUG
struct tx_descriptor *d = thread_descriptor;
if (P->h_tid & GCFLAG_STUB)
{
@@ -322,6 +323,7 @@
assert(is_old);
dprintf(("O "));
}
+#endif
}
gcptr _stm_nonrecord_barrier(gcptr P)
@@ -962,7 +964,6 @@
static void CancelLocks(struct tx_descriptor *d)
{
- revision_t my_lock = d->my_lock;
wlog_t *item;
if (!g2l_any_entry(&d->public_to_private))
@@ -984,7 +985,7 @@
if (v == expected)
{
- assert(R->h_revision != my_lock);
+ assert(R->h_revision != d->my_lock);
break; /* done */
}
@@ -993,7 +994,7 @@
#ifdef DUMP_EXTRA
dprintf(("%p->h_revision = %p (CancelLocks)\n", R, (gcptr)v));
#endif
- assert(R->h_revision == my_lock);
+ assert(R->h_revision == d->my_lock);
ACCESS_ONCE(R->h_revision) = v;
} G2L_LOOP_END;
diff --git a/c4/gcpage.c b/c4/gcpage.c
--- a/c4/gcpage.c
+++ b/c4/gcpage.c
@@ -39,13 +39,17 @@
void stmgcpage_acquire_global_lock(void)
{
int err = pthread_mutex_lock(&mutex_gc_lock);
- assert(err == 0);
+ if (err != 0)
+ stm_fatalerror("stmgcpage_acquire_global_lock: "
+ "pthread_mutex_lock() failure\n");
}
void stmgcpage_release_global_lock(void)
{
int err = pthread_mutex_unlock(&mutex_gc_lock);
- assert(err == 0);
+ if (err != 0)
+ stm_fatalerror("stmgcpage_release_global_lock: "
+ "pthread_mutex_unlock() failure\n");
}
@@ -158,7 +162,9 @@
}
}
+#ifndef NDEBUG
static unsigned char random_char = 0x55;
+#endif
void stmgcpage_free(gcptr obj)
{
diff --git a/c4/stmsync.c b/c4/stmsync.c
--- a/c4/stmsync.c
+++ b/c4/stmsync.c
@@ -57,7 +57,8 @@
void stm_initialize(void)
{
int r = DescriptorInit();
- assert(r == 1);
+ if (r != 1)
+ stm_fatalerror("stm_initialize: DescriptorInit failure\n");
stmgc_init_nursery();
init_shadowstack();
//stmgcpage_init_tls();
@@ -227,7 +228,9 @@
void stm_start_sharedlock(void)
{
int err = pthread_rwlock_rdlock(&rwlock_shared);
- assert(err == 0);
+ if (err != 0)
+ stm_fatalerror("stm_start_sharedlock: "
+ "pthread_rwlock_rdlock failure\n");
//assert(stmgc_nursery_hiding(thread_descriptor, 0));
dprintf(("stm_start_sharedlock\n"));
}
@@ -237,13 +240,17 @@
dprintf(("stm_stop_sharedlock\n"));
//assert(stmgc_nursery_hiding(thread_descriptor, 1));
int err = pthread_rwlock_unlock(&rwlock_shared);
- assert(err == 0);
+ if (err != 0)
+ stm_fatalerror("stm_stop_sharedlock: "
+ "pthread_rwlock_unlock failure\n");
}
static void start_exclusivelock(void)
{
int err = pthread_rwlock_wrlock(&rwlock_shared);
- assert(err == 0);
+ if (err != 0)
+ stm_fatalerror("start_exclusivelock: "
+ "pthread_rwlock_wrlock failure\n");
dprintf(("start_exclusivelock\n"));
}
@@ -251,7 +258,9 @@
{
dprintf(("stop_exclusivelock\n"));
int err = pthread_rwlock_unlock(&rwlock_shared);
- assert(err == 0);
+ if (err != 0)
+ stm_fatalerror("stop_exclusivelock: "
+ "pthread_rwlock_unlock failure\n");
}
void stm_start_single_thread(void)
@@ -289,9 +298,8 @@
/* Warning, may block waiting for rwlock_in_transaction while another
thread runs a major GC */
- struct tx_descriptor *d = thread_descriptor;
- assert(d->active);
- assert(in_single_thread != d);
+ assert(thread_descriptor->active);
+ assert(in_single_thread != thread_descriptor);
stm_stop_sharedlock();
/* another thread should be waiting in start_exclusivelock(),
More information about the pypy-commit
mailing list