示例#1
0
jclass deprecated_getJavaLangClass(u2 requestedClassId) {
	BEGIN;
	int i;
	int j;
	int index = 0;

	// Calculate the index into the array 'javaLangClassArray':
	for (i = 0; i < numberOfAllClassReferences; i++) {
		// The candidate for java.lang.Class generation:
		u2 classId = allClassReferences[i].targetClassId;
		if (requestedClassId == classId) {
			break;
		}

		// Verify that it hasn't been generated before:
		BOOL found = FALSE;
		for (j = 0; j < i - 1 && !found; j++) {
			found = allClassReferences[j].targetClassId == classId;
		}

		if (!found) {
			index++;
		}
	}

	return (jclass) GetObjectArrayElement(javaLangClassArray, index);
}
示例#2
0
static void sDumpObject(header_t* h) {
    if (0 <= h->e.classId && h->e.classId < cpNumberOfAllClassInstanceInfo) {
        if (isObjectArray(h->e.classId)) {
            jobjectArray oa = (jobjectArray) getObjectFromHeader(h);
            size_t length = GetArrayLength((jarray) oa);
            size_t i;
            for (i = 0; i < length; i++) {
                jobject obj = GetObjectArrayElement(NULL, oa, i);
                header_t* oh = getHeader(obj);
                consout("    [%d] %p\n", i, oh);
            }
        }
    }
    // else: Class Id out of range; can't dump
}
示例#3
0
USER_OBJECT_ 
RS_JAVA(MethodConverter)(jobject obj, jclass type, JNIEnv *env, RSFromJavaConverter *converter)
{
 int i = 0, k, n;
 int numSlots;
 USER_OBJECT_ ans, names;
 const char *tmp;

 jboolean isCopy;
 jstring jval;
 jclass klass;
 jobject jsig, jobj;
 ReflectanceMethodIDs *mids;
 boolean isMethod;
 jint modifier;

 if(ModifierStringID == NULL)
  initReflectanceMethods(env);

  /* Determine whether we have a constructor or method
     and set the method identifiers and number of slots
     appropriately.
   */
 isMethod = VMENV IsSameObject(env, type, VMENV FindClass(env, "java/lang/reflect/Method")) == JNI_TRUE;

 if(isMethod) {
   mids = &MethodIDs;
   numSlots = 6;
 } else {
   mids = &ConstructorIDs;
   numSlots = 5; /* Drop out the */
 }
 
 
 PROTECT(ans = NEW_LIST(numSlots));
 PROTECT(names = NEW_CHARACTER(numSlots));
 
 SET_VECTOR_ELT(ans, i, NEW_CHARACTER(1));
 jval = VMENV CallObjectMethod(env, obj, mids->getName);
 tmp = VMENV GetStringUTFChars(env, jval, &isCopy);  
 SET_STRING_ELT(VECTOR_ELT(ans, i), 0, COPY_TO_USER_STRING(tmp));
 if(isCopy)
   VMENV ReleaseStringUTFChars(env, jval, tmp);
 SET_STRING_ELT(names, i, COPY_TO_USER_STRING("name"));
 i++;

 SET_VECTOR_ELT(ans, i, NEW_CHARACTER(1));
 klass = VMENV CallObjectMethod(env, obj, mids->getClass);
 tmp = getClassName(env, klass, &isCopy);
 SET_STRING_ELT(VECTOR_ELT(ans, i), 0, COPY_TO_USER_STRING(tmp));
 SET_STRING_ELT(names, i, COPY_TO_USER_STRING("Declaring class")); 
 i++;


 jsig = VMENV CallObjectMethod(env, obj, mids->getParameters);
 n = VMENV GetArrayLength(env, jsig);
 SET_VECTOR_ELT(ans, i, NEW_CHARACTER(n));
 for(k = 0; k < n ; k++) {
   jobj = VMENV GetObjectArrayElement(env, jsig, k);
   tmp = getClassName(env, jobj, &isCopy);
   SET_STRING_ELT(VECTOR_ELT(ans, i), k, COPY_TO_USER_STRING(tmp));
 }
 SET_STRING_ELT(names, i, COPY_TO_USER_STRING("Parameters"));    
 i++;

 
 SET_VECTOR_ELT(ans, i, NEW_INTEGER(1));
 modifier = VMENV CallIntMethod(env, obj, mids->getModifiers);
 INTEGER_DATA(VECTOR_ELT(ans, i))[0] = modifier;
 SET_STRING_ELT(names, i, COPY_TO_USER_STRING("Modifiers"));
 {
      /* Now get the string that represents the modifier value.
         Do this by calling the static method toString(int)
         in the java.lang.reflect.Modifier class.
         We assume we have initialized the ModifierStringID
         method id earlier when getting all the method ids
         for the reflectance classes.
       */
   USER_OBJECT_ tmpr;
   const char *modName;
   jstring jmodName;
    PROTECT(tmpr = NEW_CHARACTER(1));
    jmodName = VMENV CallStaticObjectMethod(env, (jclass)VMENV FindClass(env, "java/lang/reflect/Modifier"), ModifierStringID, modifier);

   if(jmodName != NULL_JAVA_OBJECT) {
      modName = VMENV GetStringUTFChars(env, jmodName, &isCopy);   
      SET_STRING_ELT(tmpr, 0, COPY_TO_USER_STRING(modName));
    }
    SET_NAMES(VECTOR_ELT(ans, i), tmpr);
    UNPROTECT(1);
 }
 i++;


 jsig = VMENV CallObjectMethod(env, obj, mids->getExceptions);
 n = VMENV GetArrayLength(env, jsig);
 SET_VECTOR_ELT(ans, i, NEW_CHARACTER(n));
 for(k = 0; k < n ; k++) {
   jobj = VMENV GetObjectArrayElement(env, jsig, k);
   tmp = getClassName(env, jobj, &isCopy);
   SET_STRING_ELT(VECTOR_ELT(ans, i), k, COPY_TO_USER_STRING(tmp));
 }
 SET_STRING_ELT(names, i, COPY_TO_USER_STRING("Exceptions"));    
 i++;

 

 if(isMethod) {
   SET_VECTOR_ELT(ans, i, NEW_CHARACTER(1));
   klass = VMENV CallObjectMethod(env, obj, mids->getReturnType);
   tmp = getClassName(env, klass, &isCopy);
   SET_VECTOR_ELT(VECTOR_ELT(ans, i), 0, COPY_TO_USER_STRING(tmp));
   SET_STRING_ELT(names, i, COPY_TO_USER_STRING("Return type"));    
   i++;
 }
 
 SET_NAMES(ans, names); 
 
 /* Now set the class to be "JavaMethod" */

 UNPROTECT(2);

 return(ans);
}
示例#4
0
jclass getJavaLangClass(u2 requestedClassId) {
	// TODO Lazy load ?
	return (jclass) GetObjectArrayElement(javaLangClassArray, requestedClassId);
}
示例#5
0
JNIEXPORT jobjectArray JNICALL Java_org_tmu_core_Nauty_canonize
  (JNIEnv * env, jobject thisobj, jobjectArray arr, jint k){
    int subgraph_size=0;
	graph g[MAXN*MAXM];
	graph canong[MAXN*MAXM];
	int lab[MAXN],ptn[MAXN],orbits[MAXN];
	static DEFAULTOPTIONS_DIGRAPH(options);
	statsblk stats;

	subgraph_size=k;
		
	
	if (subgraph_size > MAXN)
        {
            printf("size of graph must be in the range 1..%d\n",MAXN);
            return NULL;
        }
	
	options.defaultptn = TRUE;
	options.getcanon = TRUE;
	
	
	char bin_adj[BUFSIZE];
	char zeroed_adj[BUFSIZE];
	char str[BUFSIZE];

	int n=subgraph_size;
	int m=SETWORDSNEEDED(n);
	nauty_check(WORDSIZE,m,n,NAUTYVERSIONID);
	
	int stringCount = GetArrayLength(env, arr);
	
	jobjectArray ret;
	ret= (jobjectArray)env->NewObjectArray(stringCount,  
         env->FindClass("java/lang/String"),  
         env->NewStringUTF(""));
		 

    
	for (int i=0; i<stringCount; i++) {
        jstring string = (jstring) GetObjectArrayElement(env, arr, i);
        const char *rawString = GetStringUTFChars(env, string, 0);
        strcpy(bin_adj,rawString);
		ReleaseStringUTFChars(rawString);
		int bin_len=strlen(bin_adj);
		if(bin_len<subgraph_size*subgraph_size){
			memset(zeroed_adj,'0',subgraph_size*subgraph_size-bin_len);
		}
		strcpy(zeroed_adj+subgraph_size*subgraph_size-bin_len,bin_adj);		
		EMPTYGRAPH(g,m,n);
		for (int i = 0; i < subgraph_size; i++)
            for (int j = 0; j < subgraph_size; j++)
                if (i!=j&&zeroed_adj[i * subgraph_size + j] == '1')
						ADDONEARC(g,i,j,m);
		
		densenauty(g,lab,ptn,orbits,&options,&stats,m,n,canong);
		
		memset(str,'0',subgraph_size*subgraph_size);
		for (int i = 0; i < subgraph_size; i++) {	
			for(int j = 0; j < subgraph_size; j++) {
				if(i!=j&&zeroed_adj[lab[i]*subgraph_size+lab[j]]=='1') 
					str[i*subgraph_size+j]='1';
			}
		}
		str[subgraph_size*subgraph_size]=0;
		
		env->SetObjectArrayElement(ret,i,env->NewStringUTF(str));
    }   
	
	return ret;  
}