diff options
author | rschuster <rschuster@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-02-01 13:40:05 +0000 |
---|---|---|
committer | rschuster <rschuster@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-02-01 13:40:05 +0000 |
commit | b07ed7feb8f9fc07ef1fd0a9e181446f0d432559 (patch) | |
tree | 331725f44321f544a0c7d62882b65627f0e43522 /libjava/prims.cc | |
parent | 06d9b28a09242827b83c60e3d94ca5c2fa2db6cd (diff) | |
download | linaro-gcc-b07ed7feb8f9fc07ef1fd0a9e181446f0d432559.tar.gz linaro-gcc-b07ed7feb8f9fc07ef1fd0a9e181446f0d432559.tar.bz2 linaro-gcc-b07ed7feb8f9fc07ef1fd0a9e181446f0d432559.zip |
2006-02-01 Robert Schuster <robertschuster@fsfe.org>
* link.cc:
(_Jv_Linker::find_field_helper): Added checks.
(_Jv_Linker::find_field): Use exception swallowing class resolution
and added early return.
(_Jv_ThrowNoClassDefFoundErrorTrampoline): New function.
(_Jv_Linker::link_symbol_table): Use exception swallowing class
resolution, added ffi_closure installation routine, use
_Jv_ThrowNoClassDefFoundError for missing static method.
(_Jv_Linker::ensure_class_linked): Added string check which does
not trigger class resolution.
* java/lang/natClassLoader.cc:
(_Jv_FindClassNoException): New method.
* java/lang/Class.h:
(_Jv_FindClassNoException): New method declaration.
* include/jvm.h:
(_Jv_FindClassNoException): New method declaration.
(_Jv_FindClassFromSignatureNoException): New method declaration.
* prims.cc:
(_Jv_FindClassFromSignatureNoException): New method.
* gcj/javaprims.h:
(_Jv_equalsUtf8Classname): New method declaration.
(_Jv_isPrimitiveOrDerived): Dito.
* prims.cc:
(_Jv_equalsUtf8Classnames): New method.
(_Jv_isPrimitiveOrDerived): New method.
* verify.cc:
(ref_intersection::equals): Use new classname comparison method.
(type::compatible): Use new classname comparison method. Added
check whether LHS' type is java.lang.Object .
(type::resolve): Added new optional debug message and simplified
if-expression.
(type::to_array): Added codepath that generates an array type
without resolving the element type.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@110474 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/prims.cc')
-rw-r--r-- | libjava/prims.cc | 148 |
1 files changed, 146 insertions, 2 deletions
diff --git a/libjava/prims.cc b/libjava/prims.cc index a968a9b3013..0352669315d 100644 --- a/libjava/prims.cc +++ b/libjava/prims.cc @@ -49,8 +49,10 @@ details. */ #include <java/lang/ArrayIndexOutOfBoundsException.h> #include <java/lang/ArithmeticException.h> #include <java/lang/ClassFormatError.h> +#include <java/lang/ClassNotFoundException.h> #include <java/lang/InternalError.h> #include <java/lang/NegativeArraySizeException.h> +#include <java/lang/NoClassDefFoundError.h> #include <java/lang/NullPointerException.h> #include <java/lang/OutOfMemoryError.h> #include <java/lang/System.h> @@ -168,7 +170,6 @@ SIGNAL_HANDLER (catch_fpe) } #endif - jboolean _Jv_equalUtf8Consts (const Utf8Const* a, const Utf8Const *b) @@ -236,6 +237,120 @@ _Jv_equaln (Utf8Const *a, jstring str, jint n) return true; } +// Determines whether the given Utf8Const object contains +// a type which is primitive or some derived form of it, eg. +// an array or multi-dimensional array variant. +jboolean +_Jv_isPrimitiveOrDerived(const Utf8Const *a) +{ + unsigned char *aptr = (unsigned char *) a->data; + unsigned char *alimit = aptr + a->length; + int ac = UTF8_GET(aptr, alimit); + + // Skips any leading array marks. + while (ac == '[') + ac = UTF8_GET(aptr, alimit); + + // There should not be another character. This implies that + // the type name is only one character long. + if (UTF8_GET(aptr, alimit) == -1) + switch ( ac ) + { + case 'Z': + case 'B': + case 'C': + case 'S': + case 'I': + case 'J': + case 'F': + case 'D': + return true; + default: + break; + } + + return false; +} + +// Find out whether two _Jv_Utf8Const candidates contain the same +// classname. +// The method is written to handle the different formats of classnames. +// Eg. "Ljava/lang/Class;", "Ljava.lang.Class;", "java/lang/Class" and +// "java.lang.Class" will be seen as equal. +// Warning: This function is not smart enough to declare "Z" and "boolean" +// and similar cases as equal (and is not meant to be used this way)! +jboolean +_Jv_equalUtf8Classnames (const Utf8Const *a, const Utf8Const *b) +{ + // If the class name's length differs by two characters + // it is possible that we have candidates which are given + // in the two different formats ("Lp1/p2/cn;" vs. "p1/p2/cn") + switch (a->length - b->length) + { + case -2: + case 0: + case 2: + break; + default: + return false; + } + + unsigned char *aptr = (unsigned char *) a->data; + unsigned char *alimit = aptr + a->length; + unsigned char *bptr = (unsigned char *) b->data; + unsigned char *blimit = bptr + b->length; + + if (alimit[-1] == ';') + alimit--; + + if (blimit[-1] == ';') + blimit--; + + int ac = UTF8_GET(aptr, alimit); + int bc = UTF8_GET(bptr, blimit); + + // Checks whether both strings have the same amount of leading [ characters. + while (ac == '[') + { + if (bc == '[') + { + ac = UTF8_GET(aptr, alimit); + bc = UTF8_GET(bptr, blimit); + continue; + } + + return false; + } + + // Skips leading L character. + if (ac == 'L') + ac = UTF8_GET(aptr, alimit); + + if (bc == 'L') + bc = UTF8_GET(bptr, blimit); + + // Compares the remaining characters. + while (ac != -1 && bc != -1) + { + // Replaces package separating dots with slashes. + if (ac == '.') + ac = '/'; + + if (bc == '.') + bc = '/'; + + // Now classnames differ if there is at least one non-matching + // character. + if (ac != bc) + return false; + + ac = UTF8_GET(aptr, alimit); + bc = UTF8_GET(bptr, blimit); + } + + return (ac == bc); +} + /* Count the number of Unicode chars encoded in a given Ut8 string. */ int _Jv_strLengthUtf8(char* str, int len) @@ -434,6 +549,9 @@ _Jv_AllocObjectNoInitNoFinalizer (jclass klass) jobject _Jv_AllocObjectNoFinalizer (jclass klass) { + if (_Jv_IsPhantomClass(klass) ) + throw new java::lang::NoClassDefFoundError(klass->getName()); + _Jv_InitClass (klass); jint size = klass->size (); jobject obj = (jobject) _Jv_AllocObj (size, klass); @@ -512,6 +630,11 @@ _Jv_AllocPtrFreeObject (jclass klass) jobjectArray _Jv_NewObjectArray (jsize count, jclass elementClass, jobject init) { + // Creating an array of an unresolved type is impossible. So we throw + // the NoClassDefFoundError. + if ( _Jv_IsPhantomClass(elementClass) ) + throw new java::lang::NoClassDefFoundError(elementClass->getName()); + if (__builtin_expect (count < 0, false)) throw new java::lang::NegativeArraySizeException; @@ -766,7 +889,28 @@ _Jv_FindClassFromSignature (char *sig, java::lang::ClassLoader *loader, return result; } - + +jclass +_Jv_FindClassFromSignatureNoException (char *sig, java::lang::ClassLoader *loader, + char **endp) +{ + jclass klass; + + try + { + klass = _Jv_FindClassFromSignature(sig, loader, endp); + } + catch (java::lang::NoClassDefFoundError *ncdfe) + { + return NULL; + } + catch (java::lang::ClassNotFoundException *cnfe) + { + return NULL; + } + + return klass; +} JArray<jstring> * JvConvertArgv (int argc, const char **argv) |