+/******************************************************************************************
+
+ retrieve the next argument or returntype from a descriptor
+ and return the corresponding class
+
+*******************************************************************************************/
+
+classinfo *get_type(char **utf_ptr,char *desc_end, bool skip)
+{
+ classinfo *c = class_from_descriptor(*utf_ptr,desc_end,utf_ptr,
+ (skip) ? CLASSLOAD_SKIP : CLASSLOAD_LOAD);
+ if (!c)
+ /* unknown type */
+ panic("illegal descriptor");
+
+ if (skip) return NULL;
+
+ use_class_as_object(c);
+ return c;
+}
+
+
+/******************************************************************************************
+
+ use the descriptor of a method to generate a java/lang/Class array
+ which contains the classes of the parametertypes of the method
+
+*******************************************************************************************/
+
+java_objectarray* get_parametertypes(methodinfo *m)
+{
+ utf *descr = m->descriptor; /* method-descriptor */
+ char *utf_ptr = descr->text; /* current position in utf-text */
+ char *desc_end = utf_end(descr); /* points behind utf string */
+ java_objectarray* result;
+ int parametercount = 0;
+ int i;
+
+ /* skip '(' */
+ utf_nextu2(&utf_ptr);
+
+ /* determine number of parameters */
+ while ( *utf_ptr != ')' ) {
+ get_type(&utf_ptr,desc_end,true);
+ parametercount++;
+ }
+
+ /* create class-array */
+ result = builtin_anewarray(parametercount, class_java_lang_Class);
+
+ utf_ptr = descr->text;
+ utf_nextu2(&utf_ptr);
+
+ /* get returntype classes */
+ for (i = 0; i < parametercount; i++)
+ result->data[i] = (java_objectheader *) get_type(&utf_ptr,desc_end, false);
+
+ return result;
+}
+
+
+
+
+
+/******************************************************************************************
+
+ get the exceptions which can be thrown by a method
+
+*******************************************************************************************/
+
+java_objectarray* get_exceptiontypes(methodinfo *m) {
+ u2 exccount=m->thrownexceptionscount;
+ u2 i;
+ java_objectarray *result;
+ /* create class-array */
+ result = builtin_anewarray(exccount, class_java_lang_Class);
+ for (i=0;i<exccount;i++) {
+ java_objectheader *oh=(java_objectheader*)(m->thrownexceptions[i]);
+ use_class_as_object(oh);
+ result->data[i]=oh;
+ }
+ return result;
+}
+
+
+
+
+
+/******************************************************************************************
+
+ get the returntype class of a method
+
+*******************************************************************************************/
+
+classinfo *get_returntype(methodinfo *m)
+{
+ char *utf_ptr; /* current position in utf-text */
+ char *desc_end; /* points behind utf string */
+ utf *desc = m->descriptor; /* method-descriptor */
+
+ utf_ptr = desc->text;
+ desc_end = utf_end(desc);
+
+ /* ignore parametertypes */
+ while ((utf_ptr<desc_end) && utf_nextu2(&utf_ptr)!=')')
+ /* skip */ ;
+
+ return get_type(&utf_ptr,desc_end, false);
+}
+
+
+/*****************************************************************************/
+/*****************************************************************************/
+
+
+/*--------------------------------------------------------*/
+void printNativeCall(nativeCall nc) {
+ int i,j;
+
+ printf("\n%s's Native Methods call:\n",nc.classname); fflush(stdout);
+ for (i=0; i<nc.methCnt; i++) {
+ printf("\tMethod=%s %s\n",nc.methods[i].methodname, nc.methods[i].descriptor);fflush(stdout);
+
+ for (j=0; j<nc.callCnt[i]; j++) {
+ printf("\t\t<%i,%i>aCalled = %s %s %s\n",i,j,
+ nc.methods[i].methodCalls[j].classname,
+ nc.methods[i].methodCalls[j].methodname,
+ nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
+ }
+ }
+ printf("-+++++--------------------\n");fflush(stdout);
+}
+
+/*--------------------------------------------------------*/
+void printCompNativeCall(nativeCompCall nc) {
+ int i,j;
+ printf("printCompNativeCall BEGIN\n");fflush(stdout);
+ printf("\n%s's Native Comp Methods call:\n",nc.classname->text);fflush(stdout);
+ utf_display(nc.classname); fflush(stdout);
+
+ for (i=0; i<nc.methCnt; i++) {
+ printf("\tMethod=%s %s\n",nc.methods[i].methodname->text,nc.methods[i].descriptor->text);fflush(stdout);
+ utf_display(nc.methods[i].methodname); fflush(stdout);
+ utf_display(nc.methods[i].descriptor);fflush(stdout);
+ printf("\n");fflush(stdout);
+
+ for (j=0; j<nc.callCnt[i]; j++) {
+ printf("\t\t<%i,%i>bCalled = ",i,j);fflush(stdout);
+ utf_display(nc.methods[i].methodCalls[j].classname);fflush(stdout);
+ utf_display(nc.methods[i].methodCalls[j].methodname); fflush(stdout);
+ utf_display(nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
+ printf("\n");fflush(stdout);
+ }
+ }
+printf("---------------------\n");fflush(stdout);
+}
+
+
+/*--------------------------------------------------------*/
+classMeth findNativeMethodCalls(utf *c, utf *m, utf *d )
+{
+ int i = 0;
+ int j = 0;
+ int cnt = 0;
+ classMeth mc;
+ mc.i_class = i;
+ mc.j_method = j;
+ mc.methCnt = cnt;
+
+ return mc;
+}
+
+/*--------------------------------------------------------*/
+nativeCall* findNativeClassCalls(char *aclassname ) {
+int i;
+
+for (i=0;i<NATIVECALLSSIZE; i++) {
+ /* convert table to utf later to speed up search */
+ if (strcmp(nativeCalls[i].classname, aclassname) == 0)
+ return &nativeCalls[i];
+ }
+
+return NULL;
+}
+/*--------------------------------------------------------*/
+/*--------------------------------------------------------*/
+void utfNativeCall(nativeCall nc, nativeCompCall *ncc) {
+ int i,j;
+
+
+ ncc->classname = utf_new_char(nc.classname);
+ ncc->methCnt = nc.methCnt;
+
+ for (i=0; i<nc.methCnt; i++) {
+ ncc->methods[i].methodname = utf_new_char(nc.methods[i].methodname);
+ ncc->methods[i].descriptor = utf_new_char(nc.methods[i].descriptor);
+ ncc->callCnt[i] = nc.callCnt[i];
+
+ for (j=0; j<nc.callCnt[i]; j++) {
+
+ ncc->methods[i].methodCalls[j].classname = utf_new_char(nc.methods[i].methodCalls[j].classname);
+
+ if (strcmp("", nc.methods[i].methodCalls[j].methodname) != 0) {
+ ncc->methods[i].methodCalls[j].methodname = utf_new_char(nc.methods[i].methodCalls[j].methodname);
+ ncc->methods[i].methodCalls[j].descriptor = utf_new_char(nc.methods[i].methodCalls[j].descriptor);
+ }
+ else {
+ ncc->methods[i].methodCalls[j].methodname = NULL;
+ ncc->methods[i].methodCalls[j].descriptor = NULL;
+ }
+ }
+ }
+}
+
+
+
+/*--------------------------------------------------------*/
+
+bool natcall2utf(bool natcallcompdone) {
+int i;
+
+if (natcallcompdone)
+ return true;
+
+for (i=0;i<NATIVECALLSSIZE; i++) {
+ utfNativeCall (nativeCalls[i], &nativeCompCalls[i]);
+ }
+
+return true;
+}
+
+/*--------------------------------------------------------*/
+
+
+java_objectarray *builtin_asm_createclasscontextarray(classinfo **end,classinfo **start) {
+#warning platform dependend
+ java_objectarray *tmpArray;
+ int i;
+ classinfo **current;
+ classinfo *c;
+ size_t size=(((size_t)start)-((size_t)end)) / sizeof (classinfo*);
+/* printf("end %p, start %p, size %ld\n",end,start,size);*/
+ if (!class_java_lang_Class)
+ class_java_lang_Class = class_new(utf_new_char ("java/lang/Class"));
+ if (!class_java_lang_SecurityManager)
+ class_java_lang_SecurityManager = class_new(utf_new_char ("java/lang/SecurityManager"));
+ if (size>0) {
+ if (start==class_java_lang_SecurityManager) {
+ size--;
+ start--;
+ }
+ }
+ tmpArray=builtin_newarray(size, class_array_of(class_java_lang_Class)->vftbl);
+
+ for(i=0,current=start;i<size;i++,current--) {
+ c=*current;
+/* printf("%d\n",i);
+ utf_display(c->name);*/
+ use_class_as_object(c);
+ tmpArray->data[i]=c;
+ }
+ return tmpArray;
+
+}
+
+java_lang_ClassLoader *builtin_asm_getclassloader(classinfo **end,classinfo **start) {
+#warning platform dependend
+ int i;
+ classinfo **current;
+ classinfo *c;
+ classinfo *privilegedAction;
+ size_t size=(((size_t)start)-((size_t)end)) / sizeof (classinfo*);
+/* log_text("builtin_asm_getclassloader");
+ printf("end %p, start %p, size %ld\n",end,start,size);*/
+
+ if (!class_java_lang_SecurityManager)
+ class_java_lang_SecurityManager = class_new(utf_new_char ("java/lang/SecurityManager"));
+ if (size>0) {
+ if (start==class_java_lang_SecurityManager) {
+ size--;
+ start--;
+ }
+ }
+
+ privilegedAction=class_new(utf_new_char("java/security/PrivilegedAction"));
+
+ for(i=0,current=start;i<size;i++,current--) {
+ c=*current;
+ if (c==privilegedAction) return NULL;
+ if (c->classloader) return c->classloader;
+ }
+ return NULL;
+
+
+
+
+/*
+ log_text("Java_java_lang_VMSecurityManager_currentClassLoader");
+ init_systemclassloader();
+
+ return SystemClassLoader;*/
+}