- }
-
- /* check flag consistency */
- if (m->name != utf_clinit) {
- i = (m->flags & (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED));
-
- if (i != 0 && i != ACC_PUBLIC && i != ACC_PRIVATE && i != ACC_PROTECTED) {
- *exceptionptr =
- new_classformaterror(c,
- "Illegal method modifiers: 0x%X",
- m->flags);
- return false;
- }
-
- if (m->flags & ACC_ABSTRACT) {
- if ((m->flags & (ACC_FINAL | ACC_NATIVE | ACC_PRIVATE |
- ACC_STATIC | ACC_STRICT | ACC_SYNCHRONIZED))) {
- *exceptionptr =
- new_classformaterror(c,
- "Illegal method modifiers: 0x%X",
- m->flags);
- return false;
- }
- }
-
- if (c->flags & ACC_INTERFACE) {
- if ((m->flags & (ACC_ABSTRACT | ACC_PUBLIC)) != (ACC_ABSTRACT | ACC_PUBLIC)) {
- *exceptionptr =
- new_classformaterror(c,
- "Illegal method modifiers: 0x%X",
- m->flags);
- return false;
- }
- }
-
- if (m->name == utf_init) {
- if (m->flags & (ACC_STATIC | ACC_FINAL | ACC_SYNCHRONIZED |
- ACC_NATIVE | ACC_ABSTRACT))
- panic("Instance initialization method has invalid flags set");
- }
- }
- }
-
- m->jcode = NULL;
- m->basicblockcount = 0;
- m->basicblocks = NULL;
- m->basicblockindex = NULL;
- m->instructioncount = 0;
- m->instructions = NULL;
- m->stackcount = 0;
- m->stack = NULL;
- m->exceptiontable = NULL;
- m->registerdata = NULL;
- m->stubroutine = NULL;
- m->mcode = NULL;
- m->entrypoint = NULL;
- m->methodUsed = NOTUSED;
- m->monoPoly = MONO;
- m->subRedefs = 0;
- m->subRedefsUsed = 0;
-
- m->xta = NULL;
-
- if (!(m->flags & ACC_NATIVE)) {
- m->stubroutine = createcompilerstub(m);
-
- } else {
- functionptr f = native_findfunction(c->name, m->name, m->descriptor,
- (m->flags & ACC_STATIC) != 0);
- if (f) {
- m->stubroutine = createnativestub(f, m);
- }
- }
-
- if (!check_classbuffer_size(cb, 2))
- return false;
-
- attrnum = suck_u2(cb);
- for (i = 0; i < attrnum; i++) {
- utf *aname;
-
- if (!check_classbuffer_size(cb, 2))
- return false;
-
- if (!(aname = class_getconstant(c, suck_u2(cb), CONSTANT_Utf8)))
- return false;
-
- if (aname == utf_code) {
- if (m->flags & (ACC_ABSTRACT | ACC_NATIVE)) {
- *exceptionptr =
- new_classformaterror(c,
- "Code attribute in native or abstract methods");
-
- return false;
- }
-
- if (m->jcode) {
- *exceptionptr =
- new_classformaterror(c, "Multiple Code attributes");
-
- return false;
- }
-
- if (!check_classbuffer_size(cb, 4 + 2 + 2))
- return false;
-
- suck_u4(cb);
- m->maxstack = suck_u2(cb);
- m->maxlocals = suck_u2(cb);
-
- if (m->maxlocals < argcount) {
- *exceptionptr =
- new_classformaterror(c, "Arguments can't fit into locals");
-
- return false;
- }
-
- if (!check_classbuffer_size(cb, 4))
- return false;
-
- m->jcodelength = suck_u4(cb);
-
- if (m->jcodelength == 0) {
- *exceptionptr =
- new_classformaterror(c, "Code of a method has length 0");
-
- return false;
- }
-
- if (m->jcodelength > 65535) {
- *exceptionptr =
- new_classformaterror(c,
- "Code of a method longer than 65535 bytes");
-
- return false;
- }
-
- if (!check_classbuffer_size(cb, m->jcodelength))
- return false;
-
- m->jcode = MNEW(u1, m->jcodelength);
- suck_nbytes(m->jcode, cb, m->jcodelength);
-
- if (!check_classbuffer_size(cb, 2))
- return false;
-
- m->exceptiontablelength = suck_u2(cb);
-
- if (!check_classbuffer_size(cb, (2 + 2 + 2 + 2) * m->exceptiontablelength))
- return false;
-
- m->exceptiontable = MNEW(exceptiontable, m->exceptiontablelength);
-
-#if defined(STATISTICS)
- if (opt_stat) {
- count_vmcode_len += m->jcodelength + 18;
- count_extable_len += 8 * m->exceptiontablelength;
- }
-#endif
-
- for (j = 0; j < m->exceptiontablelength; j++) {
- u4 idx;
- m->exceptiontable[j].startpc = suck_u2(cb);
- m->exceptiontable[j].endpc = suck_u2(cb);
- m->exceptiontable[j].handlerpc = suck_u2(cb);
-
- idx = suck_u2(cb);
- if (!idx) {
- m->exceptiontable[j].catchtype = NULL;
-
- } else {
- if (!(m->exceptiontable[j].catchtype =
- class_getconstant(c, idx, CONSTANT_Class)))
- return false;
- }
- }
-
- if (!check_classbuffer_size(cb, 2))
- return false;
-
- codeattrnum = suck_u2(cb);
-
- for (; codeattrnum > 0; codeattrnum--) {
- utf *caname;
-
- if (!check_classbuffer_size(cb, 2))
- return false;
-
- if (!(caname = class_getconstant(c, suck_u2(cb), CONSTANT_Utf8)))
- return false;
-
- if (caname == utf_linenumbertable) {
- u2 lncid;
-
- if (!check_classbuffer_size(cb, 4 + 2))
- return false;
-
- suck_u4(cb);
- m->linenumbercount = suck_u2(cb);
-
- if (!check_classbuffer_size(cb,
- (2 + 2) * m->linenumbercount))
- return false;
-
- m->linenumbers = MNEW(lineinfo, m->linenumbercount);
-
- for (lncid = 0; lncid < m->linenumbercount; lncid++) {
- m->linenumbers[lncid].start_pc = suck_u2(cb);
- m->linenumbers[lncid].line_number = suck_u2(cb);
- }
- codeattrnum--;
-
- if (!skipattributes(cb, codeattrnum))
- return false;
-
- break;
-
- } else {
- if (!skipattributebody(cb))
- return false;
- }
- }
-
- } else if (aname == utf_exceptions) {
- s4 j;
-
- if (m->thrownexceptions) {
- *exceptionptr =
- new_classformaterror(c, "Multiple Exceptions attributes");
- return false;
- }
-
- if (!check_classbuffer_size(cb, 4 + 2))
- return false;
-
- suck_u4(cb); /* length */
- m->thrownexceptionscount = suck_u2(cb);
-
- if (!check_classbuffer_size(cb, 2 * m->thrownexceptionscount))
- return false;
-
- m->thrownexceptions = MNEW(classinfo*, m->thrownexceptionscount);
-
- for (j = 0; j < m->thrownexceptionscount; j++) {
- if (!((m->thrownexceptions)[j] =
- class_getconstant(c, suck_u2(cb), CONSTANT_Class)))
- return false;
- }
-
- } else {
- if (!skipattributebody(cb))
- return false;
- }
- }
-
- if (!m->jcode && !(m->flags & (ACC_ABSTRACT | ACC_NATIVE))) {
- *exceptionptr = new_classformaterror(c, "Missing Code attribute");
-
- return false;
- }
-
- /* everything was ok */
-
- return true;
-}
-
-
-/********************* Function: method_free ***********************************
-
- frees all memory that was allocated for this method
-
-*******************************************************************************/
-
-static void method_free(methodinfo *m)
-{
- if (m->jcode)
- MFREE(m->jcode, u1, m->jcodelength);
-
- if (m->exceptiontable)
- MFREE(m->exceptiontable, exceptiontable, m->exceptiontablelength);
-
- if (m->mcode)
- CFREE(m->mcode, m->mcodelength);
-
- if (m->stubroutine) {
- if (m->flags & ACC_NATIVE) {
- removenativestub(m->stubroutine);
-
- } else {
- removecompilerstub(m->stubroutine);
- }
- }
-}
-
-
-/************** Function: method_display (debugging only) **************/
-
-void method_display(methodinfo *m)
-{
- printf(" ");
- printflags(m->flags);
- printf(" ");
- utf_display(m->name);
- printf(" ");
- utf_display(m->descriptor);
- printf("\n");
-}
-
-/************** Function: method_display_flags_last (debugging only) **************/
-
-void method_display_flags_last(methodinfo *m)
-{
- printf(" ");
- utf_display(m->name);
- printf(" ");
- utf_display(m->descriptor);
- printf(" ");
- printflags(m->flags);
- printf("\n");
-}
-
-
-/******************** Function: method_canoverwrite ****************************
-
- Check if m and old are identical with respect to type and name. This means
- that old can be overwritten with m.
-
-*******************************************************************************/
-
-static bool method_canoverwrite(methodinfo *m, methodinfo *old)
-{
- if (m->name != old->name) return false;
- if (m->descriptor != old->descriptor) return false;
- if (m->flags & ACC_STATIC) return false;
- return true;
-}
-
-
-/******************** function: class_loadcpool ********************************
-
- loads the constantpool of a class,
- the entries are transformed into a simpler format
- by resolving references
- (a detailed overview of the compact structures can be found in global.h)
-
-*******************************************************************************/
-
-static bool class_loadcpool(classbuffer *cb, classinfo *c)
-{
-
- /* The following structures are used to save information which cannot be
- processed during the first pass. After the complete constantpool has
- been traversed the references can be resolved.
- (only in specific order) */
-
- /* CONSTANT_Class entries */
- typedef struct forward_class {
- struct forward_class *next;
- u2 thisindex;
- u2 name_index;
- } forward_class;
-
- /* CONSTANT_String */
- typedef struct forward_string {
- struct forward_string *next;
- u2 thisindex;
- u2 string_index;
- } forward_string;
-
- /* CONSTANT_NameAndType */
- typedef struct forward_nameandtype {
- struct forward_nameandtype *next;
- u2 thisindex;
- u2 name_index;
- u2 sig_index;
- } forward_nameandtype;
-
- /* CONSTANT_Fieldref, CONSTANT_Methodref or CONSTANT_InterfaceMethodref */
- typedef struct forward_fieldmethint {
- struct forward_fieldmethint *next;
- u2 thisindex;
- u1 tag;
- u2 class_index;
- u2 nameandtype_index;
- } forward_fieldmethint;
-
-
- u4 idx;
-
- forward_class *forward_classes = NULL;
- forward_string *forward_strings = NULL;
- forward_nameandtype *forward_nameandtypes = NULL;
- forward_fieldmethint *forward_fieldmethints = NULL;
-
- forward_class *nfc;
- forward_string *nfs;
- forward_nameandtype *nfn;
- forward_fieldmethint *nff;
-
- u4 cpcount;
- u1 *cptags;
- voidptr *cpinfos;
-
- /* number of entries in the constant_pool table plus one */
- if (!check_classbuffer_size(cb, 2))
- return false;
-
- cpcount = c->cpcount = suck_u2(cb);
-
- /* allocate memory */
- cptags = c->cptags = MNEW(u1, cpcount);
- cpinfos = c->cpinfos = MNEW(voidptr, cpcount);
-
- if (cpcount < 1) {
- *exceptionptr = new_classformaterror(c, "Illegal constant pool size");
- return false;
- }
-
-#if defined(STATISTICS)
- if (opt_stat)
- count_const_pool_len += (sizeof(voidptr) + 1) * cpcount;
-#endif
-
- /* initialize constantpool */
- for (idx = 0; idx < cpcount; idx++) {
- cptags[idx] = CONSTANT_UNUSED;
- cpinfos[idx] = NULL;
- }
-
-
- /******* first pass *******/
- /* entries which cannot be resolved now are written into
- temporary structures and traversed again later */
-
- idx = 1;
- while (idx < cpcount) {
- u4 t;
-
- /* get constant type */
- if (!check_classbuffer_size(cb, 1))
- return false;
-
- t = suck_u1(cb);
-
- switch (t) {
- case CONSTANT_Class:
- nfc = NEW(forward_class);
-
- nfc->next = forward_classes;
- forward_classes = nfc;
-
- nfc->thisindex = idx;
- /* reference to CONSTANT_NameAndType */
- if (!check_classbuffer_size(cb, 2))
- return false;
-
- nfc->name_index = suck_u2(cb);
-
- idx++;
- break;
-
- case CONSTANT_String:
- nfs = NEW(forward_string);
-
- nfs->next = forward_strings;
- forward_strings = nfs;
-
- nfs->thisindex = idx;
-
- /* reference to CONSTANT_Utf8_info with string characters */
- if (!check_classbuffer_size(cb, 2))
- return false;
-
- nfs->string_index = suck_u2(cb);
-
- idx++;
- break;
-
- case CONSTANT_NameAndType:
- nfn = NEW(forward_nameandtype);
-
- nfn->next = forward_nameandtypes;
- forward_nameandtypes = nfn;
-
- nfn->thisindex = idx;
-
- if (!check_classbuffer_size(cb, 2 + 2))
- return false;
-
- /* reference to CONSTANT_Utf8_info containing simple name */
- nfn->name_index = suck_u2(cb);
-
- /* reference to CONSTANT_Utf8_info containing field or method
- descriptor */
- nfn->sig_index = suck_u2(cb);
-
- idx++;
- break;
-
- case CONSTANT_Fieldref:
- case CONSTANT_Methodref:
- case CONSTANT_InterfaceMethodref:
- nff = NEW(forward_fieldmethint);
-
- nff->next = forward_fieldmethints;
- forward_fieldmethints = nff;
-
- nff->thisindex = idx;
- /* constant type */
- nff->tag = t;
-
- if (!check_classbuffer_size(cb, 2 + 2))
- return false;
-
- /* class or interface type that contains the declaration of the
- field or method */
- nff->class_index = suck_u2(cb);
-
- /* name and descriptor of the field or method */
- nff->nameandtype_index = suck_u2(cb);
-
- idx++;
- break;
-
- case CONSTANT_Integer: {
- constant_integer *ci = NEW(constant_integer);
-
-#if defined(STATISTICS)
- if (opt_stat)
- count_const_pool_len += sizeof(constant_integer);
-#endif
-
- if (!check_classbuffer_size(cb, 4))
- return false;
-
- ci->value = suck_s4(cb);
- cptags[idx] = CONSTANT_Integer;
- cpinfos[idx] = ci;
-
- idx++;
- break;
- }
-
- case CONSTANT_Float: {
- constant_float *cf = NEW(constant_float);
-
-#if defined(STATISTICS)
- if (opt_stat)
- count_const_pool_len += sizeof(constant_float);
-#endif
-
- if (!check_classbuffer_size(cb, 4))
- return false;
-
- cf->value = suck_float(cb);
- cptags[idx] = CONSTANT_Float;
- cpinfos[idx] = cf;
-
- idx++;
- break;
- }
-
- case CONSTANT_Long: {
- constant_long *cl = NEW(constant_long);
-
-#if defined(STATISTICS)
- if (opt_stat)
- count_const_pool_len += sizeof(constant_long);
-#endif
-
- if (!check_classbuffer_size(cb, 8))
- return false;
-
- cl->value = suck_s8(cb);
- cptags[idx] = CONSTANT_Long;
- cpinfos[idx] = cl;
- idx += 2;
- if (idx > cpcount) {
- *exceptionptr =
- new_classformaterror(c, "Invalid constant pool entry");
- return false;
- }
- break;
- }
-
- case CONSTANT_Double: {
- constant_double *cd = NEW(constant_double);
-
-#if defined(STATISTICS)
- if (opt_stat)
- count_const_pool_len += sizeof(constant_double);
-#endif
-
- if (!check_classbuffer_size(cb, 8))
- return false;
-
- cd->value = suck_double(cb);
- cptags[idx] = CONSTANT_Double;
- cpinfos[idx] = cd;
- idx += 2;
- if (idx > cpcount) {
- *exceptionptr =
- new_classformaterror(c, "Invalid constant pool entry");
- return false;
- }
- break;
- }
-
- case CONSTANT_Utf8: {
- u4 length;
-
- /* number of bytes in the bytes array (not string-length) */
- if (!check_classbuffer_size(cb, 2))
- return false;
-
- length = suck_u2(cb);
- cptags[idx] = CONSTANT_Utf8;
-
- /* validate the string */
- if (!check_classbuffer_size(cb, length))
- return false;
-
- if (opt_verify &&
- !is_valid_utf(cb->pos + 1, cb->pos + 1 + length)) {
- dolog("Invalid UTF-8 string (constant pool index %d)",idx);
- panic("Invalid UTF-8 string");
- }
- /* insert utf-string into the utf-symboltable */
- cpinfos[idx] = utf_new_intern(cb->pos + 1, length);
-
- /* skip bytes of the string (buffer size check above) */
- skip_nbytes(cb, length);
- idx++;
- break;
- }
-
- default:
- *exceptionptr =
- new_classformaterror(c, "Illegal constant pool type");
- return false;
- } /* end switch */
- } /* end while */
-
-
- /* resolve entries in temporary structures */
-
- while (forward_classes) {
- utf *name =
- class_getconstant(c, forward_classes->name_index, CONSTANT_Utf8);
-
- if (opt_verify && !is_valid_name_utf(name))
- panic("Class reference with invalid name");
-
- cptags[forward_classes->thisindex] = CONSTANT_Class;
- /* retrieve class from class-table */
- if (opt_eager) {
- classinfo *tc;
- tc = class_new_intern(name);
-
- if (!class_load(tc))
- return false;
-
- /* link the class later, because we cannot link the class currently
- loading */
- list_addfirst(&unlinkedclasses, tc);
-
- cpinfos[forward_classes->thisindex] = tc;
-
- } else {
- cpinfos[forward_classes->thisindex] = class_new(name);
- }
-
- nfc = forward_classes;
- forward_classes = forward_classes->next;
- FREE(nfc, forward_class);
- }
-
- while (forward_strings) {
- utf *text =
- class_getconstant(c, forward_strings->string_index, CONSTANT_Utf8);
-
- /* resolve utf-string */
- cptags[forward_strings->thisindex] = CONSTANT_String;
- cpinfos[forward_strings->thisindex] = text;
-
- nfs = forward_strings;
- forward_strings = forward_strings->next;
- FREE(nfs, forward_string);
- }
-
- while (forward_nameandtypes) {
- constant_nameandtype *cn = NEW(constant_nameandtype);
-
-#if defined(STATISTICS)
- if (opt_stat)
- count_const_pool_len += sizeof(constant_nameandtype);
-#endif
-
- /* resolve simple name and descriptor */
- cn->name = class_getconstant(c,
- forward_nameandtypes->name_index,
- CONSTANT_Utf8);
-
- cn->descriptor = class_getconstant(c,
- forward_nameandtypes->sig_index,
- CONSTANT_Utf8);
-
- if (opt_verify) {
- /* check name */
- if (!is_valid_name_utf(cn->name))
- panic("NameAndType with invalid name");
- /* disallow referencing <clinit> among others */
- if (cn->name->text[0] == '<' && cn->name != utf_init)
- panic("NameAndType with invalid special name");
- }
-
- cptags[forward_nameandtypes->thisindex] = CONSTANT_NameAndType;
- cpinfos[forward_nameandtypes->thisindex] = cn;
-
- nfn = forward_nameandtypes;
- forward_nameandtypes = forward_nameandtypes->next;
- FREE(nfn, forward_nameandtype);
- }
-
- while (forward_fieldmethints) {
- constant_nameandtype *nat;
- constant_FMIref *fmi = NEW(constant_FMIref);
-
-#if defined(STATISTICS)
- if (opt_stat)
- count_const_pool_len += sizeof(constant_FMIref);
-#endif
- /* resolve simple name and descriptor */
- nat = class_getconstant(c,
- forward_fieldmethints->nameandtype_index,
- CONSTANT_NameAndType);
-
- fmi->class = class_getconstant(c,
- forward_fieldmethints->class_index,
- CONSTANT_Class);
- fmi->name = nat->name;
- fmi->descriptor = nat->descriptor;
-
- cptags[forward_fieldmethints->thisindex] = forward_fieldmethints->tag;
- cpinfos[forward_fieldmethints->thisindex] = fmi;
-
- switch (forward_fieldmethints->tag) {
- case CONSTANT_Fieldref: /* check validity of descriptor */
- checkfielddescriptor(fmi->descriptor->text,
- utf_end(fmi->descriptor));
- break;
- case CONSTANT_InterfaceMethodref:
- case CONSTANT_Methodref: /* check validity of descriptor */
- checkmethoddescriptor(c, fmi->descriptor);
- break;
- }
-
- nff = forward_fieldmethints;
- forward_fieldmethints = forward_fieldmethints->next;
- FREE(nff, forward_fieldmethint);
- }
-
- /* everything was ok */
-
- return true;
-}
-
-
-/********************** Function: class_load ***********************************
-
- Loads everything interesting about a class from the class file. The
- 'classinfo' structure must have been allocated previously.
-
- The super class and the interfaces implemented by this class need not be
- loaded. The link is set later by the function 'class_link'.
-
- The loaded class is removed from the list 'unloadedclasses' and added to
- the list 'unlinkedclasses'.
-
-*******************************************************************************/
-
-classinfo *class_load_intern(classbuffer *cb);
-
-classinfo *class_load(classinfo *c)
-{
- classbuffer *cb;
- classinfo *r;
-
- /* enter a monitor on the class */
-
- builtin_monitorenter((java_objectheader *) c);
-
- /* maybe the class is already loaded */
- if (c->loaded) {
- builtin_monitorexit((java_objectheader *) c);
-
- return c;
- }
-
- /* measure time */
-
- if (getcompilingtime)
- compilingtime_stop();
-
- if (getloadingtime)
- loadingtime_start();
-
- /* load classdata, throw exception on error */
-
- if ((cb = suck_start(c)) == NULL) {
- /* this means, the classpath was not set properly */
- if (c->name == utf_java_lang_Object)
- throw_cacao_exception_exit(string_java_lang_NoClassDefFoundError,
- "java/lang/Object");
-
- *exceptionptr =
- new_exception_utfmessage(string_java_lang_NoClassDefFoundError,
- c->name);
-
- builtin_monitorexit((java_objectheader *) c);
-
- return NULL;
- }
-
- /* call the internal function */
- r = class_load_intern(cb);
-
- /* if return value is NULL, we had a problem and the class is not loaded */
- if (!r) {
- c->loaded = false;
-
- /* now free the allocated memory, otherwise we could ran into a DOS */
- class_remove(c);
- }
-
- /* free memory */
- suck_stop(cb);
-
- /* measure time */
-
- if (getloadingtime)
- loadingtime_stop();
-
- if (getcompilingtime)
- compilingtime_start();
-
- /* leave the monitor */
-
- builtin_monitorexit((java_objectheader *) c);
-
- return r;
-}
-
-
-classinfo *class_load_intern(classbuffer *cb)
-{
- classinfo *c;
- classinfo *tc;
- u4 i;
- u4 ma, mi;
- char msg[MAXLOGTEXT]; /* maybe we get an exception */
-
- /* get the classbuffer's class */
- c = cb->class;
-
- /* maybe the class is already loaded */
- if (c->loaded)
- return c;
-
-#if defined(STATISTICS)
- if (opt_stat)
- count_class_loads++;
-#endif
-
- /* output for debugging purposes */
- if (loadverbose)
- log_message_class("Loading class: ", c);
-
- /* class is somewhat loaded */
- c->loaded = true;
-
- if (!check_classbuffer_size(cb, 4 + 2 + 2))
- return NULL;
-
- /* check signature */
- if (suck_u4(cb) != MAGIC) {
- *exceptionptr = new_classformaterror(c, "Bad magic number");
-
- return NULL;
- }
-
- /* check version */
- mi = suck_u2(cb);
- ma = suck_u2(cb);
-
- if (!(ma < MAJOR_VERSION || (ma == MAJOR_VERSION && mi <= MINOR_VERSION))) {
- *exceptionptr =
- new_unsupportedclassversionerror(c,
- "Unsupported major.minor version %d.%d",
- ma, mi);
-
- return NULL;
- }
-
- /* load the constant pool */
- if (!class_loadcpool(cb, c))
- return NULL;
-
- /*JOWENN*/
- c->erroneous_state = 0;
- c->initializing_thread = 0;
- /*JOWENN*/
- c->classUsed = NOTUSED; /* not used initially CO-RT */
- c->impldBy = NULL;
-
- /* ACC flags */
- if (!check_classbuffer_size(cb, 2))
- return NULL;
-
- c->flags = suck_u2(cb);
- /*if (!(c->flags & ACC_PUBLIC)) { log_text("CLASS NOT PUBLIC"); } JOWENN*/
-
- /* check ACC flags consistency */
- if (c->flags & ACC_INTERFACE) {
- if (!(c->flags & ACC_ABSTRACT)) {
- /* We work around this because interfaces in JDK 1.1 are
- * not declared abstract. */
-
- c->flags |= ACC_ABSTRACT;
- /* panic("Interface class not declared abstract"); */
- }
-
- if (c->flags & ACC_FINAL) {
- *exceptionptr =
- new_classformaterror(c,
- "Illegal class modifiers: 0x%X", c->flags);
-
- return NULL;
- }
-
- if (c->flags & ACC_SUPER) {
- c->flags &= ~ACC_SUPER; /* kjc seems to set this on interfaces */
- }
- }
-
- if ((c->flags & (ACC_ABSTRACT | ACC_FINAL)) == (ACC_ABSTRACT | ACC_FINAL)) {
- *exceptionptr =
- new_classformaterror(c, "Illegal class modifiers: 0x%X", c->flags);
-
- return NULL;
- }
-
- if (!check_classbuffer_size(cb, 2 + 2))
- return NULL;
-
- /* this class */
- i = suck_u2(cb);
- if (!(tc = class_getconstant(c, i, CONSTANT_Class)))
- return NULL;
-
- if (tc != c) {
- utf_sprint(msg, c->name);
- sprintf(msg + strlen(msg), " (wrong name: ");
- utf_sprint(msg + strlen(msg), tc->name);
- sprintf(msg + strlen(msg), ")");
-
- *exceptionptr =
- new_exception_message(string_java_lang_NoClassDefFoundError, msg);
-
- return NULL;
- }
-
- /* retrieve superclass */
- if ((i = suck_u2(cb))) {
- if (!(c->super = class_getconstant(c, i, CONSTANT_Class)))
- return NULL;
-
- /* java.lang.Object may not have a super class. */
- if (c->name == utf_java_lang_Object) {
- *exceptionptr =
- new_exception_message(string_java_lang_ClassFormatError,
- "java.lang.Object with superclass");
-
- return NULL;
- }
-
- /* Interfaces must have java.lang.Object as super class. */
- if ((c->flags & ACC_INTERFACE) &&
- c->super->name != utf_java_lang_Object) {
- *exceptionptr =
- new_exception_message(string_java_lang_ClassFormatError,
- "Interfaces must have java.lang.Object as superclass");
-
- return NULL;
- }
-
- } else {
- c->super = NULL;
-
- /* This is only allowed for java.lang.Object. */
- if (c->name != utf_java_lang_Object) {
- *exceptionptr = new_classformaterror(c, "Bad superclass index");
-
- return NULL;
- }
- }
-
- /* retrieve interfaces */
- if (!check_classbuffer_size(cb, 2))
- return NULL;
-
- c->interfacescount = suck_u2(cb);
-
- if (!check_classbuffer_size(cb, 2 * c->interfacescount))
- return NULL;
-
- c->interfaces = MNEW(classinfo*, c->interfacescount);
- for (i = 0; i < c->interfacescount; i++) {
- if (!(c->interfaces[i] = class_getconstant(c, suck_u2(cb), CONSTANT_Class)))
- return NULL;
- }
-
- /* load fields */
- if (!check_classbuffer_size(cb, 2))
- return NULL;
-
- c->fieldscount = suck_u2(cb);
- c->fields = GCNEW(fieldinfo, c->fieldscount);
-/* c->fields = MNEW(fieldinfo, c->fieldscount); */
- for (i = 0; i < c->fieldscount; i++) {
- if (!field_load(cb, c, &(c->fields[i])))
- return NULL;
- }
-
- /* load methods */
- if (!check_classbuffer_size(cb, 2))
- return NULL;
-
- c->methodscount = suck_u2(cb);
- c->methods = GCNEW(methodinfo, c->methodscount);
-/* c->methods = MNEW(methodinfo, c->methodscount); */
- for (i = 0; i < c->methodscount; i++) {
- if (!method_load(cb, c, &(c->methods[i])))
- return NULL;
- }
-
- /* Check if all fields and methods can be uniquely
- * identified by (name,descriptor). */
- if (opt_verify) {
- /* We use a hash table here to avoid making the
- * average case quadratic in # of methods, fields.
- */
- static int shift = 0;
- u2 *hashtab;
- u2 *next; /* for chaining colliding hash entries */
- size_t len;
- size_t hashlen;
- u2 index;
- u2 old;
-
- /* Allocate hashtable */
- len = c->methodscount;
- if (len < c->fieldscount) len = c->fieldscount;
- hashlen = 5 * len;
- hashtab = MNEW(u2,(hashlen + len));
- next = hashtab + hashlen;
-
- /* Determine bitshift (to get good hash values) */
- if (!shift) {
- len = sizeof(utf);
- while (len) {
- len >>= 1;
- shift++;
- }
- }
-
- /* Check fields */
- memset(hashtab, 0, sizeof(u2) * (hashlen + len));
-
- for (i = 0; i < c->fieldscount; ++i) {
- fieldinfo *fi = c->fields + i;
-
- /* It's ok if we lose bits here */
- index = ((((size_t) fi->name) +
- ((size_t) fi->descriptor)) >> shift) % hashlen;
-
- if ((old = hashtab[index])) {
- old--;
- next[i] = old;
- do {
- if (c->fields[old].name == fi->name &&
- c->fields[old].descriptor == fi->descriptor) {
- *exceptionptr =
- new_classformaterror(c,
- "Repetitive field name/signature");
-
- return NULL;
- }
- } while ((old = next[old]));
- }
- hashtab[index] = i + 1;
- }
-
- /* Check methods */
- memset(hashtab, 0, sizeof(u2) * (hashlen + len));
-
- for (i = 0; i < c->methodscount; ++i) {
- methodinfo *mi = c->methods + i;
-
- /* It's ok if we lose bits here */
- index = ((((size_t) mi->name) +
- ((size_t) mi->descriptor)) >> shift) % hashlen;
-
- if ((old = hashtab[index])) {
- old--;
- next[i] = old;
- do {
- if (c->methods[old].name == mi->name &&
- c->methods[old].descriptor == mi->descriptor) {
- *exceptionptr =
- new_classformaterror(c,
- "Repetitive method name/signature");
-
- return NULL;
- }
- } while ((old = next[old]));
- }
- hashtab[index] = i + 1;
- }
-
- MFREE(hashtab, u2, (hashlen + len));
- }
-
-#if defined(STATISTICS)
- if (opt_stat) {
- count_class_infos += sizeof(classinfo*) * c->interfacescount;
- count_class_infos += sizeof(fieldinfo) * c->fieldscount;
- count_class_infos += sizeof(methodinfo) * c->methodscount;
- }
-#endif
-
- /* load attribute structures */
- if (!check_classbuffer_size(cb, 2))
- return NULL;
-
- if (!attribute_load(cb, c, suck_u2(cb)))
- return NULL;
-
-#if 0
- /* Pre java 1.5 version don't check this. This implementation is like
- java 1.5 do it: for class file version 45.3 we don't check it, older
- versions are checked.
- */
- if ((ma == 45 && mi > 3) || ma > 45) {
- /* check if all data has been read */
- s4 classdata_left = ((cb->data + cb->size) - cb->pos - 1);
-
- if (classdata_left > 0) {
- *exceptionptr =
- new_classformaterror(c, "Extra bytes at the end of class file");
- return NULL;
- }
- }
-#endif
-
- if (loadverbose)
- log_message_class("Loading done class: ", c);
-
- return c;
-}
-
-