/* resolve ********************************************************************/
+void resolve_handle_pending_exception(bool throwError)
+{
+ vm_abort("resolve_handle_pending_exception: Not implemented.");
+}
+
bool resolve_class_from_typedesc(typedesc *d, bool checkaccess, bool link, classinfo **result)
{
abort();
TRACEJVMCALLS(("JVM_FindClassFromClassLoader(name=%s, init=%d, loader=%p, throwError=%d)", name, init, loader, throwError));
+ /* As of now, OpenJDK does not call this function with throwError
+ is true. */
+
+ assert(throwError == false);
+
u = utf_new_char(name);
cl = loader_hashtable_classloader_add((java_handle_t *) loader);
jobject JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException)
{
- java_handle_t *o;
+ java_handle_t *h;
classinfo *c;
methodinfo *m;
java_handle_t *result;
TRACEJVMCALLS(("JVM_DoPrivileged(env=%p, cls=%p, action=%p, context=%p, wrapException=%d)", env, cls, action, context, wrapException));
- o = (java_handle_t *) action;
- c = o->vftbl->class;
+ h = (java_handle_t *) action;
+ LLNI_class_get(h, c);
if (action == NULL) {
exceptions_throw_nullpointerexception();
/* XXX It seems something with a privileged stack needs to be done
here. */
- result = vm_call_method(m, o);
+ result = vm_call_method(m, h);
- e = exceptions_get_and_clear_exception();
+ e = exceptions_get_exception();
if (e != NULL) {
- exceptions_throw_privilegedactionexception(e);
+ if ( builtin_instanceof(e, class_java_lang_Exception) &&
+ !builtin_instanceof(e, class_java_lang_RuntimeException)) {
+ exceptions_clear_exception();
+ exceptions_throw_privilegedactionexception(e);
+ }
+
return NULL;
}
}
+/* exceptions_new_class_utf ****************************************************
+
+ Creates an exception object with the given class and initalizes it
+ with the given utf message.
+
+ IN:
+ c ......... exception class
+ message ... the message as an utf *
+
+ RETURN VALUE:
+ an exception pointer (in any case -- either it is the newly
+ created exception, or an exception thrown while trying to create
+ it).
+
+*******************************************************************************/
+
+static java_handle_t *exceptions_new_class_utf(classinfo *c, utf *message)
+{
+ java_handle_t *s;
+ java_handle_t *o;
+
+ if (vm_initializing)
+ exceptions_abort(c->name, message);
+
+ s = javastring_new(message);
+
+ if (s == NULL)
+ return exceptions_get_exception();
+
+ o = native_new_and_init_string(c, s);
+
+ if (o == NULL)
+ return exceptions_get_exception();
+
+ return o;
+}
+
+
/* exceptions_new_utf **********************************************************
Creates an exception object with the given name and initalizes it.
}
+/* exceptions_new_utf_javastring ***********************************************
+
+ Creates an exception object with the given name and initalizes it
+ with the given java/lang/String message.
+
+ IN:
+ classname....class name in UTF-8
+ message......the message as a java.lang.String
+
+ RETURN VALUE:
+ an exception pointer (in any case -- either it is the newly created
+ exception, or an exception thrown while trying to create it).
+
+*******************************************************************************/
+
+static java_handle_t *exceptions_new_utf_javastring(utf *classname,
+ java_handle_t *message)
+{
+ java_handle_t *o;
+ classinfo *c;
+
+ if (vm_initializing)
+ exceptions_abort(classname, NULL);
+
+ c = load_class_bootstrap(classname);
+
+ if (c == NULL)
+ return exceptions_get_exception();
+
+ o = native_new_and_init_string(c, message);
+
+ if (o == NULL)
+ return exceptions_get_exception();
+
+ return o;
+}
+
+
+/* exceptions_new_utf_utf ******************************************************
+
+ Creates an exception object with the given name and initalizes it
+ with the given utf message.
+
+ IN:
+ classname....class name in UTF-8
+ message......the message as an utf *
+
+ RETURN VALUE:
+ an exception pointer (in any case -- either it is the newly created
+ exception, or an exception thrown while trying to create it).
+
+*******************************************************************************/
+
+static java_handle_t *exceptions_new_utf_utf(utf *classname, utf *message)
+{
+ classinfo *c;
+ java_handle_t *o;
+
+ if (vm_initializing)
+ exceptions_abort(classname, message);
+
+ c = load_class_bootstrap(classname);
+
+ if (c == NULL)
+ return exceptions_get_exception();
+
+ o = exceptions_new_class_utf(c, message);
+
+ return o;
+}
+
+
+/* exceptions_throw_class_utf **************************************************
+
+ Creates an exception object with the given class, initalizes and
+ throws it with the given utf message.
+
+ IN:
+ c ......... exception class
+ message ... the message as an utf *
+
+*******************************************************************************/
+
+static void exceptions_throw_class_utf(classinfo *c, utf *message)
+{
+ java_handle_t *o;
+
+ o = exceptions_new_class_utf(c, message);
+
+ exceptions_set_exception(o);
+}
+
+
/* exceptions_throw_utf ********************************************************
Creates an exception object with the given name, initalizes and
}
-/* exceptions_new_utf_javastring ***********************************************
-
- Creates an exception object with the given name and initalizes it
- with the given java/lang/String message.
-
- IN:
- classname....class name in UTF-8
- message......the message as a java.lang.String
-
- RETURN VALUE:
- an exception pointer (in any case -- either it is the newly created
- exception, or an exception thrown while trying to create it).
-
-*******************************************************************************/
-
-static java_handle_t *exceptions_new_utf_javastring(utf *classname,
- java_handle_t *message)
-{
- java_handle_t *o;
- classinfo *c;
-
- if (vm_initializing)
- exceptions_abort(classname, NULL);
-
- c = load_class_bootstrap(classname);
-
- if (c == NULL)
- return exceptions_get_exception();
-
- o = native_new_and_init_string(c, message);
-
- if (o == NULL)
- return exceptions_get_exception();
-
- return o;
-}
-
-
-/* exceptions_new_utf_utf ******************************************************
-
- Creates an exception object with the given name and initalizes it
- with the given utf message.
-
- IN:
- classname....class name in UTF-8
- message......the message as an utf *
-
- RETURN VALUE:
- an exception pointer (in any case -- either it is the newly created
- exception, or an exception thrown while trying to create it).
-
-*******************************************************************************/
-
-static java_handle_t *exceptions_new_utf_utf(utf *classname, utf *message)
-{
- classinfo *c;
- java_handle_t *s;
- java_handle_t *o;
-
- if (vm_initializing)
- exceptions_abort(classname, message);
-
- c = load_class_bootstrap(classname);
-
- if (c == NULL)
- return exceptions_get_exception();
-
- s = javastring_new(message);
-
- if (s == NULL)
- return exceptions_get_exception();
-
- o = native_new_and_init_string(c, s);
-
- if (o == NULL)
- return exceptions_get_exception();
-
- return o;
-}
-
-
/* exceptions_throw_utf_utf ****************************************************
Creates an exception object with the given name, initalizes and
void exceptions_throw_classnotfoundexception(utf *name)
{
- exceptions_throw_utf_utf(utf_java_lang_ClassNotFoundException, name);
+ exceptions_throw_class_utf(class_java_lang_ClassNotFoundException, name);
}
}
-/* exceptions_classnotfoundexception_to_noclassdeffounderror *******************
-
- Check the exception for a ClassNotFoundException. If it is one,
- convert it to a NoClassDefFoundError.
-
-*******************************************************************************/
-
-void exceptions_classnotfoundexception_to_noclassdeffounderror(void)
-{
- classinfo *c;
- java_handle_t *o;
- java_handle_t *cause;
- java_lang_Throwable *object;
- java_lang_String *s;
-
- /* Load java/lang/ClassNotFoundException for the instanceof
- check. */
-
- c = load_class_bootstrap(utf_java_lang_ClassNotFoundException);
-
- if (c == NULL)
- return;
-
- /* Get the cause. */
-
- cause = exceptions_get_exception();
-
- /* Convert ClassNotFoundException's to NoClassDefFoundError's. */
-
- if (builtin_instanceof(cause, c)) {
- /* clear exception, because we are calling jit code again */
-
- exceptions_clear_exception();
-
- /* create new error */
-
- object = (java_lang_Throwable *) cause;
- LLNI_field_get_ref(object, detailMessage, s);
-
- o = exceptions_new_utf_javastring(utf_java_lang_NoClassDefFoundError,
- (java_handle_t *) s);
-
- /* we had an exception while creating the error */
-
- if (exceptions_get_exception())
- return;
-
- /* set new exception */
-
- exceptions_set_exception(o);
- }
-}
-
-
/* exceptions_fillinstacktrace *************************************************
Calls the fillInStackTrace-method of the currently thrown
/* src/vm/exceptions.h - exception related functions prototypes
- Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
+ Copyright (C) 1996-2005, 2006, 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
void exceptions_throw_privilegedactionexception(java_handle_t *cause);
void exceptions_throw_stringindexoutofboundsexception(void);
-void exceptions_classnotfoundexception_to_noclassdeffounderror(void);
-
java_handle_t *exceptions_fillinstacktrace(void);
void exceptions_print_exception(java_handle_t *xptr);
/* src/vm/resolve.c - resolving classes/interfaces/fields/methods
- Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
+ Copyright (C) 1996-2005, 2006, 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
/*#define RESOLVE_VERBOSE*/
+/* resolve_handle_pending_exception ********************************************
+
+ Convert a pending ClassNotFoundException into a
+ NoClassDefFoundError if requested.
+
+ See: hotspot/src/share/vm/classfile/systemDictionary.cpp
+ (handle_resolution_exception)
+
+ ARGUMENTS:
+ classname .... name of the class currently resolved
+ throwError ... if true throw a NoClassDefFoundError instead of
+ a ClassNotFoundException
+
+*******************************************************************************/
+
+void resolve_handle_pending_exception(bool throwError)
+{
+ java_handle_t *e;
+
+ /* Get the current exception. */
+
+ e = exceptions_get_exception();
+
+ if (e != NULL) {
+ if (throwError == true) {
+ /* Convert ClassNotFoundException to
+ NoClassDefFoundError. */
+
+ if (builtin_instanceof(e, class_java_lang_ClassNotFoundException)) {
+ /* Clear exception, because we are calling Java code
+ again. */
+
+ exceptions_clear_exception();
+
+ /* create new error */
+
+ exceptions_throw_noclassdeffounderror_cause(e);
+ }
+ else {
+ return;
+ }
+ }
+ else {
+ /* An exception conversion was not requested. Simply
+ return. */
+
+ return;
+ }
+ }
+}
+
+
/******************************************************************************/
/* CLASS RESOLUTION */
/******************************************************************************/
if (cls == NULL) {
cls = load_class_from_classloader(classname, referer->classloader);
- if (cls == NULL) {
- /* If the exception is a ClassNotFoundException,
- convert it to a NoClassDefFoundError. */
-
- exceptions_classnotfoundexception_to_noclassdeffounderror();
-
+ if (cls == NULL)
return false;
- }
}
}
/* src/vm/resolve.h - resolving classes/interfaces/fields/methods
- Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
+ Copyright (C) 1996-2005, 2006, 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
#define UNRESOLVED_SUBTYPE_SET_EMTPY(stset) \
do { (stset).subtyperefs = NULL; } while(0)
+
/* function prototypes ********************************************************/
+void resolve_handle_pending_exception(bool throwError);
+
bool resolve_class_from_name(classinfo* referer,methodinfo *refmethod,
utf *classname,
resolve_mode_t mode,
/* frequently used classes ****************************************************/
-/* important system classes */
+/* Important system classes. */
classinfo *class_java_lang_Object;
classinfo *class_java_lang_Class;
classinfo *class_java_lang_VMThrowable;
#endif
+/* Important system exceptions. */
+
+classinfo *class_java_lang_Exception;
+classinfo *class_java_lang_ClassNotFoundException;
+classinfo *class_java_lang_RuntimeException;
+
#if defined(WITH_CLASSPATH_SUN)
classinfo *class_sun_reflect_MagicAccessorImpl;
#endif
/* frequently used classes ****************************************************/
-/* important system classes */
+/* Important system classes. */
extern classinfo *class_java_lang_Object;
extern classinfo *class_java_lang_Class;
extern classinfo *class_java_lang_Throwable;
extern classinfo *class_java_io_Serializable;
+/* Important system exceptions. */
+
+extern classinfo *class_java_lang_Exception;
+extern classinfo *class_java_lang_ClassNotFoundException;
+extern classinfo *class_java_lang_RuntimeException;
+
#if defined(WITH_CLASSPATH_GNU)
extern classinfo *class_java_lang_VMSystem;
extern classinfo *class_java_lang_VMThread;
vm_abort("linker_init: linking failed");
#endif
+ /* Important system exceptions. */
+
+ if (!link_class(class_java_lang_Exception))
+ vm_abort("linker_init: linking failed");
+
+ if (!link_class(class_java_lang_ClassNotFoundException))
+ vm_abort("linker_init: linking failed");
+
+ if (!link_class(class_java_lang_RuntimeException))
+ vm_abort("linker_init: linking failed");
/* some classes which may be used more often */
load_class_bootstrap(utf_new_char("java/lang/VMThrowable"));
#endif
+ /* Important system exceptions. */
+
+ class_java_lang_Exception = load_class_bootstrap(utf_java_lang_Exception);
+
+ class_java_lang_ClassNotFoundException =
+ load_class_bootstrap(utf_java_lang_ClassNotFoundException);
+
+ class_java_lang_RuntimeException =
+ load_class_bootstrap(utf_java_lang_RuntimeException);
+
/* Some classes which may be used often. */
#if defined(ENABLE_JAVASE)
/* XXX This should be done better. */
tc = resolve_classref_or_classinfo_eager(CLASSREF_OR_CLASSINFO(cr), false);
- if (tc == NULL)
+ if (tc == NULL) {
+ resolve_handle_pending_exception(true);
return false;
+ }
/* Interfaces are not allowed as super classes. */
utf *utf_java_lang_InterruptedException;
utf *utf_java_lang_NegativeArraySizeException;
utf *utf_java_lang_NullPointerException;
+utf *utf_java_lang_RuntimeException;
utf *utf_java_lang_StringIndexOutOfBoundsException;
utf *utf_java_lang_reflect_InvocationTargetException;
utf_java_lang_NullPointerException =
utf_new_char("java/lang/NullPointerException");
+ utf_java_lang_RuntimeException =
+ utf_new_char("java/lang/RuntimeException");
+
utf_java_lang_StringIndexOutOfBoundsException =
utf_new_char("java/lang/StringIndexOutOfBoundsException");
extern utf *utf_java_lang_InterruptedException;
extern utf *utf_java_lang_NegativeArraySizeException;
extern utf *utf_java_lang_NullPointerException;
+extern utf *utf_java_lang_RuntimeException;
extern utf *utf_java_lang_StringIndexOutOfBoundsException;
extern utf *utf_java_lang_reflect_InvocationTargetException;
suite.addTest(new TestSuite(PR52.class));
suite.addTest(new TestSuite(PR57.class));
+ suite.addTest(new TestSuite(PR58.class));
return suite;
}
--- /dev/null
+/* tests/regression/bugzilla/PR58.java
+
+ Copyright (C) 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+*/
+
+
+import junit.framework.*;
+import junit.textui.*;
+
+import java.io.*;
+
+public class PR58 extends TestCase {
+ public static void main(String[] args) {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ return new TestSuite(PR58.class);
+ }
+
+ class x extends y {}
+ class y {}
+
+ public void test() {
+ // Delete the class file which is extended.
+ new File("PR58$y.class").delete();
+
+ try {
+ Class.forName("PR58$x");
+ fail("Should throw NoClassDefFoundError");
+ }
+ catch (ClassNotFoundException error) {
+ fail("Unexpected exception: " + error);
+ }
+ catch (NoClassDefFoundError success) {
+ // Check if the cause is correct.
+ assertTrue(success.getCause() instanceof ClassNotFoundException);
+ }
+ }
+}