jclass.c
static jint tagClasses(ClassModule * classModule, jvmtiEnv * jvmti,
		jlong beginTag) {
	jvmtiError err;
	jclass *jclasses;
	int jclassCount;
	classInfo *classInfos;
	int i;
	jint rc = JNI_OK;

	err = (*jvmti)->GetLoadedClasses(jvmti, &jclassCount, &jclasses);
	CHECK_ERROR_AND_RETURN(jvmti, err, "get loaded classes", JNI_ERR);

	classInfos = calloc(sizeof(classInfo), jclassCount);
	memset(classInfos, 0, sizeof(classInfo) * jclassCount);
	if (classInfos != NULL) {
		for (i = 0; i < jclassCount; i++) {
			char * sig = NULL;
			int tag = i + beginTag;
			err = (*jvmti)->GetClassSignature(jvmti, jclasses[i], &sig, NULL);
			print_if_error(jvmti, err, "get class signature");
			if (err == JVMTI_ERROR_NONE && sig != NULL) {
				if (strcmp(sig, "Ljava/lang/Class;") == 0) {
					classModule->jclassTag = tag;
				}
				classInfos[i].classSig = strdup(sig);
				deallocate(jvmti, sig);
				err = (*jvmti)->SetTag(jvmti, jclasses[i], tag);
				print_if_error(jvmti, err, "set object tag");
			}
		}
		classModule->classes = classInfos;
		classModule->classCount = jclassCount;
	} else {
		ulog("out of memory\n");
		rc = JNI_ERR;
	}
	deallocate(jvmti, jclasses);
	return rc;
}
/**
 * Get all classes from VM, and set the tag.
 */
Get all classes from VM, and set the tag.
Get all classes from VM and set the tag .
static jint tagClasses(ClassModule * classModule, jvmtiEnv * jvmti,
		jlong beginTag) {
	jvmtiError err;
	jclass *jclasses;
	int jclassCount;
	classInfo *classInfos;
	int i;
	jint rc = JNI_OK;
	err = (*jvmti)->GetLoadedClasses(jvmti, &jclassCount, &jclasses);
	CHECK_ERROR_AND_RETURN(jvmti, err, "get loaded classes", JNI_ERR);
	classInfos = calloc(sizeof(classInfo), jclassCount);
	memset(classInfos, 0, sizeof(classInfo) * jclassCount);
	if (classInfos != NULL) {
		for (i = 0; i < jclassCount; i++) {
			char * sig = NULL;
			int tag = i + beginTag;
			err = (*jvmti)->GetClassSignature(jvmti, jclasses[i], &sig, NULL);
			print_if_error(jvmti, err, "get class signature");
			if (err == JVMTI_ERROR_NONE && sig != NULL) {
				if (strcmp(sig, "Ljava/lang/Class;") == 0) {
					classModule->jclassTag = tag;
				}
				classInfos[i].classSig = strdup(sig);
				deallocate(jvmti, sig);
				err = (*jvmti)->SetTag(jvmti, jclasses[i], tag);
				print_if_error(jvmti, err, "set object tag");
			}
		}
		classModule->classes = classInfos;
		classModule->classCount = jclassCount;
	} else {
		ulog("out of memory\n");
		rc = JNI_ERR;
	}
	deallocate(jvmti, jclasses);
	return rc;
}
static jint tagClasses ( ClassModule * classModule , jvmtiEnv * jvmti , jlong beginTag ) { jvmtiError err ; jclass * jclasses ; int jclassCount ; classInfo * classInfos ; int i ; jint rc = JNI_OK ; err = ( * jvmti ) -> GetLoadedClasses ( jvmti , & jclassCount , & jclasses ) ; CHECK_ERROR_AND_RETURN ( jvmti , err , " " , JNI_ERR ) ; classInfos = calloc ( sizeof ( classInfo ) , jclassCount ) ; memset ( classInfos , 0 , sizeof ( classInfo ) * jclassCount ) ; if ( classInfos != NULL ) { for ( i = 0 ; i < jclassCount ; i ++ ) { char * sig = NULL ; int tag = i + beginTag ; err = ( * jvmti ) -> GetClassSignature ( jvmti , jclasses [ i ] , & sig , NULL ) ; print_if_error ( jvmti , err , " " ) ; if ( err == JVMTI_ERROR_NONE && sig != NULL ) { if ( strcmp ( sig , " " ) == 0 ) { classModule -> jclassTag = tag ; } classInfos [ i ] . classSig = strdup ( sig ) ; deallocate ( jvmti , sig ) ; err = ( * jvmti ) -> SetTag ( jvmti , jclasses [ i ] , tag ) ; print_if_error ( jvmti , err , " " ) ; } } classModule -> classes = classInfos ; classModule -> classCount = jclassCount ; } else { ulog ( " \n " ) ; rc = JNI_ERR ; } deallocate ( jvmti , jclasses ) ; return rc ; }
Get all classes from VM, and set the tag.
Get all classes from VM and set the tag .