OSDN Git Service

2002-03-26 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libjava / jni.cc
index dbe1d1f..1abd2d2 100644 (file)
@@ -1,6 +1,6 @@
 // jni.cc - JNI implementation, including the jump table.
 
-/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -13,9 +13,6 @@ details.  */
 #include <stddef.h>
 #include <string.h>
 
-// Define this before including jni.h.
-#define __GCJ_JNI_IMPL__
-
 #include <gcj/cni.h>
 #include <jvm.h>
 #include <java-assert.h>
@@ -29,7 +26,7 @@ details.  */
 #include <java/lang/Throwable.h>
 #include <java/lang/ArrayIndexOutOfBoundsException.h>
 #include <java/lang/StringIndexOutOfBoundsException.h>
-#include <java/lang/AbstractMethodError.h>
+#include <java/lang/UnsatisfiedLinkError.h>
 #include <java/lang/InstantiationException.h>
 #include <java/lang/NoSuchFieldError.h>
 #include <java/lang/NoSuchMethodError.h>
@@ -41,7 +38,6 @@ details.  */
 #include <java/lang/Integer.h>
 #include <java/lang/ThreadGroup.h>
 #include <java/lang/Thread.h>
-#include <gnu/gcj/runtime/JNIWeakRef.h>
 
 #include <gcj/method.h>
 #include <gcj/field.h>
@@ -329,7 +325,7 @@ _Jv_JNI_NewLocalRef (JNIEnv *env, jobject obj)
 
       // If we found a slot, or if the frame we just searched is the
       // mark frame, then we are done.
-      if (done || frame->marker != MARK_NONE)
+      if (done || frame == NULL || frame->marker != MARK_NONE)
        break;
     }
 
@@ -2018,7 +2014,7 @@ _Jv_LookupJNIMethod (jclass klass, _Jv_Utf8Const *name,
       if (function == NULL)
        {
          jstring str = JvNewStringUTF (name->data);
-         throw new java::lang::AbstractMethodError (str);
+         throw new java::lang::UnsatisfiedLinkError (str);
        }
     }
 
@@ -2066,6 +2062,17 @@ _Jv_JNIMethod::call (ffi_cif *, void *ret, ffi_raw *args, void *__this)
   if ((_this->self->accflags & java::lang::reflect::Modifier::STATIC))
     real_args[offset++].ptr = _this->defining_class;
 
+  // In libgcj, the callee synchronizes.
+  jobject sync = NULL;
+  if ((_this->self->accflags & java::lang::reflect::Modifier::SYNCHRONIZED))
+    {
+      if ((_this->self->accflags & java::lang::reflect::Modifier::STATIC))
+       sync = _this->defining_class;
+      else
+       sync = (jobject) args[0].ptr;
+      _Jv_MonitorEnter (sync);
+    }
+
   // Copy over passed-in arguments.
   memcpy (&real_args[offset], args, _this->args_raw_size);
 
@@ -2073,6 +2080,9 @@ _Jv_JNIMethod::call (ffi_cif *, void *ret, ffi_raw *args, void *__this)
   ffi_raw_call (&_this->jni_cif, (void (*)()) _this->function,
                ret, real_args);
 
+  if (sync != NULL)
+    _Jv_MonitorExit (sync);
+
   _Jv_JNI_PopSystemFrame (env);
 }
 
@@ -2121,6 +2131,14 @@ _Jv_JNI_AttachCurrentThread (JavaVM *, jstring name, void **penv, void *args)
       _Jv_Free (env);
       return JNI_ERR;
     }
+
+  env->locals->marker = MARK_SYSTEM;
+  env->locals->size = FRAME_SIZE;
+  env->locals->next = NULL;
+
+  for (int i = 0; i < env->locals->size; ++i)
+    env->locals->vec[i] = NULL;
+
   *penv = reinterpret_cast<void *> (env);
 
   // This thread might already be a Java thread -- this function might