hprof_class.c

来自「一个小公司要求给写的很简单的任务管理系统。」· C语言 代码 · 共 674 行 · 第 1/2 页

C
674
字号
    return create_entry(&key);}voidclass_prime_system_classes(void){    /* Prime System classes? Anything before VM_START is System class.     *   Or classes loaded before env arg is non-NULL.     *   Or any of the classes listed below.     */    static const char * signatures[] =              {            "Ljava/lang/Object;",            "Ljava/io/Serializable;",            "Ljava/lang/String;",            "Ljava/lang/Class;",            "Ljava/lang/ClassLoader;",            "Ljava/lang/System;",            "Ljava/lang/Thread;",            "Ljava/lang/ThreadGroup;",        };    int n_signatures;    int i;    LoaderIndex loader_index;       n_signatures = (int)sizeof(signatures)/(int)sizeof(signatures[0]);    loader_index = loader_find_or_create(NULL, NULL);    for ( i = 0 ; i < n_signatures ; i++ ) {        ClassInfo  *info;        ClassIndex  index;	ClassKey    key;		fillin_pkey(signatures[i], loader_index, &key);        index = find_or_create_entry(&key);        info = get_info(index);        info->status |= CLASS_SYSTEM;    }}voidclass_add_status(ClassIndex index, ClassStatus status){    ClassInfo *info;    info = get_info(index);    info->status |= status;}ClassStatusclass_get_status(ClassIndex index){    ClassInfo *info;    info = get_info(index);    return info->status;}StringIndexclass_get_signature(ClassIndex index){    ClassKey *pkey;    pkey = get_pkey(index);    return pkey->sig_string_index;}SerialNumberclass_get_serial_number(ClassIndex index){    ClassInfo *info;    if ( index == 0 ) {	return 0;    }    info = get_info(index);    return info->serial_num;}voidclass_all_status_remove(ClassStatus status){    table_walk_items(gdata->class_table, &all_status_remove, 		(void*)(ptrdiff_t)(long)status);}voidclass_do_unloads(JNIEnv *env){    table_walk_items(gdata->class_table, &unload_walker, (void*)env);}voidclass_list(void){    debug_message(         "--------------------- Class Table ------------------------\n");    table_walk_items(gdata->class_table, &list_item, NULL);    debug_message(         "----------------------------------------------------------\n");}voidclass_cleanup(void){    table_cleanup(gdata->class_table, &cleanup_item, NULL);    gdata->class_table = NULL;}voidclass_delete_global_references(JNIEnv* env){    table_walk_items(gdata->class_table, &delete_ref_item, (void*)env);}voidclass_set_methods(ClassIndex index, const char **name, const char **sig, 			int count){    ClassInfo *info;    int        i;    info               = get_info(index);    if ( info->method_count > 0 ) {        HPROF_FREE((void*)info->method);	info->method_count = 0;        info->method       = NULL;    }    info->method_count = count;    if ( count > 0 ) {	info->method = (MethodInfo *)HPROF_MALLOC(count*(int)sizeof(MethodInfo));	for ( i = 0 ; i < count ; i++ ) {	    info->method[i].name_index = string_find_or_create(name[i]); 	    info->method[i].sig_index  = string_find_or_create(sig[i]);	    info->method[i].method_id  = NULL;	}    }}jclassclass_new_classref(JNIEnv *env, ClassIndex index, jclass classref){    ClassInfo *info;        HPROF_ASSERT(classref!=NULL);    info = get_info(index);    if ( ! isSameObject(env, classref, info->classref) ) {        delete_classref(env, info, classref);    }    return info->classref;}jclassclass_get_class(JNIEnv *env, ClassIndex index){    ClassInfo *info;    jclass     clazz;        info 	= get_info(index);    clazz 	= info->classref;    if ( env != NULL && clazz == NULL ) {	WITH_LOCAL_REFS(env, 1) {	    jclass   new_clazz;	    char    *class_name;	    	    class_name = string_get(info->name);	    /* This really only makes sense for the bootclass classes, 	     *   since FindClass doesn't provide a way to load a class in	     *   a specific class loader.	     */	    new_clazz = findClass(env, class_name);	    if ( new_clazz == NULL ) {		HPROF_ERROR(JNI_TRUE, "Cannot load class with findClass");	    }	    HPROF_ASSERT(new_clazz!=NULL);	    clazz = class_new_classref(env, index, new_clazz);	} END_WITH_LOCAL_REFS;        HPROF_ASSERT(clazz!=NULL);    }    return clazz;}jmethodIDclass_get_methodID(JNIEnv *env, ClassIndex index, MethodIndex mnum){    ClassInfo *info;    jmethodID  method;        info = get_info(index);    HPROF_ASSERT(mnum < info->method_count);    method = info->method[mnum].method_id;    if ( method == NULL ) {        char * name;        char * sig;        jclass clazz;                name  = (char *)string_get(info->method[mnum].name_index);        HPROF_ASSERT(name!=NULL);        sig   = (char *)string_get(info->method[mnum].sig_index);        HPROF_ASSERT(sig!=NULL);        clazz = class_get_class(env, index);	if ( clazz != NULL ) {	    method = getMethodID(env, clazz, name, sig);	    HPROF_ASSERT(method!=NULL);	    info = get_info(index);	    info->method[mnum].method_id = method;	}    }    return method;}voidclass_set_inst_size(ClassIndex index, jint inst_size){    ClassInfo *info;        info = get_info(index);    info->inst_size = inst_size;}jintclass_get_inst_size(ClassIndex index){    ClassInfo *info;        info = get_info(index);    return info->inst_size;}voidclass_set_object_index(ClassIndex index, ObjectIndex object_index){    ClassInfo *info;        info = get_info(index);    info->object_index = object_index;}ObjectIndexclass_get_object_index(ClassIndex index){    ClassInfo *info;        info = get_info(index);    return info->object_index;}ClassIndex	class_get_super(ClassIndex index){    ClassInfo *info;        info = get_info(index);    return info->super;}void	class_set_super(ClassIndex index, ClassIndex super){    ClassInfo *info;        info = get_info(index);    info->super = super;}LoaderIndex     class_get_loader(ClassIndex index){    ClassKey *pkey;    pkey = get_pkey(index);    HPROF_ASSERT(pkey->loader_index!=0);    return pkey->loader_index;}/* Get ALL class fields (supers too), return 1 on error, 0 if ok */jintclass_get_all_fields(JNIEnv *env, ClassIndex index,                jint *pfield_count, FieldInfo **pfield){    ClassInfo  *info;    FieldInfo  *finfo;    jint        count;    jint        ret;        count = 0;    finfo = NULL;    ret   = 1;       /* Default is to return an error condition */        info = get_info(index);    if ( info != NULL ) {        if ( info->field_count >= 0 ) {	    /* Get cache */	    count = info->field_count;	    finfo = info->field;	    ret   = 0;                 /* Return of cache data, no error */        } else {	    jclass     klass;    		    klass = info->classref;	    if ( klass == NULL || isSameObject(env, klass, NULL) ) {	        /* This is probably an error because this will cause the field	         *    index values to be off, but I'm hesitant to generate a	         *    fatal error here, so I will issue something and continue.	         *    I should have been holding a global reference to all the	         *    jclass, so I'm not sure how this could happen.		 *    Issuing a FindClass() here is just asking for trouble		 *    because if the class went away, we aren't even sure		 *    what ClassLoader to use.	         */	        HPROF_ERROR(JNI_FALSE, "Missing jclass when fields needed");	    } else {		jint status;		status = getClassStatus(klass);		if ( status & 		    (JVMTI_CLASS_STATUS_PRIMITIVE|JVMTI_CLASS_STATUS_ARRAY) ) {		    /* Set cache */		    info->field_count = count;		    info->field       = finfo;		    ret               = 0;      /* Primitive or array ok */		} else if ( status & JVMTI_CLASS_STATUS_PREPARED ) {		    /* Call JVMTI to get them */		    getAllClassFieldInfo(env, klass, &count, &finfo);		    /* Set cache */		    info->field_count = count;		    info->field       = finfo;		    ret               = 0;		}	    }        }    }    *pfield_count = count;    *pfield       = finfo;    return ret;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?