📄 support.c
字号:
BEGIN_EXCEPTION_HANDLING_VOID(); KaffeVM_callMethodV(meth, func, obj, args, ret); END_EXCEPTION_HANDLING();}/** * q:: *//** * Lookup a method given class, name and signature. * * @param cls the class where to start search * @param name name of the method being searched * @param sig signature of the method being searched * @param einfo struct errorInfo * * @throws OutOfMemoryError * * @return struct _jmethodID of the method being searched or 0 in case of an error */Method*lookupClassMethod(Hjava_lang_Class* cls, const char* name, const char* sig, bool declared, errorInfo *einfo){ Method *meth; Utf8Const *name_utf8, *sig_utf8; assert(cls != NULL); assert(name != NULL); assert(sig != NULL); name_utf8 = utf8ConstFromString(name); if (!name_utf8) { postOutOfMemory(einfo); return NULL; } sig_utf8 = utf8ConstFromString(sig); if (!sig_utf8) { utf8ConstRelease(name_utf8); postOutOfMemory(einfo); return NULL; } if (declared) meth = KaffeVM_findDeclaredMethod(cls, name_utf8, sig_utf8, einfo); else meth = findMethod(cls, name_utf8, sig_utf8, einfo); utf8ConstRelease(name_utf8); utf8ConstRelease(sig_utf8); return(meth);}/** * Lookup a method given object, name and signature. * * @param obj the object where to start search * @param name name of the method being searched * @param sig signature of the method being searched * @param einfo struct errorInfo * * @return struct _jmethodID of the method being searched or 0 in case of an error */Method*lookupObjectMethod(Hjava_lang_Object* obj, const char* name, const char* sig, errorInfo *einfo){ assert(obj != NULL && name != NULL && sig != NULL); return (lookupClassMethod(OBJECT_CLASS(obj), name, sig, false, einfo));}/** * Signal an error by creating the object and throwing the exception. * See also SignalErrorf * * @param cname the name of the class of the exception object to be created * @param str the message to be passed to the constructor of the exception object */voidSignalError(const char* cname, const char* str){ Hjava_lang_Throwable* obj; if (str == NULL || *str == '\0') { obj = (Hjava_lang_Throwable*)execute_java_constructor(cname, NULL, NULL, ERROR_SIGNATURE0); } else { obj = (Hjava_lang_Throwable*)execute_java_constructor(cname, NULL, NULL, ERROR_SIGNATURE, checkPtr(stringC2Java(str))); } throwException(obj);}/** * Signal an error by creating the object and throwing the exception. * allows for printf-like msg format with additional parameters. * * @param cname the name of the class of the exception object to be created * @param fmt the printf like format of the message * @param ... the parameters necessary for the message format denoted by fmt */voidSignalErrorf(const char* cname, const char* fmt, ...){ errorInfo info; va_list args; va_start(args, fmt); vpostExceptionMessage(&info, cname, fmt, args); va_end(args); throwError(&info);}static voidreplacechar(const char* from, char* to, char old, char new){ int i; /* Convert any 'old' in name to 'new' */ for (i = 0; from[i] != 0; i++) { if (from[i] == old) { to[i] = new; } else { to[i] = from[i]; } } to[i] = 0;}/** * Convert a class name to a path name. * * @param from points to the class name * @param to points to path name */voidclassname2pathname(const char* from, char* to){ replacechar(from, to, '.', '/');}/** * Convert a path name to a class name. * * @param from points to the path name * @param to points to the class name */voidpathname2classname(const char* from, char* to){ replacechar(from, to, '/', '.');}/** * Return current time in milliseconds. */jlongcurrentTime(void){ jlong tme;#if defined(HAVE_GETTIMEOFDAY) struct timeval tm; gettimeofday(&tm, NULL); tme = (((jlong)tm.tv_sec * (jlong)1000) + ((jlong)tm.tv_usec / (jlong)1000));#elif defined(HAVE_FTIME) struct timeb tm; ftime(&tm); tme = (((jlong)tm.time * (jlong)1000) + (jlong)tm.millitm);#elif defined(HAVE__FTIME) struct timeb tm; _ftime(&tm); tme = (((jlong)tm.time * (jlong)1000) + (jlong)tm.millitm);#elif defined(HAVE_TIME) tme = (jlong)1000 * (jlong)time(0);#else tme = 0;#endif return (tme);}/** * Allocate a new object of the given class name. * * @param classname the name of the class to be instantiated * @param loader the loader to be used to lookup the class * * @return the newly allocated object */Hjava_lang_Object*AllocObject(const char* classname, Hjava_lang_ClassLoader* loader){ Hjava_lang_Class* clazz; errorInfo info; clazz = lookupClass(classname, loader, &info); if (clazz == 0) { throwError(&info); } return (newObject(clazz));}/** * Allocate a new array of a given size and type. * * @param len the size of the array * @param type the type of the elements of the array. * * @return the new allocated array */Hjava_lang_Object*AllocArray(jsize len, int type){ return (newArray(TYPE_CLASS(type), len));}/** * Allocate a new array of the given size and class name. * * @param sz the size of the array * @param classname name of the class of the elements * @param loader the class loader to be used to lookup the class * * @return the newly allocated array * * @throws NegativeArraySizeException iff the size<0 */Hjava_lang_Object*AllocObjectArray(int sz, const char* classname, Hjava_lang_ClassLoader* loader){ Hjava_lang_Class *elclass; errorInfo info; if (sz < 0) { throwException(NegativeArraySizeException); } elclass = getClassFromSignature(classname, loader, &info); if (elclass == 0) { throwError(&info); } return (newArray(elclass, sz));}/** * Used to generate exception for unimplemented features. * * @param mess the message to be displayed * * @throws an InternalError */voidunimp(const char* mess){ SignalError("java.lang.InternalError", mess);}/** * Print messages. * * @param out the FILE* to write the message to * @param mess the printf like format of the message * @param ... the parameters needed for the format */voidkprintf(FILE* out, const char* mess, ...){ va_list argptr; va_start(argptr, mess); Kaffe_JavaVMArgs.jni_vfprintf(out, mess, argptr); va_end(argptr);}/** * Enter/leave critical region. This interface is exported to * native libraries to protect calls to non-reentrant functions. * It works as a global masterlock for C libraries that are not * thread-safe. */void enterUnsafeRegion(void){ KTHREAD(spinon)(NULL);}void leaveUnsafeRegion(void){ KTHREAD(spinoff)(NULL);}/* XXX Ick */int bitCount(int bits){ unsigned int lpc; int retval = 0; for( lpc = 0; lpc < (sizeof(int) * 8); lpc++ ) { if( (1L << lpc) & bits ) retval++; } return( retval );}/** * Return a pointer to a field. * * @param declaring_class class declaring the field * @param instance object contaning the field * @param slot index of the field in the fields array */volatile void * KaffeVM_GetFieldAddress(jclass declaring_class, jobject instance, jlong slot) { Field* fld; Hjava_lang_Class * clazz = (Hjava_lang_Class *) declaring_class; /* Get the declaring class' field descriptor located at the given slot */ fld = CLASS_FIELDS(clazz) + slot; /* If the field is static, complete return its address */ if (slot < CLASS_NSFIELDS(clazz)) { errorInfo einfo; /* If the instanca type is not completely initialized, initialize it now. */ if (!processClass(clazz, CSTATE_COMPLETE, &einfo)) { throwError(&einfo); } return FIELD_ADDRESS(fld); } else { /* If the field is not static, compute its address based on the location of the instance, and return it. */ if (instance == NULL) { SignalError("java.lang.NullPointerException", ""); } if (!soft_instanceof(declaring_class, instance)) { SignalError("java.lang.IllegalArgumentException",""); } return (void*)(((char*)(instance)) + FIELD_BOFFSET(fld)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -