Commit b099f07d by Tom Tromey Committed by Tom Tromey

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
parent c45da1ca
2000-03-02 Tom Tromey <tromey@cygnus.com>
* 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.
2000-02-28 Mo DeJong <mdejong@cygnus.com> 2000-02-28 Mo DeJong <mdejong@cygnus.com>
* java/util/zip/ZipOutputStream.java(closeEntry) : Fixed * java/util/zip/ZipOutputStream.java(closeEntry) : Fixed
......
...@@ -267,11 +267,6 @@ gnu/gcj/runtime/VMClassLoader.h: gnu/gcj/runtime/VMClassLoader.class libgcj.zip ...@@ -267,11 +267,6 @@ gnu/gcj/runtime/VMClassLoader.h: gnu/gcj/runtime/VMClassLoader.class libgcj.zip
-friend 'java::lang::ClassLoader;' \ -friend 'java::lang::ClassLoader;' \
$(basename $<) $(basename $<)
gnu/gcj/runtime/MethodInvocation.h: gnu/gcj/runtime/MethodInvocation.class libgcj.zip
$(GCJH) -classpath $(top_builddir) \
-friend 'class _Jv_InterpMethod;' \
$(basename $<)
## Headers we maintain by hand and which we want to install. ## Headers we maintain by hand and which we want to install.
extra_headers = java/lang/Object.h java/lang/Class.h extra_headers = java/lang/Object.h java/lang/Class.h
...@@ -525,7 +520,6 @@ ordinary_java_source_files = $(convert_source_files) \ ...@@ -525,7 +520,6 @@ ordinary_java_source_files = $(convert_source_files) \
gnu/gcj/io/DefaultMimeTypes.java \ gnu/gcj/io/DefaultMimeTypes.java \
gnu/gcj/io/MimeTypes.java \ gnu/gcj/io/MimeTypes.java \
gnu/gcj/jni/NativeThread.java \ gnu/gcj/jni/NativeThread.java \
gnu/gcj/runtime/MethodInvocation.java \
gnu/gcj/runtime/VMClassLoader.java \ gnu/gcj/runtime/VMClassLoader.java \
gnu/gcj/text/BaseBreakIterator.java \ gnu/gcj/text/BaseBreakIterator.java \
gnu/gcj/text/CharacterBreakIterator.java \ gnu/gcj/text/CharacterBreakIterator.java \
......
...@@ -329,7 +329,6 @@ ordinary_java_source_files = $(convert_source_files) \ ...@@ -329,7 +329,6 @@ ordinary_java_source_files = $(convert_source_files) \
gnu/gcj/io/DefaultMimeTypes.java \ gnu/gcj/io/DefaultMimeTypes.java \
gnu/gcj/io/MimeTypes.java \ gnu/gcj/io/MimeTypes.java \
gnu/gcj/jni/NativeThread.java \ gnu/gcj/jni/NativeThread.java \
gnu/gcj/runtime/MethodInvocation.java \
gnu/gcj/runtime/VMClassLoader.java \ gnu/gcj/runtime/VMClassLoader.java \
gnu/gcj/text/BaseBreakIterator.java \ gnu/gcj/text/BaseBreakIterator.java \
gnu/gcj/text/CharacterBreakIterator.java \ gnu/gcj/text/CharacterBreakIterator.java \
...@@ -739,7 +738,7 @@ THANKS acinclude.m4 aclocal.m4 configure configure.in libgcj.spec.in ...@@ -739,7 +738,7 @@ THANKS acinclude.m4 aclocal.m4 configure configure.in libgcj.spec.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar TAR = tar
GZIP_ENV = --best GZIP_ENV = --best
DIST_SUBDIRS = @DIRLTDL@ testsuite gcj include @DIRLTDL@ gcj include DIST_SUBDIRS = @DIRLTDL@ testsuite gcj include @DIRLTDL@ gcj include
DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
...@@ -765,7 +764,6 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ ...@@ -765,7 +764,6 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
.deps/gnu/gcj/protocol/http/Handler.P \ .deps/gnu/gcj/protocol/http/Handler.P \
.deps/gnu/gcj/protocol/jar/Connection.P \ .deps/gnu/gcj/protocol/jar/Connection.P \
.deps/gnu/gcj/protocol/jar/Handler.P \ .deps/gnu/gcj/protocol/jar/Handler.P \
.deps/gnu/gcj/runtime/MethodInvocation.P \
.deps/gnu/gcj/runtime/VMClassLoader.P \ .deps/gnu/gcj/runtime/VMClassLoader.P \
.deps/gnu/gcj/text/BaseBreakIterator.P \ .deps/gnu/gcj/text/BaseBreakIterator.P \
.deps/gnu/gcj/text/CharacterBreakIterator.P \ .deps/gnu/gcj/text/CharacterBreakIterator.P \
...@@ -1284,7 +1282,7 @@ distdir: $(DISTFILES) ...@@ -1284,7 +1282,7 @@ distdir: $(DISTFILES)
@for file in $(DISTFILES); do \ @for file in $(DISTFILES); do \
d=$(srcdir); \ d=$(srcdir); \
if test -d $$d/$$file; then \ if test -d $$d/$$file; then \
cp -pr $$d/$$file $(distdir)/$$file; \ cp -pr $$/$$file $(distdir)/$$file; \
else \ else \
test -f $(distdir)/$$file \ test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
...@@ -1565,11 +1563,6 @@ gnu/gcj/runtime/VMClassLoader.h: gnu/gcj/runtime/VMClassLoader.class libgcj.zip ...@@ -1565,11 +1563,6 @@ gnu/gcj/runtime/VMClassLoader.h: gnu/gcj/runtime/VMClassLoader.class libgcj.zip
-friend 'java::lang::ClassLoader;' \ -friend 'java::lang::ClassLoader;' \
$(basename $<) $(basename $<)
gnu/gcj/runtime/MethodInvocation.h: gnu/gcj/runtime/MethodInvocation.class libgcj.zip
$(GCJH) -classpath $(top_builddir) \
-friend 'class _Jv_InterpMethod;' \
$(basename $<)
install-data-local: install-data-local:
$(PRE_INSTALL) $(PRE_INSTALL)
@for f in $(nat_headers) $(extra_headers); do \ @for f in $(nat_headers) $(extra_headers); do \
......
// MethodInvocation.java - wrapper used by the interpreter.
// (the native method is implemented in interpret.cc)
/* Copyright (C) 1999 Red Hat, Inc.
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
/* Author: Kresten Krab Thorup <krab@gnu.org> */
package gnu.gcj.runtime;
import gnu.gcj.RawData;
final class MethodInvocation {
private static Throwable continue0 (RawData meth, RawData inv)
{
try {
continue1 (meth, inv);
} catch (Throwable ex) {
return ex;
}
return null;
}
private static native void continue1 (RawData meth, RawData inv);
}
...@@ -20,7 +20,6 @@ details. */ ...@@ -20,7 +20,6 @@ details. */
#include <java/lang/Class.h> #include <java/lang/Class.h>
#include <java/lang/ClassLoader.h> #include <java/lang/ClassLoader.h>
#include <gnu/gcj/runtime/MethodInvocation.h>
extern "C" { extern "C" {
#include <ffi.h> #include <ffi.h>
...@@ -135,7 +134,6 @@ class _Jv_InterpMethod : public _Jv_MethodBase ...@@ -135,7 +134,6 @@ class _Jv_InterpMethod : public _Jv_MethodBase
friend class _Jv_ClassReader; friend class _Jv_ClassReader;
friend class _Jv_InterpMethodInvocation; friend class _Jv_InterpMethodInvocation;
friend class gnu::gcj::runtime::MethodInvocation;
friend void _Jv_PrepareClass(jclass); friend void _Jv_PrepareClass(jclass);
}; };
......
...@@ -33,19 +33,7 @@ details. */ ...@@ -33,19 +33,7 @@ details. */
#include <java-insns.h> #include <java-insns.h>
#include <java-signal.h> #include <java-signal.h>
#ifndef INTERPRETER #ifdef INTERPRETER
#include <gnu/gcj/runtime/MethodInvocation.h>
/* This should never happen. */
void
gnu::gcj::runtime::MethodInvocation::continue1 (gnu::gcj::RawData *,
gnu::gcj::RawData *)
{
JvFail ("no interpreter");
}
#else
#define ClassError _CL_Q34java4lang5Error #define ClassError _CL_Q34java4lang5Error
extern java::lang::Class ClassError; extern java::lang::Class ClassError;
...@@ -216,10 +204,17 @@ _Jv_InterpMethod::run (ffi_cif* cif, ...@@ -216,10 +204,17 @@ _Jv_InterpMethod::run (ffi_cif* cif,
memcpy ((void*) locals, (void*) args, args_raw_size); memcpy ((void*) locals, (void*) args, args_raw_size);
next_segment: next_segment:
/* this will call the method _Jv_InterpMethod::continue0, see below */
jobject ex = jobject ex = NULL;
gnu::gcj::runtime::MethodInvocation::continue0
((gnu::gcj::RawData *)this, (gnu::gcj::RawData *)inv); try
{
continue1 (inv);
}
catch (java::lang::Throwable *ex2)
{
ex = ex2;
}
if (ex == 0) // no exception... if (ex == 0) // no exception...
{ {
...@@ -280,7 +275,6 @@ _Jv_InterpMethod::run (ffi_cif* cif, ...@@ -280,7 +275,6 @@ _Jv_InterpMethod::run (ffi_cif* cif,
default: default:
throw_internal_error ("unknown return type"); throw_internal_error ("unknown return type");
} }
} }
/** handle an exception */ /** handle an exception */
...@@ -379,16 +373,6 @@ void _Jv_InterpMethod::run_synch_class (ffi_cif* cif, ...@@ -379,16 +373,6 @@ void _Jv_InterpMethod::run_synch_class (ffi_cif* cif,
if (ex != 0) _Jv_Throw (ex); if (ex != 0) _Jv_Throw (ex);
} }
/* this is the exception handler hack, for the interpreter */
void
gnu::gcj::runtime::MethodInvocation::continue1 (gnu::gcj::RawData *meth,
gnu::gcj::RawData *inv)
{
_Jv_InterpMethod *meth0 = (_Jv_InterpMethod*)meth;
_Jv_InterpMethodInvocation *inv0 = (_Jv_InterpMethodInvocation*)inv;
meth0->continue1 (inv0);
}
/* /*
This proceeds execution, as designated in "inv". If an exception This proceeds execution, as designated in "inv". If an exception
happens, then it is simply thrown, and handled in Java. Thus, the pc happens, then it is simply thrown, and handled in Java. Thus, the pc
......
...@@ -157,9 +157,6 @@ public: ...@@ -157,9 +157,6 @@ public:
private: private:
void checkMemberAccess (jint flags); void checkMemberAccess (jint flags);
// Various functions to handle class initialization.
java::lang::Throwable *hackTrampoline (jint, java::lang::Throwable *);
void hackRunInitializers (void);
void initializeClass (void); void initializeClass (void);
// Friend functions implemented in natClass.cc. // Friend functions implemented in natClass.cc.
......
...@@ -172,32 +172,6 @@ public final class Class implements Serializable ...@@ -172,32 +172,6 @@ public final class Class implements Serializable
sm.checkMemberAccess(this, flags); 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. // Initialize the class.
private native void initializeClass (); private native void initializeClass ();
......
// ClassLoader.java - Define policies for loading Java classes. // 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. This file is part of libgcj.
...@@ -234,28 +234,6 @@ public abstract class ClassLoader { ...@@ -234,28 +234,6 @@ public abstract class ClassLoader {
throws java.lang.ClassNotFoundException, java.lang.LinkageError; 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 * Link the given class. This will bring the class to a state where
* the class initializer can be run. Linking involves the following * the class initializer can be run. Linking involves the following
......
// Object.h - Header file for java.lang.Object. -*- c++ -*- // 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. This file is part of libgcj.
...@@ -69,8 +69,6 @@ private: ...@@ -69,8 +69,6 @@ private:
// Initialize the sync_info field. // Initialize the sync_info field.
void sync_init (void); void sync_init (void);
static void hack12_6 (jobject f);
}; };
#endif /* __JAVA_LANG_OBJECT_H__ */ #endif /* __JAVA_LANG_OBJECT_H__ */
// Object.java - The root of all evil. // 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. This file is part of libgcj.
...@@ -66,21 +66,6 @@ public class Object ...@@ -66,21 +66,6 @@ public class Object
// completeness (some day we'll be able to auto-generate Object.h). // completeness (some day we'll be able to auto-generate Object.h).
private final native void sync_init (); 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, // Note that we don't mention the sync_info field here. If we do,
// jc1 will not work correctly. // jc1 will not work correctly.
} }
...@@ -116,8 +116,8 @@ public class Thread implements Runnable ...@@ -116,8 +116,8 @@ public class Thread implements Runnable
public final native void resume (); public final native void resume ();
// This method exists only to avoid a warning from the C++ compiler. // This method exists only to avoid a warning from the C++ compiler.
private static final native void run__ (Object obj); private static final native void run_ (Object obj);
private native final void finish_ (); private final native void finish_ ();
// Convenience method to check and clear the thread's interrupted status. // Convenience method to check and clear the thread's interrupted status.
private boolean isInterrupted_ () private boolean isInterrupted_ ()
...@@ -127,28 +127,6 @@ public class Thread implements Runnable ...@@ -127,28 +127,6 @@ public class Thread implements Runnable
return r; 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 () public void run ()
{ {
if (runnable != null) if (runnable != null)
......
...@@ -27,6 +27,7 @@ details. */ ...@@ -27,6 +27,7 @@ details. */
#include <java/lang/reflect/Constructor.h> #include <java/lang/reflect/Constructor.h>
#include <java/lang/AbstractMethodError.h> #include <java/lang/AbstractMethodError.h>
#include <java/lang/ClassNotFoundException.h> #include <java/lang/ClassNotFoundException.h>
#include <java/lang/ExceptionInInitializerError.h>
#include <java/lang/IllegalAccessException.h> #include <java/lang/IllegalAccessException.h>
#include <java/lang/IllegalAccessError.h> #include <java/lang/IllegalAccessError.h>
#include <java/lang/IncompatibleClassChangeError.h> #include <java/lang/IncompatibleClassChangeError.h>
...@@ -690,15 +691,6 @@ java::lang::Class::finalize (void) ...@@ -690,15 +691,6 @@ java::lang::Class::finalize (void)
#endif #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 // This implements the initialization process for a class. From Spec
// section 12.4.2. // section 12.4.2.
void void
...@@ -764,46 +756,53 @@ java::lang::Class::initializeClass (void) ...@@ -764,46 +756,53 @@ java::lang::Class::initializeClass (void)
// Step 7. // Step 7.
if (! isInterface () && superclass) if (! isInterface () && superclass)
{ {
// FIXME: We can't currently catch a Java exception in C++ code. try
// So instead we call a Java trampoline. It returns an {
// exception, or null. superclass->initializeClass ();
jobject except = superclass->hackTrampoline(0, NULL); }
if (except) catch (java::lang::Throwable *except)
{ {
// Caught an exception. // Caught an exception.
_Jv_MonitorEnter (this); _Jv_MonitorEnter (this);
state = JV_STATE_ERROR; state = JV_STATE_ERROR;
notifyAll (); notifyAll ();
_Jv_MonitorExit (this); _Jv_MonitorExit (this);
JvThrow (except); throw except;
} }
} }
// Step 8. // Steps 8, 9, 10, 11.
// FIXME: once again we have to go through a trampoline. try
java::lang::Throwable *except = hackTrampoline (1, NULL);
// Steps 9, 10, 11.
if (! except)
{ {
_Jv_MonitorEnter (this); _Jv_Method *meth = _Jv_GetMethodLocal (this, clinit_name,
state = JV_STATE_DONE; void_signature);
if (meth)
((void (*) (void)) meth->ncode) ();
} }
else catch (java::lang::Throwable *except)
{ {
if (! ErrorClass.isInstance(except)) if (! ErrorClass.isInstance(except))
{ {
// Once again we must use the trampoline. In this case we try
// have to detect an OutOfMemoryError. {
except = hackTrampoline(2, except); except = new ExceptionInInitializerError (except);
}
catch (java::lang::Throwable *t)
{
except = t;
}
} }
_Jv_MonitorEnter (this); _Jv_MonitorEnter (this);
state = JV_STATE_ERROR; state = JV_STATE_ERROR;
}
notifyAll (); notifyAll ();
_Jv_MonitorExit (this); _Jv_MonitorExit (this);
if (except)
JvThrow (except); JvThrow (except);
}
_Jv_MonitorEnter (this);
state = JV_STATE_DONE;
notifyAll ();
_Jv_MonitorExit (this);
} }
......
...@@ -58,15 +58,6 @@ java::lang::ClassLoader::getSystemClassLoader (void) ...@@ -58,15 +58,6 @@ java::lang::ClassLoader::getSystemClassLoader (void)
return system; 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::Class *
java::lang::ClassLoader::defineClass0 (jstring name, java::lang::ClassLoader::defineClass0 (jstring name,
jbyteArray data, jbyteArray data,
...@@ -94,11 +85,11 @@ java::lang::ClassLoader::defineClass0 (jstring name, ...@@ -94,11 +85,11 @@ java::lang::ClassLoader::defineClass0 (jstring name,
klass->name = name2; klass->name = name2;
} }
// this will do the magic. loadInto also operates try
// as an exception trampoline for now... {
Throwable *ex = defineClass1 (klass, data, offset, length); _Jv_DefineClass (klass, data, offset, length);
}
if (ex) // we failed to load it catch (java::lang::Throwable *ex)
{ {
klass->state = JV_STATE_ERROR; klass->state = JV_STATE_ERROR;
klass->notifyAll (); klass->notifyAll ();
......
// natObject.cc - Implementation of the Object class. // 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. This file is part of libgcj.
...@@ -242,5 +242,13 @@ _Jv_MonitorExit (jobject obj) ...@@ -242,5 +242,13 @@ _Jv_MonitorExit (jobject obj)
void void
_Jv_FinalizeObject (jobject obj) _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.
}
} }
...@@ -263,9 +263,9 @@ java::lang::Thread::sleep (jlong millis, jint nanos) ...@@ -263,9 +263,9 @@ java::lang::Thread::sleep (jlong millis, jint nanos)
} }
void 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); _Jv_MonitorEnter (this);
alive_flag = false; alive_flag = false;
...@@ -285,10 +285,28 @@ java::lang::Thread::finish_ (void) ...@@ -285,10 +285,28 @@ java::lang::Thread::finish_ (void)
} }
void void
java::lang::Thread::run__ (jobject obj) java::lang::Thread::run_ (jobject obj)
{ {
java::lang::Thread *thread = (java::lang::Thread *) 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 void
...@@ -301,7 +319,7 @@ java::lang::Thread::start (void) ...@@ -301,7 +319,7 @@ java::lang::Thread::start (void)
alive_flag = true; alive_flag = true;
natThread *nt = (natThread *) data; natThread *nt = (natThread *) data;
_Jv_ThreadStart (this, nt->thread, (_Jv_ThreadStartFunc *) &run__); _Jv_ThreadStart (this, nt->thread, (_Jv_ThreadStartFunc *) &run_);
} }
void void
......
// Method.java - Represent method of class or interface. // 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. This file is part of libgcj.
...@@ -68,30 +68,6 @@ public final class Method extends AccessibleObject implements Member ...@@ -68,30 +68,6 @@ public final class Method extends AccessibleObject implements Member
return name.hashCode() + declaringClass.getName().hashCode(); 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) public native Object invoke (Object obj, Object[] args)
throws IllegalAccessException, IllegalArgumentException, throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException; InvocationTargetException;
......
...@@ -152,21 +152,6 @@ get_ffi_type (jclass klass) ...@@ -152,21 +152,6 @@ get_ffi_type (jclass klass)
return r; 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 jobject
java::lang::reflect::Method::invoke (jobject obj, jobjectArray args) java::lang::reflect::Method::invoke (jobject obj, jobjectArray args)
{ {
...@@ -419,19 +404,23 @@ _Jv_CallAnyMethodA (jobject obj, ...@@ -419,19 +404,23 @@ _Jv_CallAnyMethodA (jobject obj,
// FIXME: initialize class here. // FIXME: initialize class here.
java::lang::Throwable *ex;
using namespace java::lang; using namespace java::lang;
using namespace java::lang::reflect; 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) 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 // FIXME: this is wrong for JNI. But if we just return the
// exception, then the non-JNI cases won't be able to distinguish // exception, then the non-JNI cases won't be able to
// it from exceptions we might generate ourselves. Sigh. // distinguish it from exceptions we might generate ourselves.
ex = new InvocationTargetException (ex); // Sigh.
ex = new InvocationTargetException (ex2);
}
if (is_constructor) if (is_constructor)
result->l = obj; result->l = obj;
......
...@@ -115,6 +115,7 @@ mark_for_gc (jobject obj) ...@@ -115,6 +115,7 @@ mark_for_gc (jobject obj)
using namespace java::lang; using namespace java::lang;
Integer *refcount = (Integer *) ref_table->get (obj); Integer *refcount = (Integer *) ref_table->get (obj);
jint val = (refcount == NULL) ? 0 : refcount->intValue (); jint val = (refcount == NULL) ? 0 : refcount->intValue ();
// FIXME: what about out of memory error?
ref_table->put (obj, new Integer (val + 1)); ref_table->put (obj, new Integer (val + 1));
} }
...@@ -131,6 +132,7 @@ unmark_for_gc (jobject obj) ...@@ -131,6 +132,7 @@ unmark_for_gc (jobject obj)
if (val == 0) if (val == 0)
ref_table->remove (obj); ref_table->remove (obj);
else else
// FIXME: what about out of memory error?
ref_table->put (obj, new Integer (val)); ref_table->put (obj, new Integer (val));
} }
...@@ -180,13 +182,15 @@ _Jv_JNI_EnsureLocalCapacity (JNIEnv *env, jint size) ...@@ -180,13 +182,15 @@ _Jv_JNI_EnsureLocalCapacity (JNIEnv *env, jint size)
// size. This isn't the most efficient thing, but for now we don't // size. This isn't the most efficient thing, but for now we don't
// care. Note that _Jv_JNI_PushLocalFrame relies on this right now. // care. Note that _Jv_JNI_PushLocalFrame relies on this right now.
_Jv_JNI_LocalFrame *frame _Jv_JNI_LocalFrame *frame;
= (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame) try
{
frame = (_Jv_JNI_LocalFrame *) _Jv_Malloc (sizeof (_Jv_JNI_LocalFrame)
+ size * sizeof (jobject)); + size * sizeof (jobject));
if (frame == NULL) }
catch (jthrowable t)
{ {
// FIXME: exception processing. env->ex = t;
env->ex = new java::lang::OutOfMemoryError;
return JNI_ERR; return JNI_ERR;
} }
...@@ -304,16 +308,24 @@ static jclass ...@@ -304,16 +308,24 @@ static jclass
_Jv_JNI_DefineClass (JNIEnv *env, jobject loader, _Jv_JNI_DefineClass (JNIEnv *env, jobject loader,
const jbyte *buf, jsize bufLen) const jbyte *buf, jsize bufLen)
{ {
try
{
jbyteArray bytes = JvNewByteArray (bufLen); jbyteArray bytes = JvNewByteArray (bufLen);
jbyte *elts = elements (bytes); jbyte *elts = elements (bytes);
memcpy (elts, buf, bufLen * sizeof (jbyte)); memcpy (elts, buf, bufLen * sizeof (jbyte));
java::lang::ClassLoader *l java::lang::ClassLoader *l
= reinterpret_cast<java::lang::ClassLoader *> (loader); = reinterpret_cast<java::lang::ClassLoader *> (loader);
// FIXME: exception processing.
jclass result = l->defineClass (bytes, 0, bufLen); jclass result = l->defineClass (bytes, 0, bufLen);
return (jclass) wrap_value (env, result); return (jclass) wrap_value (env, result);
}
catch (jthrowable t)
{
env->ex = t;
return NULL;
}
} }
static jclass static jclass
...@@ -324,6 +336,11 @@ _Jv_JNI_FindClass (JNIEnv *env, const char *name) ...@@ -324,6 +336,11 @@ _Jv_JNI_FindClass (JNIEnv *env, const char *name)
char s[len + 1]; char s[len + 1];
for (int i = 0; i <= len; ++i) for (int i = 0; i <= len; ++i)
s[i] = (name[i] == '/') ? '.' : name[i]; s[i] = (name[i] == '/') ? '.' : name[i];
jclass r = NULL;
try
{
// This might throw an out of memory exception.
jstring n = JvNewStringUTF (s); jstring n = JvNewStringUTF (s);
java::lang::ClassLoader *loader; java::lang::ClassLoader *loader;
...@@ -336,8 +353,12 @@ _Jv_JNI_FindClass (JNIEnv *env, const char *name) ...@@ -336,8 +353,12 @@ _Jv_JNI_FindClass (JNIEnv *env, const char *name)
else else
loader = env->klass->getClassLoader (); loader = env->klass->getClassLoader ();
// FIXME: exception processing. r = loader->loadClass (n);
jclass r = loader->loadClass (n); }
catch (jthrowable t)
{
env->ex = t;
}
return (jclass) wrap_value (env, r); return (jclass) wrap_value (env, r);
} }
...@@ -370,24 +391,32 @@ _Jv_JNI_ThrowNew (JNIEnv *env, jclass clazz, const char *message) ...@@ -370,24 +391,32 @@ _Jv_JNI_ThrowNew (JNIEnv *env, jclass clazz, const char *message)
JvAssert ((&ThrowableClass)->isAssignableFrom (clazz)); JvAssert ((&ThrowableClass)->isAssignableFrom (clazz));
int r = JNI_OK;
try
{
JArray<jclass> *argtypes JArray<jclass> *argtypes
= (JArray<jclass> *) JvNewObjectArray (1, &ClassClass, NULL); = (JArray<jclass> *) JvNewObjectArray (1, &ClassClass, NULL);
jclass *elts = elements (argtypes); jclass *elts = elements (argtypes);
elts[0] = &StringClass; elts[0] = &StringClass;
// FIXME: exception processing.
Constructor *cons = clazz->getConstructor (argtypes); Constructor *cons = clazz->getConstructor (argtypes);
jobjectArray values = JvNewObjectArray (1, &StringClass, NULL); jobjectArray values = JvNewObjectArray (1, &StringClass, NULL);
jobject *velts = elements (values); jobject *velts = elements (values);
velts[0] = JvNewStringUTF (message); velts[0] = JvNewStringUTF (message);
// FIXME: exception processing.
jobject obj = cons->newInstance (values); jobject obj = cons->newInstance (values);
env->ex = reinterpret_cast<jthrowable> (obj); env->ex = reinterpret_cast<jthrowable> (obj);
return 0; }
catch (jthrowable t)
{
env->ex = t;
r = JNI_ERR;
}
return r;
} }
static jthrowable static jthrowable
...@@ -435,15 +464,21 @@ _Jv_JNI_AllocObject (JNIEnv *env, jclass clazz) ...@@ -435,15 +464,21 @@ _Jv_JNI_AllocObject (JNIEnv *env, jclass clazz)
jobject obj = NULL; jobject obj = NULL;
using namespace java::lang::reflect; using namespace java::lang::reflect;
try
{
JvAssert (clazz && ! clazz->isArray ()); JvAssert (clazz && ! clazz->isArray ());
if (clazz->isInterface() || Modifier::isAbstract(clazz->getModifiers())) if (clazz->isInterface() || Modifier::isAbstract(clazz->getModifiers()))
env->ex = new java::lang::InstantiationException (); env->ex = new java::lang::InstantiationException ();
else else
{ {
// FIXME: exception processing.
// FIXME: will this work for String? // FIXME: will this work for String?
obj = JvAllocObject (clazz); obj = JvAllocObject (clazz);
} }
}
catch (jthrowable t)
{
env->ex = t;
}
return wrap_value (env, obj); return wrap_value (env, obj);
} }
...@@ -472,7 +507,8 @@ static jmethodID ...@@ -472,7 +507,8 @@ static jmethodID
_Jv_JNI_GetAnyMethodID (JNIEnv *env, jclass clazz, _Jv_JNI_GetAnyMethodID (JNIEnv *env, jclass clazz,
const char *name, const char *sig) const char *name, const char *sig)
{ {
// FIXME: exception processing. try
{
_Jv_InitClass (clazz); _Jv_InitClass (clazz);
_Jv_Utf8Const *name_u = _Jv_makeUtf8Const ((char *) name, -1); _Jv_Utf8Const *name_u = _Jv_makeUtf8Const ((char *) name, -1);
...@@ -502,6 +538,12 @@ _Jv_JNI_GetAnyMethodID (JNIEnv *env, jclass clazz, ...@@ -502,6 +538,12 @@ _Jv_JNI_GetAnyMethodID (JNIEnv *env, jclass clazz,
} }
env->ex = new java::lang::NoSuchMethodError (); env->ex = new java::lang::NoSuchMethodError ();
}
catch (jthrowable t)
{
env->ex = t;
}
return NULL; return NULL;
} }
...@@ -553,7 +595,9 @@ _Jv_JNI_CallAnyMethodV (JNIEnv *env, jobject obj, jclass klass, ...@@ -553,7 +595,9 @@ _Jv_JNI_CallAnyMethodV (JNIEnv *env, jobject obj, jclass klass,
jclass return_type; jclass return_type;
JArray<jclass> *arg_types; JArray<jclass> *arg_types;
// FIXME: exception processing.
try
{
_Jv_GetTypesFromSignature (id, decl_class, _Jv_GetTypesFromSignature (id, decl_class,
&arg_types, &return_type); &arg_types, &return_type);
...@@ -574,6 +618,13 @@ _Jv_JNI_CallAnyMethodV (JNIEnv *env, jobject obj, jclass klass, ...@@ -574,6 +618,13 @@ _Jv_JNI_CallAnyMethodV (JNIEnv *env, jobject obj, jclass klass,
// We cheat a little here. FIXME. // We cheat a little here. FIXME.
return wrap_value (env, * (T *) &result); return wrap_value (env, * (T *) &result);
}
catch (jthrowable t)
{
env->ex = t;
}
return wrap_value (env, (T) 0);
} }
template<typename T, invocation_type style> template<typename T, invocation_type style>
...@@ -604,7 +655,8 @@ _Jv_JNI_CallAnyMethodA (JNIEnv *env, jobject obj, jclass klass, ...@@ -604,7 +655,8 @@ _Jv_JNI_CallAnyMethodA (JNIEnv *env, jobject obj, jclass klass,
jclass return_type; jclass return_type;
JArray<jclass> *arg_types; JArray<jclass> *arg_types;
// FIXME: exception processing. try
{
_Jv_GetTypesFromSignature (id, decl_class, _Jv_GetTypesFromSignature (id, decl_class,
&arg_types, &return_type); &arg_types, &return_type);
...@@ -622,6 +674,13 @@ _Jv_JNI_CallAnyMethodA (JNIEnv *env, jobject obj, jclass klass, ...@@ -622,6 +674,13 @@ _Jv_JNI_CallAnyMethodA (JNIEnv *env, jobject obj, jclass klass,
// We cheat a little here. FIXME. // We cheat a little here. FIXME.
return wrap_value (env, * (T *) &result); return wrap_value (env, * (T *) &result);
}
catch (jthrowable t)
{
env->ex = t;
}
return wrap_value (env, (T) 0);
} }
template<invocation_type style> template<invocation_type style>
...@@ -637,7 +696,8 @@ _Jv_JNI_CallAnyVoidMethodV (JNIEnv *env, jobject obj, jclass klass, ...@@ -637,7 +696,8 @@ _Jv_JNI_CallAnyVoidMethodV (JNIEnv *env, jobject obj, jclass klass,
jclass return_type; jclass return_type;
JArray<jclass> *arg_types; JArray<jclass> *arg_types;
// FIXME: exception processing. try
{
_Jv_GetTypesFromSignature (id, decl_class, _Jv_GetTypesFromSignature (id, decl_class,
&arg_types, &return_type); &arg_types, &return_type);
...@@ -654,6 +714,11 @@ _Jv_JNI_CallAnyVoidMethodV (JNIEnv *env, jobject obj, jclass klass, ...@@ -654,6 +714,11 @@ _Jv_JNI_CallAnyVoidMethodV (JNIEnv *env, jobject obj, jclass klass,
if (ex != NULL) if (ex != NULL)
env->ex = ex; env->ex = ex;
}
catch (jthrowable t)
{
env->ex = t;
}
} }
template<invocation_type style> template<invocation_type style>
...@@ -681,7 +746,8 @@ _Jv_JNI_CallAnyVoidMethodA (JNIEnv *env, jobject obj, jclass klass, ...@@ -681,7 +746,8 @@ _Jv_JNI_CallAnyVoidMethodA (JNIEnv *env, jobject obj, jclass klass,
jclass return_type; jclass return_type;
JArray<jclass> *arg_types; JArray<jclass> *arg_types;
// FIXME: exception processing. try
{
_Jv_GetTypesFromSignature (id, decl_class, _Jv_GetTypesFromSignature (id, decl_class,
&arg_types, &return_type); &arg_types, &return_type);
...@@ -691,6 +757,11 @@ _Jv_JNI_CallAnyVoidMethodA (JNIEnv *env, jobject obj, jclass klass, ...@@ -691,6 +757,11 @@ _Jv_JNI_CallAnyVoidMethodA (JNIEnv *env, jobject obj, jclass klass,
if (ex != NULL) if (ex != NULL)
env->ex = ex; env->ex = ex;
}
catch (jthrowable t)
{
env->ex = t;
}
} }
// Functions with this signature are used to implement functions in // Functions with this signature are used to implement functions in
...@@ -895,7 +966,8 @@ static jfieldID ...@@ -895,7 +966,8 @@ static jfieldID
_Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz, _Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz,
const char *name, const char *sig) const char *name, const char *sig)
{ {
// FIXME: exception processing. try
{
_Jv_InitClass (clazz); _Jv_InitClass (clazz);
_Jv_Utf8Const *a_name = _Jv_makeUtf8Const ((char *) name, -1); _Jv_Utf8Const *a_name = _Jv_makeUtf8Const ((char *) name, -1);
...@@ -938,6 +1010,11 @@ _Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz, ...@@ -938,6 +1010,11 @@ _Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz,
} }
env->ex = new java::lang::NoSuchFieldError (); env->ex = new java::lang::NoSuchFieldError ();
}
catch (jthrowable t)
{
env->ex = t;
}
return NULL; return NULL;
} }
...@@ -960,9 +1037,16 @@ _Jv_JNI_SetStaticField (JNIEnv *, jclass, jfieldID field, T value) ...@@ -960,9 +1037,16 @@ _Jv_JNI_SetStaticField (JNIEnv *, jclass, jfieldID field, T value)
static jstring static jstring
_Jv_JNI_NewString (JNIEnv *env, const jchar *unichars, jsize len) _Jv_JNI_NewString (JNIEnv *env, const jchar *unichars, jsize len)
{ {
// FIXME: exception processing. try
{
jstring r = _Jv_NewString (unichars, len); jstring r = _Jv_NewString (unichars, len);
return (jstring) wrap_value (env, r); return (jstring) wrap_value (env, r);
}
catch (jthrowable t)
{
env->ex = t;
return NULL;
}
} }
static jsize static jsize
...@@ -990,9 +1074,16 @@ _Jv_JNI_ReleaseStringChars (JNIEnv *, jstring string, const jchar *) ...@@ -990,9 +1074,16 @@ _Jv_JNI_ReleaseStringChars (JNIEnv *, jstring string, const jchar *)
static jstring static jstring
_Jv_JNI_NewStringUTF (JNIEnv *env, const char *bytes) _Jv_JNI_NewStringUTF (JNIEnv *env, const char *bytes)
{ {
// FIXME: exception processing. try
{
jstring result = JvNewStringUTF (bytes); jstring result = JvNewStringUTF (bytes);
return (jstring) wrap_value (env, result); return (jstring) wrap_value (env, result);
}
catch (jthrowable t)
{
env->ex = t;
return NULL;
}
} }
static jsize static jsize
...@@ -1002,10 +1093,11 @@ _Jv_JNI_GetStringUTFLength (JNIEnv *, jstring string) ...@@ -1002,10 +1093,11 @@ _Jv_JNI_GetStringUTFLength (JNIEnv *, jstring string)
} }
static const char * static const char *
_Jv_JNI_GetStringUTFChars (JNIEnv *, jstring string, jboolean *isCopy) _Jv_JNI_GetStringUTFChars (JNIEnv *env, jstring string, jboolean *isCopy)
{ {
jsize len = JvGetStringUTFLength (string); jsize len = JvGetStringUTFLength (string);
// FIXME: exception processing. try
{
char *r = (char *) _Jv_Malloc (len + 1); char *r = (char *) _Jv_Malloc (len + 1);
JvGetStringUTFRegion (string, 0, len, r); JvGetStringUTFRegion (string, 0, len, r);
r[len] = '\0'; r[len] = '\0';
...@@ -1014,6 +1106,12 @@ _Jv_JNI_GetStringUTFChars (JNIEnv *, jstring string, jboolean *isCopy) ...@@ -1014,6 +1106,12 @@ _Jv_JNI_GetStringUTFChars (JNIEnv *, jstring string, jboolean *isCopy)
*isCopy = true; *isCopy = true;
return (const char *) r; return (const char *) r;
}
catch (jthrowable t)
{
env->ex = t;
return NULL;
}
} }
static void static void
...@@ -1029,7 +1127,16 @@ _Jv_JNI_GetStringRegion (JNIEnv *env, jstring string, jsize start, jsize len, ...@@ -1029,7 +1127,16 @@ _Jv_JNI_GetStringRegion (JNIEnv *env, jstring string, jsize start, jsize len,
jchar *result = _Jv_GetStringChars (string); jchar *result = _Jv_GetStringChars (string);
if (start < 0 || start > string->length () if (start < 0 || start > string->length ()
|| len < 0 || start + len > string->length ()) || len < 0 || start + len > string->length ())
{
try
{
env->ex = new java::lang::StringIndexOutOfBoundsException (); env->ex = new java::lang::StringIndexOutOfBoundsException ();
}
catch (jthrowable t)
{
env->ex = t;
}
}
else else
memcpy (buf, &result[start], len * sizeof (jchar)); memcpy (buf, &result[start], len * sizeof (jchar));
} }
...@@ -1040,7 +1147,16 @@ _Jv_JNI_GetStringUTFRegion (JNIEnv *env, jstring str, jsize start, ...@@ -1040,7 +1147,16 @@ _Jv_JNI_GetStringUTFRegion (JNIEnv *env, jstring str, jsize start,
{ {
if (start < 0 || start > str->length () if (start < 0 || start > str->length ()
|| len < 0 || start + len > str->length ()) || len < 0 || start + len > str->length ())
{
try
{
env->ex = new java::lang::StringIndexOutOfBoundsException (); env->ex = new java::lang::StringIndexOutOfBoundsException ();
}
catch (jthrowable t)
{
env->ex = t;
}
}
else else
_Jv_GetStringUTFRegion (str, start, len, buf); _Jv_GetStringUTFRegion (str, start, len, buf);
} }
...@@ -1070,9 +1186,16 @@ static jarray ...@@ -1070,9 +1186,16 @@ static jarray
_Jv_JNI_NewObjectArray (JNIEnv *env, jsize length, jclass elementClass, _Jv_JNI_NewObjectArray (JNIEnv *env, jsize length, jclass elementClass,
jobject init) jobject init)
{ {
// FIXME: exception processing. try
{
jarray result = JvNewObjectArray (length, elementClass, init); jarray result = JvNewObjectArray (length, elementClass, init);
return (jarray) wrap_value (env, result); return (jarray) wrap_value (env, result);
}
catch (jthrowable t)
{
env->ex = t;
return NULL;
}
} }
static jobject static jobject
...@@ -1083,21 +1206,34 @@ _Jv_JNI_GetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index) ...@@ -1083,21 +1206,34 @@ _Jv_JNI_GetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index)
} }
static void static void
_Jv_JNI_SetObjectArrayElement (JNIEnv *, jobjectArray array, jsize index, _Jv_JNI_SetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index,
jobject value) jobject value)
{ {
// FIXME: exception processing. try
{
_Jv_CheckArrayStore (array, value); _Jv_CheckArrayStore (array, value);
jobject *elts = elements (array); jobject *elts = elements (array);
elts[index] = value; elts[index] = value;
}
catch (jthrowable t)
{
env->ex = t;
}
} }
template<typename T, jclass K> template<typename T, jclass K>
static JArray<T> * static JArray<T> *
_Jv_JNI_NewPrimitiveArray (JNIEnv *env, jsize length) _Jv_JNI_NewPrimitiveArray (JNIEnv *env, jsize length)
{ {
// FIXME: exception processing. try
{
return (JArray<T> *) wrap_value (env, _Jv_NewPrimArray (K, length)); return (JArray<T> *) wrap_value (env, _Jv_NewPrimArray (K, length));
}
catch (jthrowable t)
{
env->ex = t;
return NULL;
}
} }
template<typename T> template<typename T>
...@@ -1134,9 +1270,17 @@ _Jv_JNI_GetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array, ...@@ -1134,9 +1270,17 @@ _Jv_JNI_GetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array,
{ {
if (start < 0 || len >= array->length || start + len >= array->length) if (start < 0 || len >= array->length || start + len >= array->length)
{ {
try
{
// FIXME: index. // FIXME: index.
env->ex = new java::lang::ArrayIndexOutOfBoundsException (); env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
} }
catch (jthrowable t)
{
// Could have thown out of memory error.
env->ex = t;
}
}
else else
{ {
T *elts = elements (array) + start; T *elts = elements (array) + start;
...@@ -1151,9 +1295,16 @@ _Jv_JNI_SetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array, ...@@ -1151,9 +1295,16 @@ _Jv_JNI_SetPrimitiveArrayRegion (JNIEnv *env, JArray<T> *array,
{ {
if (start < 0 || len >= array->length || start + len >= array->length) if (start < 0 || len >= array->length || start + len >= array->length)
{ {
try
{
// FIXME: index. // FIXME: index.
env->ex = new java::lang::ArrayIndexOutOfBoundsException (); env->ex = new java::lang::ArrayIndexOutOfBoundsException ();
} }
catch (jthrowable t)
{
env->ex = t;
}
}
else else
{ {
T *elts = elements (array) + start; T *elts = elements (array) + start;
...@@ -1181,19 +1332,31 @@ _Jv_JNI_ReleasePrimitiveArrayCritical (JNIEnv *, jarray, void *, jint) ...@@ -1181,19 +1332,31 @@ _Jv_JNI_ReleasePrimitiveArrayCritical (JNIEnv *, jarray, void *, jint)
} }
static jint static jint
_Jv_JNI_MonitorEnter (JNIEnv *, jobject obj) _Jv_JNI_MonitorEnter (JNIEnv *env, jobject obj)
{ {
// FIXME: exception processing. try
jint r = _Jv_MonitorEnter (obj); {
return r; return _Jv_MonitorEnter (obj);
}
catch (jthrowable t)
{
env->ex = t;
}
return JNI_ERR;
} }
static jint static jint
_Jv_JNI_MonitorExit (JNIEnv *, jobject obj) _Jv_JNI_MonitorExit (JNIEnv *env, jobject obj)
{ {
// FIXME: exception processing. try
jint r = _Jv_MonitorExit (obj); {
return r; return _Jv_MonitorExit (obj);
}
catch (jthrowable t)
{
env->ex = t;
}
return JNI_ERR;
} }
// JDK 1.2 // JDK 1.2
...@@ -1201,12 +1364,19 @@ jobject ...@@ -1201,12 +1364,19 @@ jobject
_Jv_JNI_ToReflectedField (JNIEnv *env, jclass cls, jfieldID fieldID, _Jv_JNI_ToReflectedField (JNIEnv *env, jclass cls, jfieldID fieldID,
jboolean) jboolean)
{ {
// FIXME: exception processing. try
{
java::lang::reflect::Field *field = new java::lang::reflect::Field(); java::lang::reflect::Field *field = new java::lang::reflect::Field();
field->declaringClass = cls; field->declaringClass = cls;
field->offset = (char*) fieldID - (char *) cls->fields; field->offset = (char*) fieldID - (char *) cls->fields;
field->name = _Jv_NewStringUtf8Const (fieldID->getNameUtf8Const (cls)); field->name = _Jv_NewStringUtf8Const (fieldID->getNameUtf8Const (cls));
return wrap_value (env, field); return wrap_value (env, field);
}
catch (jthrowable t)
{
env->ex = t;
}
return NULL;
} }
// JDK 1.2 // JDK 1.2
...@@ -1228,7 +1398,10 @@ _Jv_JNI_ToReflectedMethod (JNIEnv *env, jclass klass, jmethodID id, ...@@ -1228,7 +1398,10 @@ _Jv_JNI_ToReflectedMethod (JNIEnv *env, jclass klass, jmethodID id,
// FIXME. // FIXME.
static _Jv_Utf8Const *init_name = _Jv_makeUtf8Const ("<init>", 6); static _Jv_Utf8Const *init_name = _Jv_makeUtf8Const ("<init>", 6);
jobject result; jobject result = NULL;
try
{
if (_Jv_equalUtf8Consts (id->name, init_name)) if (_Jv_equalUtf8Consts (id->name, init_name))
{ {
// A constructor. // A constructor.
...@@ -1244,6 +1417,11 @@ _Jv_JNI_ToReflectedMethod (JNIEnv *env, jclass klass, jmethodID id, ...@@ -1244,6 +1417,11 @@ _Jv_JNI_ToReflectedMethod (JNIEnv *env, jclass klass, jmethodID id,
meth->declaringClass = klass; meth->declaringClass = klass;
result = meth; result = meth;
} }
}
catch (jthrowable t)
{
env->ex = t;
}
return wrap_value (env, result); return wrap_value (env, result);
} }
...@@ -1302,7 +1480,14 @@ _Jv_JNI_RegisterNatives (JNIEnv *env, jclass k, ...@@ -1302,7 +1480,14 @@ _Jv_JNI_RegisterNatives (JNIEnv *env, jclass k,
if (! found) if (! found)
{ {
jstring m = JvNewStringUTF (methods[j].name); jstring m = JvNewStringUTF (methods[j].name);
_Jv_JNI_Throw (env, new java::lang::NoSuchMethodError (m)); try
{
env->ex =new java::lang::NoSuchMethodError (m);
}
catch (jthrowable t)
{
env->ex = t;
}
return JNI_ERR; return JNI_ERR;
} }
} }
...@@ -1545,8 +1730,15 @@ _Jv_JNI_AttachCurrentThread (JavaVM *, jstring name, void **penv, void *args) ...@@ -1545,8 +1730,15 @@ _Jv_JNI_AttachCurrentThread (JavaVM *, jstring name, void **penv, void *args)
// have been called simply to set the new JNIEnv. // have been called simply to set the new JNIEnv.
if (_Jv_ThreadCurrent () == NULL) if (_Jv_ThreadCurrent () == NULL)
{ {
try
{
(void) new gnu::gcj::jni::NativeThread (group, name); (void) new gnu::gcj::jni::NativeThread (group, name);
} }
catch (jthrowable t)
{
return JNI_ERR;
}
}
_Jv_SetCurrentJNIEnv (env); _Jv_SetCurrentJNIEnv (env);
return 0; return 0;
...@@ -1567,8 +1759,19 @@ _Jv_JNI_DestroyJavaVM (JavaVM *vm) ...@@ -1567,8 +1759,19 @@ _Jv_JNI_DestroyJavaVM (JavaVM *vm)
JNIEnv *env; JNIEnv *env;
if (_Jv_ThreadCurrent () != NULL) if (_Jv_ThreadCurrent () != NULL)
{ {
jstring main_name;
// This sucks.
try
{
main_name = JvNewStringLatin1 ("main");
}
catch (jthrowable t)
{
return JNI_ERR;
}
jint r = _Jv_JNI_AttachCurrentThread (vm, jint r = _Jv_JNI_AttachCurrentThread (vm,
JvNewStringLatin1 ("main"), main_name,
reinterpret_cast<void **> (&env), reinterpret_cast<void **> (&env),
NULL); NULL);
if (r < 0) if (r < 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment