+// 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);
+}
+