* Merged twisti branch to default. This merge introduces C++ wrapper
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Thu, 7 Aug 2008 21:43:02 +0000 (17:43 -0400)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Thu, 7 Aug 2008 21:43:02 +0000 (17:43 -0400)
classes for Java object access.

1  2 
configure.ac
src/threads/posix/thread-posix.cpp

diff --combined configure.ac
index 8a529e3be3686a450be11584d6a61a1cd932ee54,e50b39d1230f3c0c956084eaa74a946b8674d83f..3853a5853b4d12ec92d784c5e5b42ba6ae155242
@@@ -37,13 -37,13 +37,13 @@@ AC_PREFIX_DEFAULT(/usr/local/cacao
  
  dnl Set optimization and debugging for all architectures and systems.
  if test x"$CFLAGS" = "x"; then
 -    OPT_CFLAGS="-O0 -g"
 +    OPT_CFLAGS="-g -O0"
  else
      OPT_CFLAGS=$CFLAGS
  fi
  
  if test x"$CXXFLAGS" = "x"; then
 -    OPT_CXXFLAGS="-O0 -g"
 +    OPT_CXXFLAGS="-g -O0"
  else
      OPT_CXXFLAGS=$CXXFLAGS
  fi
@@@ -56,7 -56,7 +56,7 @@@ alpha | alphaev56 | alphapca56 
      JAVA_ARCH="alpha"
      ;;
  
 -arm | armv4 | armv4tl | armv5b | armv5l | armv5tejl )
 +arm | armv4 | armv4tl | armv5b | armv5l | armv5tel | armv5tejl )
      ARCH_DIR="arm"
      ARCH_FLAGS="-D__ARM__"
      JAVA_ARCH="arm"
@@@ -70,7 -70,7 +70,7 @@@ hppa2.0 
  
  i386 | i486 | i586 | i686 )
      ARCH_DIR="i386"
 -    ARCH_FLAGS="-D__I386__"
 +    ARCH_FLAGS="-m32 -D__I386__"
      JAVA_ARCH="i386"
      ;;
  
@@@ -89,13 -89,13 +89,13 @@@ mips | mipsel 
  
  powerpc )
      ARCH_DIR="powerpc"
 -    ARCH_FLAGS="-D__POWERPC__"
 +    ARCH_FLAGS="-m32 -D__POWERPC__"
      JAVA_ARCH="ppc"
      ;;
  
  powerpc64 )
      ARCH_DIR="powerpc64"
 -    ARCH_FLAGS="-D__POWERPC64__"
 +    ARCH_FLAGS="-m64 -D__POWERPC64__"
      JAVA_ARCH="ppc64"
      ;;
  
@@@ -549,7 -549,6 +549,6 @@@ AC_DEFINE_UNQUOTED([CACAO_VM_ZIP], "${C
  AC_SUBST(CACAO_VM_ZIP)
  
  
- AC_CHECK_WITH_CACAOH
  AC_CHECK_WITH_JAVA_RUNTIME_LIBRARY
  
  dnl Now we check for jre-layout so we can skip some checks that are
@@@ -653,7 -652,6 +652,6 @@@ AC_CONFIG_FILES([Makefile
                [man/Makefile]
                [src/Makefile]
                [src/cacao/Makefile]
-               [src/cacaoh/Makefile]
                [src/classes/Makefile]
                [src/fdlibm/Makefile]
                [src/mm/Makefile]
index cd1b19a26f7e752139cc075e556258c9376823ff,2e0ac45b590658415a9649d8b69149c60831755d..6db5dfdab5e7d79f6b3ade281e7675469e8ce54c
  #include "native/llni.h"
  #include "native/native.h"
  
- #include "native/include/java_lang_Object.h"
- #include "native/include/java_lang_String.h"
- #include "native/include/java_lang_Throwable.h"
- #include "native/include/java_lang_Thread.h"
- #if defined(ENABLE_JAVASE)
- # include "native/include/java_lang_ThreadGroup.h"
- #endif
- #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
- # include "native/include/java_lang_VMThread.h"
- #endif
  #include "threads/condition.hpp"
  #include "threads/lock-common.h"
  #include "threads/mutex.hpp"
@@@ -84,6 -71,7 +71,7 @@@
  #include "vm/jit/asmpart.h"
  
  #include "vmcore/globals.hpp"
+ #include "vmcore/javaobjects.hpp"
  #include "vmcore/options.h"
  
  #if defined(ENABLE_STATISTICS)
@@@ -121,10 -109,10 +109,10 @@@ extern "C" 
     from Boehm-GC. */
  
  /*
 -   This is a very simple semaphore implementation for darwin. It
 +   This is a very simple semaphore implementation for Darwin. It
     is implemented in terms of pthreads calls so it isn't async signal
     safe. This isn't a problem because signals aren't used to
 -   suspend threads on darwin.
 +   suspend threads on Darwin.
  */
     
  static int sem_init(sem_t *sem, int pshared, int value)
        if (pshared)
                assert(0);
  
 -      sem->value = value;
 -    
        sem->mutex = new Mutex();
 -
 -      if (pthread_cond_init(&sem->cond, NULL) < 0)
 -              return -1;
 +      sem->cond  = new Condition();
 +      sem->value = value;
  
        return 0;
  }
  static int sem_post(sem_t *sem)
  {
        sem->mutex->lock();
 -
        sem->value++;
 -
 -      if (pthread_cond_signal(&sem->cond) < 0) {
 -              sem->mutex->unlock();
 -              return -1;
 -      }
 -
 +      sem->cond->signal();
        sem->mutex->unlock();
  
        return 0;
@@@ -154,10 -151,12 +142,10 @@@ static int sem_wait(sem_t *sem
        sem->mutex->lock();
  
        while (sem->value == 0) {
 -#error We cannot call pthread_cond_wait on a Mutex-class pointer.
 -              pthread_cond_wait(&sem->cond, &sem->mutex);
 +              sem->cond->wait(sem->mutex);
        }
  
        sem->value--;
 -
        sem->mutex->unlock();
  
        return 0;
  
  static int sem_destroy(sem_t *sem)
  {
 -      if (pthread_cond_destroy(&sem->cond) < 0)
 -              return -1;
 -
 +      delete sem->cond;
        delete sem->mutex;
  
        return 0;
@@@ -743,17 -744,12 +731,12 @@@ void threads_impl_init(void
  
  static void *threads_startup_thread(void *arg)
  {
-       startupinfo        *startup;
-       threadobject       *t;
-       java_lang_Thread   *object;
- #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
-       java_lang_VMThread *vmt;
- #endif
-       sem_t              *psem;
-       classinfo          *c;
-       methodinfo         *m;
-       java_handle_t      *o;
-       functionptr         function;
+       startupinfo  *startup;
+       threadobject *t;
+       sem_t        *psem;
+       classinfo    *c;
+       methodinfo   *m;
+       functionptr   function;
  
  #if defined(ENABLE_GC_BOEHM)
  # if !defined(__DARWIN__)
  # endif
  #endif
  
-       /* get the java.lang.Thread object for this thread */
-       object = (java_lang_Thread *) thread_get_object(t);
+       // Get the java.lang.Thread object for this thread.
+       java_handle_t* object = thread_get_object(t);
+       java_lang_Thread jlt(object);
  
        /* set our priority */
  
-       threads_set_thread_priority(t->tid, LLNI_field_direct(object, priority));
+       threads_set_thread_priority(t->tid, jlt.get_priority());
  
        /* Thread is completely initialized. */
  
  #warning Move to C++
  
  #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
-               /* we need to start the run method of java.lang.VMThread */
  
-               LLNI_field_get_ref(object, vmThread, vmt);
-               o = (java_handle_t *) vmt;
+               // We need to start the run method of java.lang.VMThread.
+               java_lang_VMThread jlvmt(jlt.get_vmThread());
+               java_handle_t* h = jlvmt.get_handle();
  
  #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) || defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
-               o = (java_handle_t *) object;
+               java_handle_t* h = jlt.get_handle();
  #else
  # error unknown classpath configuration
  #endif
  
                /* Run the thread. */
  
-               (void) vm_call_method(m, o);
+               (void) vm_call_method(m, h);
        }
        else {
                /* set ThreadMXBean variables */
@@@ -1043,19 -1041,7 +1028,7 @@@ void threads_set_thread_priority(pthrea
   */
  bool thread_detach_current_thread(void)
  {
-       threadobject          *t;
-       bool                   result;
-       java_lang_Thread      *object;
-       java_handle_t         *o;
- #if defined(ENABLE_JAVASE)
-       java_lang_ThreadGroup *group;
-       java_handle_t         *e;
-       void                  *handler;
-       classinfo             *c;
-       methodinfo            *m;
- #endif
-       t = thread_get_current();
+       threadobject* t = thread_get_current();
  
        /* Sanity check. */
  
      /* If the given thread has already been detached, this operation
           is a no-op. */
  
-       result = thread_is_attached(t);
-       if (result == false)
+       if (thread_is_attached(t) == false)
                return true;
  
        DEBUGTHREADS("detaching", t);
  
-       object = (java_lang_Thread *) thread_get_object(t);
+       java_handle_t* object = thread_get_object(t);
+       java_lang_Thread jlt(object);
  
  #if defined(ENABLE_JAVASE)
-       LLNI_field_get_ref(object, group, group);
+       java_handle_t* group = jlt.get_group();
  
      /* If there's an uncaught exception, call uncaughtException on the
         thread's exception handler, or the thread's group if this is
         unset. */
  
-       e = exceptions_get_and_clear_exception();
+       java_handle_t* e = exceptions_get_and_clear_exception();
  
      if (e != NULL) {
                /* We use the type void* for handler here, as it's not trivial
                   header file with cacaoh. */
  
  # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
-               LLNI_field_get_ref(object, exceptionHandler, handler);
+               java_handle_t* handler = jlt.get_exceptionHandler();
  # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
-               LLNI_field_get_ref(object, uncaughtExceptionHandler, handler);
+               java_handle_t* handler = jlt.get_uncaughtExceptionHandler();
  # endif
  
+               classinfo*     c;
+               java_handle_t* h;
                if (handler != NULL) {
                        LLNI_class_get(handler, c);
-                       o = (java_handle_t *) handler;
+                       h = (java_handle_t *) handler;
                }
                else {
                        LLNI_class_get(group, c);
-                       o = (java_handle_t *) group;
+                       h = (java_handle_t *) group;
                }
  
-               m = class_resolveclassmethod(c,
-                                                                        utf_uncaughtException,
-                                                                        utf_java_lang_Thread_java_lang_Throwable__V,
-                                                                        NULL,
-                                                                        true);
+               methodinfo* m = class_resolveclassmethod(c,
+                                                                                                utf_uncaughtException,
+                                                                                                utf_java_lang_Thread_java_lang_Throwable__V,
+                                                                                                NULL,
+                                                                                                true);
  
                if (m == NULL)
                        return false;
  
-               (void) vm_call_method(m, o, object, e);
+               (void) vm_call_method(m, h, object, e);
  
                if (exceptions_get_exception())
                        return false;
        /* Remove thread from the thread group. */
  
        if (group != NULL) {
+               classinfo* c;
                LLNI_class_get(group, c);
  
  # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
-               m = class_resolveclassmethod(c,
-                                                                        utf_removeThread,
-                                                                        utf_java_lang_Thread__V,
-                                                                        class_java_lang_ThreadGroup,
-                                                                        true);
+               methodinfo* m = class_resolveclassmethod(c,
+                                                                                                utf_removeThread,
+                                                                                                utf_java_lang_Thread__V,
+                                                                                                class_java_lang_ThreadGroup,
+                                                                                                true);
  # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
-               m = class_resolveclassmethod(c,
-                                                                        utf_remove,
-                                                                        utf_java_lang_Thread__V,
-                                                                        class_java_lang_ThreadGroup,
-                                                                        true);
+               methodinfo* m = class_resolveclassmethod(c,
+                                                                                                utf_remove,
+                                                                                                utf_java_lang_Thread__V,
+                                                                                                class_java_lang_ThreadGroup,
+                                                                                                true);
  # else
  #  error unknown classpath configuration
  # endif
                if (m == NULL)
                        return false;
  
-               o = (java_handle_t *) group;
-               (void) vm_call_method(m, o, object);
+               (void) vm_call_method(m, group, object);
  
                if (exceptions_get_exception())
                        return false;
  
-               /* Reset the threadgroup in the Java thread object (Mauve
-                  test: gnu/testlet/java/lang/Thread/getThreadGroup). */
-               LLNI_field_set_ref(object, group, NULL);
+               // Clear the ThreadGroup in the Java thread object (Mauve
+               // test: gnu/testlet/java/lang/Thread/getThreadGroup).
+               jlt.set_group(NULL);
        }
  #endif
  
        /* Notify all threads waiting on this thread.  These are joining
           this thread. */
  
-       o = (java_handle_t *) object;
        /* XXX Care about exceptions? */
-       (void) lock_monitor_enter(o);
+       (void) lock_monitor_enter(jlt.get_handle());
        
-       lock_notify_all_object(o);
+       lock_notify_all_object(jlt.get_handle());
  
        /* XXX Care about exceptions? */
-       (void) lock_monitor_exit(o);
+       (void) lock_monitor_exit(jlt.get_handle());
  
        /* Enter the join-mutex before calling thread_free, so
           threads_join_all_threads gets the correct number of non-daemon
@@@ -1543,7 -1531,7 +1518,7 @@@ void threads_thread_interrupt(threadobj
  
        /* Interrupt blocking system call using a signal. */
  
 -      pthread_kill(t->tid, Signal_THREAD_INTERRUPT);
 +      pthread_kill(t->tid, Signal_INTERRUPT_SYSTEM_CALL);
  
        t->waitcond->signal();