aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/lang
diff options
context:
space:
mode:
authorTom Tromey <tromey@cygnus.com>2000-03-02 20:25:20 +0000
committerTom Tromey <tromey@gcc.gnu.org>2000-03-02 20:25:20 +0000
commitb099f07de92d7b228ff662711b148addf4b2b115 (patch)
treedd49bb49b56ee51fa4bbd2a20cc08ae6eefa6306 /libjava/java/lang
parentc45da1ca925d67685ca633b48a4ca1ec44dfaca1 (diff)
downloadgcc-b099f07de92d7b228ff662711b148addf4b2b115.zip
gcc-b099f07de92d7b228ff662711b148addf4b2b115.tar.gz
gcc-b099f07de92d7b228ff662711b148addf4b2b115.tar.bz2
java-interp.h: Don't include MethodInvocation.h.
* include/java-interp.h: Don't include MethodInvocation.h. (class _Jv_InterpMethod): Don't make MethodInvocation a friend. * Makefile.in: Rebuilt. * Makefile.am (gnu/gcj/runtime/MethodInvocation.h): Removed. (ordinary_java_source_files): Don't mention MethodInvocation.java. * gnu/gcj/runtime/MethodInvocation.java: Removed. * interpret.cc (MethodInvocation::continue1): Removed. (run): Handle exceptions here. * java/lang/ClassLoader.java (defineClass1, defineClass2): Removed. * java/lang/natClassLoader.cc (defineClass0): Catch exceptions here. (defineClass2): Removed. * java/lang/reflect/Method.java (hack_trampoline, hack_call): Removed. * java/lang/reflect/natMethod.cc (_Jv_CallAnyMethodA): Catch exceptions here. (hack_call): Removed. * java/lang/Class.h (Class): Removed hackRunInitializers, hackTrampoline. * java/lang/natClass.cc (hackRunInitializers): Removed. (initializeClass): Catch exceptions here. Include ExceptionInInitializerError.h. * java/lang/Class.java (hackTrampoline, hackRunInitializers): Removed. * java/lang/Object.h (Object): Don't mention hack12_6. * java/lang/natObject.cc (_Jv_FinalizeObject): Catch exceptions here. * java/lang/Object.java (hack12_6): Removed. * java/lang/natThread.cc (run_): Renamed. Catch exceptions here. (start): Use run_, not run__. * java/lang/Thread.java (run_): Renamed from run__; old run_ removed. * jni.cc (_Jv_JNI_FindClass): Handle exceptions. (_Jv_JNI_EnsureLocalCapacity): Likewise. (_Jv_JNI_DefineClass): Likewise. (_Jv_JNI_ThrowNew): Likewise. (_Jv_JNI_AllocObject): Likewise. (_Jv_JNI_GetAnyMethodID): Likewise. (_Jv_JNI_CallAnyMethodV): Likewise. (_Jv_JNI_CallAnyMethodA): Likewise. (_Jv_JNI_CallAnyVoidMethodV): Likewise. (_Jv_JNI_CallAnyVoidMethodA): Likewise. (_Jv_JNI_GetAnyFieldID): Likewise. (_Jv_JNI_NewString): Likewise. (_Jv_JNI_NewStringUTF): Likewise. (_Jv_JNI_GetStringUTFChars): Likewise. (_Jv_JNI_NewObjectArray): Likewise. (_Jv_JNI_NewPrimitiveArray): Likewise. (_Jv_JNI_GetPrimitiveArrayRegion): Likewise. (_Jv_JNI_GetStringRegion): Likewise. (_Jv_JNI_GetStringUTFRegion): Likewise. (_Jv_JNI_SetPrimitiveArrayRegion): Likewise. (_Jv_JNI_MonitorEnter): Likewise. (_Jv_JNI_MonitorExit): Likewise. (_Jv_JNI_ToReflectedField): Likewise. (_Jv_JNI_ToReflectedMethod): Likewise. (_Jv_JNI_RegisterNatives): Likewise. (_Jv_JNI_AttachCurrentThread): Likewise. (_Jv_JNI_DestroyJavaVM): Likewise. From-SVN: r32294
Diffstat (limited to 'libjava/java/lang')
-rw-r--r--libjava/java/lang/Class.h3
-rw-r--r--libjava/java/lang/Class.java26
-rw-r--r--libjava/java/lang/ClassLoader.java24
-rw-r--r--libjava/java/lang/Object.h4
-rw-r--r--libjava/java/lang/Object.java17
-rw-r--r--libjava/java/lang/Thread.java26
-rw-r--r--libjava/java/lang/natClass.cc57
-rw-r--r--libjava/java/lang/natClassLoader.cc25
-rw-r--r--libjava/java/lang/natObject.cc12
-rw-r--r--libjava/java/lang/natThread.cc28
-rw-r--r--libjava/java/lang/reflect/Method.java26
-rw-r--r--libjava/java/lang/reflect/natMethod.cc39
12 files changed, 89 insertions, 198 deletions
diff --git a/libjava/java/lang/Class.h b/libjava/java/lang/Class.h
index 2ad6c5d..717eed7 100644
--- a/libjava/java/lang/Class.h
+++ b/libjava/java/lang/Class.h
@@ -157,9 +157,6 @@ public:
private:
void checkMemberAccess (jint flags);
- // Various functions to handle class initialization.
- java::lang::Throwable *hackTrampoline (jint, java::lang::Throwable *);
- void hackRunInitializers (void);
void initializeClass (void);
// Friend functions implemented in natClass.cc.
diff --git a/libjava/java/lang/Class.java b/libjava/java/lang/Class.java
index 1d73c89..b080624 100644
--- a/libjava/java/lang/Class.java
+++ b/libjava/java/lang/Class.java
@@ -172,32 +172,6 @@ public final class Class implements Serializable
sm.checkMemberAccess(this, flags);
}
- // FIXME: this method exists only because we cannot catch Java
- // exceptions from C++ code. This is a helper for initializeClass.
- private Throwable hackTrampoline (int what, Throwable old_exception)
- {
- Throwable new_val = null;
- try
- {
- if (what == 0)
- initializeClass ();
- else if (what == 1)
- hackRunInitializers ();
- else if (what == 2)
- new_val = new ExceptionInInitializerError (old_exception);
- }
- catch (Throwable t)
- {
- new_val = t;
- }
- return new_val;
- }
-
- // FIXME: this is a hack to let us run the class initializers. We
- // could do it inline in initializeClass() if we could catch Java
- // exceptions from C++.
- private native void hackRunInitializers ();
-
// Initialize the class.
private native void initializeClass ();
diff --git a/libjava/java/lang/ClassLoader.java b/libjava/java/lang/ClassLoader.java
index 776093e..fb3f37a 100644
--- a/libjava/java/lang/ClassLoader.java
+++ b/libjava/java/lang/ClassLoader.java
@@ -1,6 +1,6 @@
// ClassLoader.java - Define policies for loading Java classes.
-/* Copyright (C) 1998, 1999 Red Hat, Inc.
+/* Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
This file is part of libgcj.
@@ -234,28 +234,6 @@ public abstract class ClassLoader {
throws java.lang.ClassNotFoundException, java.lang.LinkageError;
- /** This is called by defineClass0, once the "raw" and uninitialized
- * class object has been created, and handles exceptions generated
- * while actually defining the class (_Jv_DefineClass). defineClass0
- * holds the lock on the new class object, so it needs to capture
- * these exceptions. */
-
- private static Throwable defineClass1 (Class klass, byte[] data,
- int offset, int length)
- {
- try {
- defineClass2 (klass, data, offset, length);
- } catch (Throwable x) {
- return x;
- }
- return null;
- }
-
- /** This is just a wrapper for _Jv_DefineClass */
- private static native void defineClass2 (Class klass, byte[] data,
- int offset, int length)
- throws Throwable;
-
/**
* Link the given class. This will bring the class to a state where
* the class initializer can be run. Linking involves the following
diff --git a/libjava/java/lang/Object.h b/libjava/java/lang/Object.h
index 05a4751..5e7337a 100644
--- a/libjava/java/lang/Object.h
+++ b/libjava/java/lang/Object.h
@@ -1,6 +1,6 @@
// Object.h - Header file for java.lang.Object. -*- c++ -*-
-/* Copyright (C) 1998, 1999 Red Hat, Inc.
+/* Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
This file is part of libgcj.
@@ -69,8 +69,6 @@ private:
// Initialize the sync_info field.
void sync_init (void);
-
- static void hack12_6 (jobject f);
};
#endif /* __JAVA_LANG_OBJECT_H__ */
diff --git a/libjava/java/lang/Object.java b/libjava/java/lang/Object.java
index b61943a..9523f03 100644
--- a/libjava/java/lang/Object.java
+++ b/libjava/java/lang/Object.java
@@ -1,6 +1,6 @@
// Object.java - The root of all evil.
-/* Copyright (C) 1998, 1999 Red Hat, Inc.
+/* Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
This file is part of libgcj.
@@ -66,21 +66,6 @@ public class Object
// completeness (some day we'll be able to auto-generate Object.h).
private final native void sync_init ();
- // This exists as a workaround for the fact that we can't catch a
- // Java Exception from C++. This is from section 12.6 of the Java
- // Language Spec. FIXME: remove this once exception processing
- // works.
- private static final void hack12_6 (Object f)
- {
- try
- {
- f.finalize();
- }
- catch (Throwable x)
- {
- }
- }
-
// Note that we don't mention the sync_info field here. If we do,
// jc1 will not work correctly.
}
diff --git a/libjava/java/lang/Thread.java b/libjava/java/lang/Thread.java
index 68dc244..9cf7109 100644
--- a/libjava/java/lang/Thread.java
+++ b/libjava/java/lang/Thread.java
@@ -116,8 +116,8 @@ public class Thread implements Runnable
public final native void resume ();
// This method exists only to avoid a warning from the C++ compiler.
- private static final native void run__ (Object obj);
- private native final void finish_ ();
+ private static final native void run_ (Object obj);
+ private final native void finish_ ();
// Convenience method to check and clear the thread's interrupted status.
private boolean isInterrupted_ ()
@@ -127,28 +127,6 @@ public class Thread implements Runnable
return r;
}
- private final void run_ ()
- {
- try
- {
- run ();
- }
- catch (Throwable e)
- {
- // Uncaught exceptions are forwarded to the ThreadGroup. If
- // this results in an uncaught exception, that is ignored.
- try
- {
- group.uncaughtException(this, e);
- }
- catch (Throwable f)
- {
- // Nothing.
- }
- }
- finish_ ();
- }
-
public void run ()
{
if (runnable != null)
diff --git a/libjava/java/lang/natClass.cc b/libjava/java/lang/natClass.cc
index 882fadd..42af715 100644
--- a/libjava/java/lang/natClass.cc
+++ b/libjava/java/lang/natClass.cc
@@ -27,6 +27,7 @@ details. */
#include <java/lang/reflect/Constructor.h>
#include <java/lang/AbstractMethodError.h>
#include <java/lang/ClassNotFoundException.h>
+#include <java/lang/ExceptionInInitializerError.h>
#include <java/lang/IllegalAccessException.h>
#include <java/lang/IllegalAccessError.h>
#include <java/lang/IncompatibleClassChangeError.h>
@@ -690,15 +691,6 @@ java::lang::Class::finalize (void)
#endif
}
-// FIXME.
-void
-java::lang::Class::hackRunInitializers (void)
-{
- _Jv_Method *meth = _Jv_GetMethodLocal (this, clinit_name, void_signature);
- if (meth)
- ((void (*) (void)) meth->ncode) ();
-}
-
// This implements the initialization process for a class. From Spec
// section 12.4.2.
void
@@ -764,46 +756,53 @@ java::lang::Class::initializeClass (void)
// Step 7.
if (! isInterface () && superclass)
{
- // FIXME: We can't currently catch a Java exception in C++ code.
- // So instead we call a Java trampoline. It returns an
- // exception, or null.
- jobject except = superclass->hackTrampoline(0, NULL);
- if (except)
+ try
+ {
+ superclass->initializeClass ();
+ }
+ catch (java::lang::Throwable *except)
{
// Caught an exception.
_Jv_MonitorEnter (this);
state = JV_STATE_ERROR;
notifyAll ();
_Jv_MonitorExit (this);
- JvThrow (except);
+ throw except;
}
}
- // Step 8.
- // FIXME: once again we have to go through a trampoline.
- java::lang::Throwable *except = hackTrampoline (1, NULL);
-
- // Steps 9, 10, 11.
- if (! except)
+ // Steps 8, 9, 10, 11.
+ try
{
- _Jv_MonitorEnter (this);
- state = JV_STATE_DONE;
+ _Jv_Method *meth = _Jv_GetMethodLocal (this, clinit_name,
+ void_signature);
+ if (meth)
+ ((void (*) (void)) meth->ncode) ();
}
- else
+ catch (java::lang::Throwable *except)
{
if (! ErrorClass.isInstance(except))
{
- // Once again we must use the trampoline. In this case we
- // have to detect an OutOfMemoryError.
- except = hackTrampoline(2, except);
+ try
+ {
+ except = new ExceptionInInitializerError (except);
+ }
+ catch (java::lang::Throwable *t)
+ {
+ except = t;
+ }
}
_Jv_MonitorEnter (this);
state = JV_STATE_ERROR;
+ notifyAll ();
+ _Jv_MonitorExit (this);
+ JvThrow (except);
}
+
+ _Jv_MonitorEnter (this);
+ state = JV_STATE_DONE;
notifyAll ();
_Jv_MonitorExit (this);
- if (except)
- JvThrow (except);
}
diff --git a/libjava/java/lang/natClassLoader.cc b/libjava/java/lang/natClassLoader.cc
index e5ff17e..39ee0ba 100644
--- a/libjava/java/lang/natClassLoader.cc
+++ b/libjava/java/lang/natClassLoader.cc
@@ -58,15 +58,6 @@ java::lang::ClassLoader::getSystemClassLoader (void)
return system;
}
-void
-java::lang::ClassLoader::defineClass2 (jclass klass, jbyteArray data,
- jint offset, jint length)
-{
-#ifdef INTERPRETER
- _Jv_DefineClass (klass, data, offset, length);
-#endif
-}
-
java::lang::Class *
java::lang::ClassLoader::defineClass0 (jstring name,
jbyteArray data,
@@ -94,11 +85,11 @@ java::lang::ClassLoader::defineClass0 (jstring name,
klass->name = name2;
}
- // this will do the magic. loadInto also operates
- // as an exception trampoline for now...
- Throwable *ex = defineClass1 (klass, data, offset, length);
-
- if (ex) // we failed to load it
+ try
+ {
+ _Jv_DefineClass (klass, data, offset, length);
+ }
+ catch (java::lang::Throwable *ex)
{
klass->state = JV_STATE_ERROR;
klass->notifyAll ();
@@ -106,15 +97,15 @@ java::lang::ClassLoader::defineClass0 (jstring name,
_Jv_UnregisterClass (klass);
_Jv_MonitorExit (klass);
-
+
// FIXME: Here we may want to test that EX does
// indeed represent a valid exception. That is,
// anything but ClassNotFoundException,
// or some kind of Error.
-
+
JvThrow (ex);
}
-
+
// if everything proceeded sucessfully, we're loaded.
JvAssert (klass->state == JV_STATE_LOADED);
diff --git a/libjava/java/lang/natObject.cc b/libjava/java/lang/natObject.cc
index 66fbdbf..cdce6d2 100644
--- a/libjava/java/lang/natObject.cc
+++ b/libjava/java/lang/natObject.cc
@@ -1,6 +1,6 @@
// natObject.cc - Implementation of the Object class.
-/* Copyright (C) 1998, 1999 Red Hat, Inc.
+/* Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
This file is part of libgcj.
@@ -242,5 +242,13 @@ _Jv_MonitorExit (jobject obj)
void
_Jv_FinalizeObject (jobject obj)
{
- java::lang::Object::hack12_6(obj);
+ // Ignore exceptions. From section 12.6 of the Java Language Spec.
+ try
+ {
+ obj->finalize ();
+ }
+ catch (java::lang::Throwable *t)
+ {
+ // Ignore.
+ }
}
diff --git a/libjava/java/lang/natThread.cc b/libjava/java/lang/natThread.cc
index 6d05217..9c56808 100644
--- a/libjava/java/lang/natThread.cc
+++ b/libjava/java/lang/natThread.cc
@@ -263,9 +263,9 @@ java::lang::Thread::sleep (jlong millis, jint nanos)
}
void
-java::lang::Thread::finish_ (void)
+java::lang::Thread::finish_ ()
{
- // Notify all threads waiting to join this thread.
+ // Notify all threads waiting to join this this.
_Jv_MonitorEnter (this);
alive_flag = false;
@@ -285,10 +285,28 @@ java::lang::Thread::finish_ (void)
}
void
-java::lang::Thread::run__ (jobject obj)
+java::lang::Thread::run_ (jobject obj)
{
java::lang::Thread *thread = (java::lang::Thread *) obj;
- thread->run_ ();
+ try
+ {
+ thread->run ();
+ }
+ catch (java::lang::Throwable *t)
+ {
+ // Uncaught exceptions are forwarded to the ThreadGroup. If
+ // this results in an uncaught exception, that is ignored.
+ try
+ {
+ thread->group->uncaughtException (thread, t);
+ }
+ catch (java::lang::Throwable *f)
+ {
+ // Nothing.
+ }
+ }
+
+ thread->finish_ ();
}
void
@@ -301,7 +319,7 @@ java::lang::Thread::start (void)
alive_flag = true;
natThread *nt = (natThread *) data;
- _Jv_ThreadStart (this, nt->thread, (_Jv_ThreadStartFunc *) &run__);
+ _Jv_ThreadStart (this, nt->thread, (_Jv_ThreadStartFunc *) &run_);
}
void
diff --git a/libjava/java/lang/reflect/Method.java b/libjava/java/lang/reflect/Method.java
index edca309..e95ca0d 100644
--- a/libjava/java/lang/reflect/Method.java
+++ b/libjava/java/lang/reflect/Method.java
@@ -1,6 +1,6 @@
// Method.java - Represent method of class or interface.
-/* Copyright (C) 1998, 1999 Red Hat, Inc.
+/* Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
This file is part of libgcj.
@@ -68,30 +68,6 @@ public final class Method extends AccessibleObject implements Member
return name.hashCode() + declaringClass.getName().hashCode();
}
- // This is used to perform an actual method call via ffi.
- private static final native void hack_call (RawData cif,
- RawData method,
- RawData ret_value,
- RawData values);
-
- // Perform an ffi call while capturing exceptions. We have to do
- // this because we can't catch Java exceptions from C++.
- static final Throwable hack_trampoline (RawData cif,
- RawData method,
- RawData ret_value,
- RawData values)
- {
- try
- {
- hack_call (cif, method, ret_value, values);
- }
- catch (Throwable x)
- {
- return x;
- }
- return null;
- }
-
public native Object invoke (Object obj, Object[] args)
throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException;
diff --git a/libjava/java/lang/reflect/natMethod.cc b/libjava/java/lang/reflect/natMethod.cc
index 988fa1e..c4482ee 100644
--- a/libjava/java/lang/reflect/natMethod.cc
+++ b/libjava/java/lang/reflect/natMethod.cc
@@ -152,21 +152,6 @@ get_ffi_type (jclass klass)
return r;
}
-// Actually perform an FFI call.
-void
-java::lang::reflect::Method::hack_call (gnu::gcj::RawData *rcif,
- gnu::gcj::RawData *rmethod,
- gnu::gcj::RawData *rret_value,
- gnu::gcj::RawData *rvalues)
-{
- ffi_cif *cif = (ffi_cif *) rcif;
- void (*method) (...) = (void (*) (...)) rmethod;
- void *ret_value = (void *) rret_value;
- void **values = (void **) rvalues;
-
- ffi_call (cif, method, ret_value, values);
-}
-
jobject
java::lang::reflect::Method::invoke (jobject obj, jobjectArray args)
{
@@ -419,19 +404,23 @@ _Jv_CallAnyMethodA (jobject obj,
// FIXME: initialize class here.
- java::lang::Throwable *ex;
using namespace java::lang;
using namespace java::lang::reflect;
- ex = Method::hack_trampoline ((gnu::gcj::RawData *) &cif,
- (gnu::gcj::RawData *) meth->ncode,
- (gnu::gcj::RawData *) result,
- (gnu::gcj::RawData *) values);
- if (ex)
- // FIXME: this is wrong for JNI. But if we just return the
- // exception, then the non-JNI cases won't be able to distinguish
- // it from exceptions we might generate ourselves. Sigh.
- ex = new InvocationTargetException (ex);
+ Throwable *ex = NULL;
+
+ try
+ {
+ ffi_call (&cif, (void (*) (...)) meth->ncode, result, values);
+ }
+ catch (Throwable *ex2)
+ {
+ // FIXME: this is wrong for JNI. But if we just return the
+ // exception, then the non-JNI cases won't be able to
+ // distinguish it from exceptions we might generate ourselves.
+ // Sigh.
+ ex = new InvocationTargetException (ex2);
+ }
if (is_constructor)
result->l = obj;