* configure.ac: Define automake conditinal ENABLE_TLH if SSA enabled.
authorPeter Molnar <pm@complang.tuwien.ac.at>
Fri, 4 Jul 2008 11:12:33 +0000 (13:12 +0200)
committerPeter Molnar <pm@complang.tuwien.ac.at>
Fri, 4 Jul 2008 11:12:33 +0000 (13:12 +0200)
* src/mm/Makefile.am [ENABLE_TLH]: Build tlh.c
* src/mm/tlh.c,
src/mm/tlh.h: New files: thread local heap implementation.
* src/threads/posix/thread-posix.c,
src/threads/posix/thread-posix.h (threadobject_t) [ENABLE_TLH]: added a tlh_t memeber, (threads_impl_thread_init) [ENABLE_TLH]: calling tlh_init, (threads_impl_thread_reuse) [ENABLE_TLH]: calling tlh_init and tlh_destroy.
* src/vm/jit/optimizing/escape.c: Removed now obsolete code.

configure.ac
src/mm/Makefile.am
src/mm/tlh.c [new file with mode: 0644]
src/mm/tlh.h [new file with mode: 0644]
src/threads/posix/thread-posix.c
src/threads/posix/thread-posix.h
src/vm/jit/optimizing/escape.c

index 441263b2b5410c52430c5ef97822f1f79a666a33..885af628968f933a0139f2f61114dad93099bf61 100644 (file)
@@ -668,6 +668,7 @@ AC_MSG_RESULT(${ENABLE_SSA})
 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])
index 22c39cec2ed77c989a22004cbf4b07976c250b7f..afd9feef0301c0ed095e05f36c7dec2f1c5c92ca 100644 (file)
@@ -69,6 +69,11 @@ libmm_la_SOURCES = \
 libmm_la_LIBADD = \
        $(GC_LIB)
 
+if ENABLE_TLH
+libmm_la_SOURCES += \
+       tlh.h \
+       tlh.c
+endif
 
 ## Local variables:
 ## mode: Makefile
diff --git a/src/mm/tlh.c b/src/mm/tlh.c
new file mode 100644 (file)
index 0000000..5db19b8
--- /dev/null
@@ -0,0 +1,125 @@
+/* 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:
+ */
diff --git a/src/mm/tlh.h b/src/mm/tlh.h
new file mode 100644 (file)
index 0000000..884d16e
--- /dev/null
@@ -0,0 +1,57 @@
+/* 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:
+ */
index b7d83c289f6efec76b9b92e990daafe6f33cd294..f5c6c3148ce89c85d70bf2effa5fa04ce745e661 100644 (file)
@@ -688,7 +688,7 @@ void threads_impl_thread_init(threadobject *t)
                vm_abort_errnum(result, "threads_impl_thread_new: pthread_cond_init failed");
 
 #if defined(ENABLE_TLH)
-       tlh_init(t);
+       tlh_init(&(t->tlh));
 #endif
 }
 
@@ -781,7 +781,8 @@ void threads_impl_thread_reuse(threadobject *t)
        t->flc_object = NULL;
 
 #if defined(ENABLE_TLH)
-       tlh_reset(t);
+       tlh_destroy(&(t->tlh));
+       tlh_init(&(t->tlh));
 #endif
 }
 
index 87df756dde8760b893f5e97567776c5a4582c867..069d0f5daa9b82eabc56b92bd536bd212c7f11da 100644 (file)
@@ -40,6 +40,10 @@ typedef struct threadobject threadobject;
 
 #include "mm/memory.h"
 
+#if defined(ENABLE_TLH)
+#include "mm/tlh.h"
+#endif
+
 #include "native/localref.h"
 
 #include "threads/mutex.h"
@@ -73,6 +77,7 @@ typedef struct {
 #endif
 
 
+
 /* current threadobject *******************************************************/
 
 #if defined(HAVE___THREAD)
@@ -172,9 +177,7 @@ struct threadobject {
 #endif
 
 #if defined(ENABLE_TLH)
-       uint8_t              *tlhstart;
-       uint8_t              *tlhtop;
-       uint8_t              *tlhbase;
+       tlh_t                 tlh;
 #endif
 
        listnode_t            linkage;      /* threads-list                       */
index 5cd77dce96a83cc91d5fe94c561a32115cca9ad9..e05bf5cbe8071f4afc82c0eb52439833096b6dee 100644 (file)
@@ -1,4 +1,4 @@
-/* srcontainsc/vm/optimizing/escape.c
+/* src/vm/optimizing/escape.c
 
    Copyright (C) 2008
    CACAOVM - Verein zu Foerderung der freien virtuellen Machine CACAO
@@ -690,7 +690,7 @@ static void escape_analysis_process_instruction(escape_analysis_t *e, instructio
                        break;
 
                case ICMD_ARRAYLENGTH:
-                       /* TODO */
+                       escape_analysis_ensure_state(e, instruction_s1(iptr), ESCAPE_METHOD);
                        break;
 
                case ICMD_AALOAD:
@@ -1109,118 +1109,3 @@ bool method_profile_is_monomorphic(methodinfo *m) {
 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