void java_lang_VMClass_initialize(struct Hjava_lang_Class* c) { errorInfo einfo; if (processClass(c, CSTATE_COMPLETE, &einfo) == false) { throwError(&einfo); } }
/** * Allocate an object and execute the constructor. * * @param cname the name of the class to be instantiated (may be 0 if cc is != 0) * @param loader the class loader that's to be used to lookup the class * @param cc the class to be instantiated (may be 0 if cname is != 0) * @param signature the signature of the constructor to be executed * @param argptr arguments to be passed to the constructor * * @throws InstantiationException if class is an interface or abstract * @throws NoSuchMethodError if the specified constructor cannot be found * * @return the newly allocated object */ Hjava_lang_Object* execute_java_constructor_v(const char* cname, Hjava_lang_ClassLoader* loader, Hjava_lang_Class* cc, const char* signature, va_list argptr) { Hjava_lang_Object* obj; Method* mb; jvalue retval; errorInfo info; Utf8Const* sig; if (cc == 0) { char *buf; /* Convert "." to "/" and lookup class */ buf = checkPtr(KMALLOC(strlen(cname) + 1)); classname2pathname(cname, buf); cc = lookupClass(buf, loader, &info); KFREE(buf); if (!cc) { throwError(&info); } } /* We cannot construct interfaces or abstract classes */ if (CLASS_IS_INTERFACE(cc) || CLASS_IS_ABSTRACT(cc)) { throwException(InstantiationException(cc->name->data)); } if (cc->state < CSTATE_USABLE) { if (processClass(cc, CSTATE_COMPLETE, &info) == false) { throwError(&info); } } sig = checkPtr(utf8ConstFromString(signature)); mb = findMethodLocal(cc, constructor_name, sig); utf8ConstRelease(sig); if (mb == 0) { throwException(NoSuchMethodError(constructor_name->data)); } obj = newObject(cc); assert(obj != 0); /* Make the call */ KaffeVM_callMethodV(mb, METHOD_NATIVECODE(mb), obj, argptr, &retval); return (obj); }
static void findTag (tokenInfo *const token) { if (currentContext->kind != K_UNDEFINED) { /* Drop context, but only if an end token is found */ dropContext (token); } if (token->kind == K_CONSTANT && vStringItem (token->name, 0) == '`') { /* Bug #961001: Verilog compiler directives are line-based. */ int c = skipWhite (vGetc ()); readIdentifier (token, c); createTag (token); /* Skip the rest of the line. */ do { c = vGetc(); } while (c != EOF && c != '\n'); vUngetc (c); } else if (token->kind == K_BLOCK) { /* Process begin..end blocks */ processBlock (token); } else if (token->kind == K_FUNCTION || token->kind == K_TASK) { /* Functions are treated differently because they may also include the * type of the return value. * Tasks are treated in the same way, although not having a return * value.*/ processFunction (token); } else if (token->kind == K_ASSERTION) { if (vStringLength (currentContext->blockName) > 0) { vStringCopy (token->name, currentContext->blockName); createTag (token); skipToSemiColon (); } } else if (token->kind == K_TYPEDEF) { processTypedef (token); } else if (token->kind == K_CLASS) { processClass (token); } else if (token->kind == K_IGNORE && isSingleStatement (token)) { currentContext->singleStat = TRUE; } else if (isVariable (token)) { int c = skipWhite (vGetc ()); tagNameList (token, c); } else if (token->kind != K_UNDEFINED && token->kind != K_IGNORE) { int c = skipWhite (vGetc ()); if (isIdentifierCharacter (c)) { readIdentifier (token, c); while (getKind (token) == K_IGNORE) { c = skipWhite (vGetc ()); readIdentifier (token, c); } createTag (token); /* Get port list if required */ c = skipWhite (vGetc ()); if (c == '(' && hasSimplePortList (token)) { processPortList (c); } else { vUngetc (c); } } } }
/* * Convert string name to class object. */ struct Hjava_lang_Class* java_lang_VMClass_forName0(struct Hjava_lang_String* str, struct Hjava_lang_ClassLoader* loader) { errorInfo einfo; Hjava_lang_Class* clazz; Utf8Const *utf8buf; const char *buf; int jlen; jchar *js; /* * NB: internally, we store class names as path names (with slashes * instead of dots. However, we must also prevent calls to * "java/lang/Object" or "[[Ljava/lang/Object;" from succeeding. * Since class names cannot have slashes, we reject all attempts * to look up names that do. Awkward. Inefficient. */ js = STRING_DATA(str); jlen = STRING_SIZE(str); while (--jlen > 0) { if (*js++ == '/') { postExceptionMessage(&einfo, JAVA_LANG(ClassNotFoundException), "Cannot have slashes - use dots instead."); throwError(&einfo); } } /* * Note the following oddity: * * It is apparently perfectly legal to call forName for array types, * such as "[Ljava.lang.String;" or "[B". * However, it is wrong to call Class.forName("Ljava.lang.String;") * * This situation is similar to the constant pool resolution. We * therefore do the same thing as in getClass in kaffevm/lookup.c, * that is, use either loadArray or loadClass depending on the name. * * This is somewhat described in Section 5.1.3 of the VM * Specification, titled "Array Classes". This section seems to * imply that we must avoid asking a class loader to resolve such * array names (those starting with an [), and this is what calling * loadArray does. */ /* Convert string to utf8, converting '.' to '/' */ utf8buf = checkPtr(stringJava2Utf8ConstReplace(str, '.', '/')); buf = utf8buf->data; if (buf[0] == '[') { clazz = loadArray(utf8buf, loader, &einfo); } else { clazz = loadClass(utf8buf, loader, &einfo); } /* if an error occurred, throw an exception */ if (clazz == 0) { utf8ConstRelease(utf8buf); throwError(&einfo); } utf8ConstRelease(utf8buf); /* * loadClass returns the class in state CSTATE_LINKED. * * Processing to CSTATE_COMPLETE will initialize the class, resolve * its constants and run its static initializers. * * The option to load a class via forName without initializing it * was introduced in 1.2, presumably for the convenience of * programs such as stub compilers. */ if (processClass(clazz, CSTATE_COMPLETE, &einfo) == false) { throwError(&einfo); } return (clazz); }
void AdaptJClassLoad(JNIEnv *env_id, const char *name, const char *src_name, jint num_interfaces, jint num_methods, JVMPI_Method *methods, jint num_static_fields, JVMPI_Field *statics, int num_instance_fields, JVMPI_Field *instances, jobjectID class_id, jint requested) { AdaptJEvent eventID; byte *byteBuff; byte *b; size_t bLength = 0; size_t buffSize; /* Computed buffer size for malloc() */ size_t tmpLen; jint i; jshort s; processClass(name, num_methods, methods, class_id); s = eventInfo[ADAPTJ_CLASS_LOAD]; /* Calculate buffer size */ buffSize = 1; if (s & ADAPTJ_FIELD_ENV_ID) { buffSize += 4; } if (s & ADAPTJ_FIELD_CLASS_NAME) { buffSize += strlen(name) + 2; } if (s & ADAPTJ_FIELD_SOURCE_NAME) { if (src_name == NULL) { src_name = "(null)"; } buffSize += strlen(src_name) + 2; } if (s & ADAPTJ_FIELD_NUM_INTERFACES) { buffSize += 4; } if ((s & ADAPTJ_FIELD_NUM_METHODS) || (s & ADAPTJ_FIELD_METHODS)) { buffSize += 4; } if (s & ADAPTJ_FIELD_METHODS) { for (i = 0; i < num_methods; i++) { buffSize += strlen(methods[i].method_name) + 2; buffSize += strlen(methods[i].method_signature) + 2; buffSize += 12; } } if ((s & ADAPTJ_FIELD_NUM_STATIC_FIELDS) || (s & ADAPTJ_FIELD_STATICS)) { buffSize += 4; } if (s & ADAPTJ_FIELD_STATICS) { for (i = 0; i < num_static_fields; i++) { buffSize += strlen(statics[i].field_name) + 2; buffSize += strlen(statics[i].field_signature) + 2; } } if ((s & ADAPTJ_FIELD_NUM_INSTANCE_FIELDS) || (s & ADAPTJ_FIELD_INSTANCES)) { buffSize += 4; } if (s & ADAPTJ_FIELD_INSTANCES) { for (i = 0; i < num_instance_fields; i++) { buffSize += strlen(instances[i].field_name) + 2; buffSize += strlen(instances[i].field_signature) + 2; } } if (s & ADAPTJ_FIELD_CLASS_LOAD_CLASS_ID) { buffSize += 4; } /* Allocate buffer */ byteBuff = (byte *) malloc(buffSize); b = byteBuff; /* Write Data to Buffer */ eventID = ADAPTJ_CLASS_LOAD; if (requested) { eventID |= ADAPTJ_REQUESTED_EVENT; } ADAPTJ_WRITE_BYTE(((byte)eventID), b, bLength); if (s & ADAPTJ_FIELD_ENV_ID) { ADAPTJ_WRITE_JINT(((jint)env_id), b, bLength); } if (s & ADAPTJ_FIELD_CLASS_NAME) { tmpLen = strlen(name); ADAPTJ_WRITE_UTF8(name, tmpLen, b, bLength); } if (s & ADAPTJ_FIELD_SOURCE_NAME) { tmpLen = strlen(src_name); ADAPTJ_WRITE_UTF8(src_name, tmpLen, b, bLength); } if (s & ADAPTJ_FIELD_NUM_INTERFACES) { ADAPTJ_WRITE_JINT(num_interfaces, b, bLength); } /* FIXME no interfaces array?? */ if ((s & ADAPTJ_FIELD_NUM_METHODS) || (s & ADAPTJ_FIELD_METHODS)) { ADAPTJ_WRITE_JINT(num_methods, b, bLength); } if (s & ADAPTJ_FIELD_METHODS) { for (i = 0; i < num_methods; i++) { tmpLen = strlen(methods[i].method_name); ADAPTJ_WRITE_UTF8(methods[i].method_name, tmpLen, b, bLength); tmpLen = strlen(methods[i].method_signature); ADAPTJ_WRITE_UTF8(methods[i].method_signature, tmpLen, b, bLength); ADAPTJ_WRITE_JINT(methods[i].start_lineno, b, bLength); ADAPTJ_WRITE_JINT(methods[i].end_lineno, b, bLength); ADAPTJ_WRITE_JINT(((jint)methods[i].method_id), b, bLength); } } if ((s & ADAPTJ_FIELD_NUM_STATIC_FIELDS) || (s & ADAPTJ_FIELD_STATICS)) { ADAPTJ_WRITE_JINT(num_static_fields, b, bLength); } if (s & ADAPTJ_FIELD_STATICS) { for (i = 0; i < num_static_fields; i++) { tmpLen = strlen(statics[i].field_name); ADAPTJ_WRITE_UTF8(statics[i].field_name, tmpLen, b, bLength); tmpLen = strlen(statics[i].field_signature); ADAPTJ_WRITE_UTF8(statics[i].field_signature, tmpLen, b, bLength); } } if ((s & ADAPTJ_FIELD_NUM_INSTANCE_FIELDS) || (s & ADAPTJ_FIELD_INSTANCES)) { ADAPTJ_WRITE_JINT(num_instance_fields, b, bLength); } if (s & ADAPTJ_FIELD_INSTANCES) { for (i = 0; i < num_instance_fields; i++) { tmpLen = strlen(instances[i].field_name); ADAPTJ_WRITE_UTF8(instances[i].field_name, tmpLen, b, bLength); tmpLen = strlen(instances[i].field_signature); ADAPTJ_WRITE_UTF8(instances[i].field_signature, tmpLen, b, bLength); } } if (s & ADAPTJ_FIELD_CLASS_LOAD_CLASS_ID) { ADAPTJ_WRITE_JINT(((jint)class_id), b, bLength); } fileBytes += bLength; #ifdef ADAPTJ_WRITE_OUTPUT fwrite(byteBuff, 1, bLength, outputFile); #endif free(byteBuff); }