AM_CONDITIONAL([ENABLE_SSA], test x"${ENABLE_SSA}" = "xyes")
AM_CONDITIONAL([ENABLE_ESCAPE], test x"${ENABLE_SSA}" = "xyes")
AM_CONDITIONAL([ENABLE_ESCAPE_CHECK], test x"${ENABLE_SSA}" = "xyes")
+AM_CONDITIONAL([ENABLE_TLH], test x"${ENABLE_SSA}" = "xyes")
if test x"${ENABLE_SSA}" = "xyes"; then
AC_DEFINE([ENABLE_SSA], 1, [enable lsra with ssa])
libmm_la_LIBADD = \
$(GC_LIB)
+if ENABLE_TLH
+libmm_la_SOURCES += \
+ tlh.h \
+ tlh.c
+endif
## Local variables:
## mode: Makefile
--- /dev/null
+/* src/mm/tlh.c
+
+ Copyright (C) 2008
+ CACAOVM - Verein zu Foerderung der freien virtuellen Machine CACAO
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+*/
+
+#include "config.h"
+
+#include "mm/tlh.h"
+#include "vm/global.h"
+
+#include <assert.h>
+#include <sys/mman.h>
+
+static const int TLH_MAX_SIZE = (20 * 1024 * 1024);
+
+static inline bool tlh_avail(tlh_t *tlh, unsigned n) {
+ /*
+ --- --- --- ---
+ ^ end
+ ^ top
+ ^ top + 2
+ */
+ return (tlh->top + n) <= tlh->end;
+}
+
+void tlh_init(tlh_t *tlh) {
+
+ void *heap = mmap(
+ NULL,
+ TLH_MAX_SIZE,
+ PROT_READ|PROT_WRITE,
+ MAP_ANONYMOUS|MAP_PRIVATE,
+ -1,
+ 0
+ );
+
+ if (heap == MAP_FAILED) {
+ /* The top pointer points to end, so all allocations will fail. */
+ tlh->start = NULL;
+ tlh->end = NULL;
+ tlh->top = NULL;
+ tlh->base = NULL;
+ } else {
+ tlh->start = (uint8_t *)heap;
+ tlh->top = tlh->start;
+ tlh->base = tlh->start;
+ tlh->end = tlh->start + TLH_MAX_SIZE;
+ }
+
+ tlh->overflows = 0;
+}
+
+void tlh_destroy(tlh_t *tlh) {
+ int res = munmap(tlh->start, TLH_MAX_SIZE);
+ if (res == -1) {
+ /* TODO */
+ assert(0);
+ }
+ tlh->start = NULL;
+ tlh->end = NULL;
+ tlh->top = NULL;
+ tlh->base = NULL;
+}
+
+void tlh_add_frame(tlh_t *tlh) {
+ if (tlh_avail(tlh, SIZEOF_VOID_P)) {
+ *(uint8_t **)tlh->top = tlh->base;
+ tlh->base = tlh->top;
+ tlh->top += SIZEOF_VOID_P;
+ } else {
+ tlh->overflows += 1;
+ }
+}
+
+void tlh_remove_frame(tlh_t *tlh) {
+ if (tlh->overflows > 0) {
+ tlh->overflows -= 1;
+ } else {
+ tlh->top = tlh->base;
+ tlh->base = *(uint8_t **)tlh->top;
+ }
+}
+
+void *tlh_alloc(tlh_t *tlh, size_t size) {
+ void *ret;
+ if (tlh_avail(tlh, size)) {
+ ret = tlh->top;
+ tlh->top += size;
+ } else {
+ ret = NULL;
+ }
+ return ret;
+}
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
--- /dev/null
+/* src/mm/tlh.h
+
+ Copyright (C) 2008
+ CACAOVM - Verein zu Foerderung der freien virtuellen Machine CACAO
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+*/
+
+#include <stddef.h>
+#include <stdint.h>
+
+typedef struct {
+ uint8_t *start;
+ uint8_t *end;
+ uint8_t *top;
+ uint8_t *base;
+ unsigned overflows;
+} tlh_t;
+
+void tlh_init(tlh_t *tlh);
+
+void tlh_destroy(tlh_t *tlh);
+
+void tlh_add_frame(tlh_t *tlh);
+
+void tlh_remove_frame(tlh_t *tlh);
+
+void *tlh_alloc(tlh_t *tlh, size_t size);
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
vm_abort_errnum(result, "threads_impl_thread_new: pthread_cond_init failed");
#if defined(ENABLE_TLH)
- tlh_init(t);
+ tlh_init(&(t->tlh));
#endif
}
t->flc_object = NULL;
#if defined(ENABLE_TLH)
- tlh_reset(t);
+ tlh_destroy(&(t->tlh));
+ tlh_init(&(t->tlh));
#endif
}
#include "mm/memory.h"
+#if defined(ENABLE_TLH)
+#include "mm/tlh.h"
+#endif
+
#include "native/localref.h"
#include "threads/mutex.h"
#endif
+
/* current threadobject *******************************************************/
#if defined(HAVE___THREAD)
#endif
#if defined(ENABLE_TLH)
- uint8_t *tlhstart;
- uint8_t *tlhtop;
- uint8_t *tlhbase;
+ tlh_t tlh;
#endif
listnode_t linkage; /* threads-list */
-/* srcontainsc/vm/optimizing/escape.c
+/* src/vm/optimizing/escape.c
Copyright (C) 2008
CACAOVM - Verein zu Foerderung der freien virtuellen Machine CACAO
break;
case ICMD_ARRAYLENGTH:
- /* TODO */
+ escape_analysis_ensure_state(e, instruction_s1(iptr), ESCAPE_METHOD);
break;
case ICMD_AALOAD:
return 0;
}
-#if 0
-
-/*** HACK to store method monomorphy information upon shutdown ****************/
-
-#include <sqlite3.h>
-
-bool method_profile_is_monomorphic(methodinfo *m) {
- static sqlite3 *db = NULL;
- static sqlite3_stmt *stmt = NULL;
- int ret;
-
- if (db == NULL) {
- assert(sqlite3_open("/home/peter/cacao-dev/profile.sqlite", &db) == SQLITE_OK);
- assert(sqlite3_prepare(db, "SELECT count(*) FROM monomorphic where class=? and method=? and descriptor=?", -1, &stmt, 0) == SQLITE_OK);
- }
-
- assert(sqlite3_bind_text(stmt, 1, m->clazz->name->text, -1, SQLITE_STATIC) == SQLITE_OK);
- assert(sqlite3_bind_text(stmt, 2, m->name->text, -1, SQLITE_STATIC) == SQLITE_OK);
- assert(sqlite3_bind_text(stmt, 3, m->descriptor->text, -1, SQLITE_STATIC) == SQLITE_OK);
-
- assert(sqlite3_step(stmt) == SQLITE_ROW);
- ret = sqlite3_column_int(stmt, 0);
- assert(sqlite3_reset(stmt) == SQLITE_OK);
-
- return ret;
-}
-void func(classinfo *c, void *arg) {
- methodinfo *it;
- sqlite3_stmt *stmt = (sqlite3_stmt *)arg;
- s4 flags;
- for (it = c->methods; it != c->methods + c->methodscount; ++it) {
- flags = it->flags;
- if (flags & (ACC_STATIC | ACC_FINAL | ACC_PRIVATE)) {
- continue;
- }
- if ((flags & (ACC_METHOD_MONOMORPHIC | ACC_METHOD_IMPLEMENTED | ACC_ABSTRACT)) ==
- (ACC_METHOD_MONOMORPHIC | ACC_METHOD_IMPLEMENTED)) {
- assert(sqlite3_bind_text(stmt, 1, c->name->text, -1, SQLITE_STATIC) == SQLITE_OK);
- assert(sqlite3_bind_text(stmt, 2, it->name->text, -1, SQLITE_STATIC) == SQLITE_OK);
- assert(sqlite3_bind_text(stmt, 3, it->descriptor->text, -1, SQLITE_STATIC) == SQLITE_OK);
-
- assert(sqlite3_step(stmt) == SQLITE_DONE);
- assert(sqlite3_reset(stmt) == SQLITE_OK);
- }
- }
-}
-
-
-void method_profile_store() {
- sqlite3 *db = NULL;
- sqlite3_stmt *stmt;
- assert(sqlite3_open("/home/peter/cacao-dev/profile.sqlite", &db) == SQLITE_OK);
- assert(sqlite3_exec(db, "DELETE FROM monomorphic", NULL, NULL, NULL) == SQLITE_OK);
- assert(sqlite3_prepare(db, "INSERT INTO monomorphic (class, method, descriptor) VALUES (?,?,?)", -1, &stmt, 0) == SQLITE_OK);
- classcache_foreach_loaded_class(func, stmt);
- assert(sqlite3_finalize(stmt) == SQLITE_OK);
- assert(sqlite3_close(db) == SQLITE_OK);
-}
-
-void iterate_classes() {
- return;
- method_profile_store();
-
-}
-
-#endif
-
-#if defined(ENABLE_TLH)
-/*** TLH (Thread local heap) hack ********************************************/
-
-#include <sys/mman.h>
-#include "threads/thread.h"
-
-#define TLH_MAX_SIZE (20 * 1024 * 1024)
-
-void tlh_init(threadobject *t) {
- uint8_t *heap = (uint8_t *)mmap(
- NULL,
- TLH_MAX_SIZE,
- PROT_READ|PROT_WRITE,
- MAP_ANONYMOUS|MAP_PRIVATE,
- -1,
- 0
- );
- uint8_t *red = (uint8_t *)mmap(
- heap + TLH_MAX_SIZE - getpagesize(),
- getpagesize(),
- PROT_NONE,
- MAP_ANONYMOUS|MAP_PRIVATE|MAP_FIXED,
- -1,
- 0
- );
- assert(heap);
- assert(red);
- t->tlhstart = heap;
- t->tlhtop = heap;
- t->tlhbase = heap;
-}
-
-void tlh_reset(threadobject *t) {
- t->tlhtop = t->tlhstart;
- t->tlhbase = t->tlhstart;
-}
-
-void tlh_destroy(threadobject *t) {
- int res = munmap(t->tlhstart, TLH_MAX_SIZE - getpagesize());
- int res2 = munmap(t->tlhstart + TLH_MAX_SIZE - getpagesize(), getpagesize());
- assert(res);
- assert(res2);
-}
-
-bool tlh_sigsegv_handler(void *addr) {
-}
-
-#endif