Merge from subtype.
[cacao.git] / src / vm / jit / optimizing / profile.c
index b820cd9d869e798a061c053a608b20f0ac64bdd6..e397be6021bf31dc2313016d4226fadc7191a265 100644 (file)
 
 #include "mm/memory.h"
 
-#include "threads/threadlist.h"
-#include "threads/threads-common.h"
+#include "threads/threadlist.hpp"
+#include "threads/thread.hpp"
 
-#include "vm/builtin.h"
-#include "vm/stringlocal.h"
+#include "vm/jit/builtin.hpp"
+#include "vm/class.hpp"
+#include "vm/classcache.hpp"
+#include "vm/method.hpp"
+#include "vm/options.h"
+#include "vm/string.hpp"
 
-#include "vm/jit/jit.h"
+#include "vm/jit/jit.hpp"
 #include "vm/jit/methodheader.h"
-#include "vm/jit/optimizing/recompile.h"
+#include "vm/jit/methodtree.h"
 
-#include "vmcore/class.h"
-#include "vmcore/classcache.h"
-#include "vmcore/method.h"
-#include "vmcore/options.h"
+#include "vm/jit/optimizing/recompiler.hpp"
 
 
 /* profile_init ****************************************************************
@@ -91,13 +92,12 @@ static void profile_thread(void)
                threads_sleep(0, nanos);
                runs++;
 
-               /* lock the threads lists */
-
-               threadlist_lock();
+               // Lock the thread lists.
+               ThreadList_lock();
 
                /* iterate over all started threads */
 
-               for (t = threadlist_first(); t != NULL; t = threadlist_next(t)) {
+               for (t = ThreadList_first(); t != NULL; t = ThreadList_next(t)) {
                        /* is this a Java thread? */
 
                        if (!(t->flags & THREAD_FLAG_JAVA))
@@ -112,9 +112,9 @@ static void profile_thread(void)
 
                        pc = t->pc;
 
-                       /* get the PV for the current PC */
+                       /* Get the PV for the current PC. */
 
-                       pv = codegen_get_pv_from_pc_nocheck(pc);
+                       pv = methodtree_find_nocheck(pc);
 
                        /* get methodinfo pointer from data segment */
 
@@ -147,16 +147,15 @@ static void profile_thread(void)
                                                        /* add this method to the method list and
                                                           start recompilation */
 
-                                                       recompile_queue_method(m);
+                                                       Recompiler_queue_method(m);
                                                }
                                        }
                                }
                        }
                }
 
-               /* unlock the threads lists */
-
-               threadlist_unlock();
+               // Unlock the thread lists.
+               ThreadList_unlock();
        }
 }
 #endif
@@ -194,9 +193,6 @@ bool profile_start_thread(void)
 #if !defined(NDEBUG)
 void profile_printstats(void)
 {
-       list_t                 *l;
-       list_method_entry      *lme;
-       list_method_entry      *tlme;
        classinfo              *c;
        methodinfo             *m;
        codeinfo               *code;
@@ -212,8 +208,8 @@ void profile_printstats(void)
        cycles    = 0;
 
        /* create new method list */
-
-       l = list_create(OFFSET(list_method_entry, linkage));
+       // TODO Use a sorted container.
+       List* l = List_new();
 
        /* iterate through all classes and methods */
 
@@ -244,15 +240,10 @@ void profile_printstats(void)
                                                frequency += code->frequency;
                                                cycles    += code->cycles;
 
-                                               /* create new list entry */
-
-                                               lme = NEW(list_method_entry);
-                                               lme->m = m;
-
                                                /* sort the new entry into the list */
                                                
-                                               if ((tlme = list_first(l)) == NULL) {
-                                                       list_add_first(l, lme);
+                                               if (List_empty(l) == NULL) {
+                                                       List_push_back(l, m);
                                                }
                                                else {
                                                        for (; tlme != NULL; tlme = list_next(l, tlme)) {