1 /****************************** native.c ***************************************
3 Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
5 See file COPYRIGHT for information on usage and disclaimer of warranties
7 Contains the tables for native methods.
8 The .hh files created with the header file generator are all included here
9 as are the C functions implementing these methods.
11 Authors: Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at
12 Roman Obermaisser EMAIL: cacao@complang.tuwien.ac.at
13 Andreas Krall EMAIL: cacao@complang.tuwien.ac.at
15 Last Change: 2003/02/26
17 *******************************************************************************/
23 #include "nativetypes.hh"
33 #include <sys/utsname.h>
35 #include "threads/thread.h" /* schani */
36 #include "threads/locks.h"
38 /* Include files for IO functions */
42 #include <sys/types.h>
48 #include "../threads/threadio.h"
50 /* searchpath for classfiles */
51 static char *classpath;
53 /* for java-string to char conversion */
54 #define MAXSTRINGSIZE 1000
56 /******************** systemclasses required for native methods ***************/
58 static classinfo *class_java_lang_Class;
59 static classinfo *class_java_lang_Cloneable;
60 static classinfo *class_java_lang_CloneNotSupportedException;
61 static classinfo *class_java_lang_System;
62 static classinfo *class_java_lang_ClassLoader;
63 static classinfo *class_java_lang_ClassNotFoundException;
64 static classinfo *class_java_lang_InstantiationException;
65 static classinfo *class_java_lang_NoSuchMethodError;
66 static classinfo *class_java_lang_NoSuchFieldError;
67 static classinfo *class_java_lang_ClassFormatError;
68 static classinfo *class_java_lang_IllegalArgumentException;
69 static classinfo *class_java_lang_ArrayIndexOutOfBoundsException;
70 static classinfo *class_java_lang_NoSuchFieldException;
71 static classinfo *class_java_io_SyncFailedException;
72 static classinfo *class_java_io_IOException;
73 static classinfo *class_java_io_FileNotFoundException;
74 static classinfo *class_java_io_UnixFileSystem;
75 static classinfo *class_java_security_PrivilegedActionException;
76 static classinfo *class_java_net_UnknownHostException;
77 static classinfo *class_java_net_SocketException;
78 static classinfo *class_java_lang_NoSuchMethodException;
79 static classinfo *class_java_lang_Double;
80 static classinfo *class_java_lang_Float;
81 static classinfo *class_java_lang_Long;
82 static classinfo *class_java_lang_Byte;
83 static classinfo *class_java_lang_Short;
84 static classinfo *class_java_lang_Boolean;
85 static classinfo *class_java_lang_Void;
86 static classinfo *class_java_lang_Character;
87 static classinfo *class_java_lang_Integer;
89 /* the system classloader object */
90 struct java_lang_ClassLoader *SystemClassLoader = NULL;
92 /* for raising exceptions from native methods */
93 java_objectheader* exceptionptr = NULL;
95 /************* use classinfo structure as java.lang.Class object **************/
97 static void use_class_as_object (classinfo *c)
99 vftbl *vt = class_java_lang_Class -> vftbl;
101 if (!c->classvftbl) {
102 c->classvftbl = true;
103 copy_vftbl(&newtbl, vt);
104 newtbl->class = c->header.vftbl->class;
105 newtbl->baseval = c->header.vftbl->baseval;
106 newtbl->diffval = c->header.vftbl->diffval;
107 c->header.vftbl = newtbl;
111 /*********************** include Java Native Interface ************************/
115 /*************************** include native methods ***************************/
117 #include "nat/Object.c"
118 #include "nat/String.c"
119 #include "nat/ClassLoader.c"
120 #include "nat/Class.c"
121 #include "nat/Compiler.c"
122 #include "nat/Double.c"
123 #include "nat/Float.c"
124 #include "nat/Math.c"
125 #include "nat/Package.c"
126 #include "nat/Runtime.c"
127 #include "nat/SecurityManager.c"
128 #include "nat/System.c"
129 #include "nat/Thread.c"
130 #include "nat/Throwable.c"
131 #include "nat/Finalizer.c"
132 #include "nat/Array.c"
133 #include "nat/Constructor.c"
134 #include "nat/Field.c"
135 #include "nat/Method.c"
136 #include "nat/FileDescriptor.c"
137 #include "nat/FileInputStream.c"
138 #include "nat/FileOutputStream.c"
139 #include "nat/FileSystem.c"
140 #include "nat/ObjectInputStream.c"
141 #include "nat/ObjectStreamClass.c"
142 #include "nat/RandomAccessFile.c"
143 #include "nat/ResourceBundle.c"
144 #include "nat/JarFile.c"
145 #include "nat/Adler32.c"
146 #include "nat/CRC32.c"
147 #include "nat/Deflater.c"
148 #include "nat/Inflater.c"
149 #include "nat/ZipEntry.c"
150 #include "nat/ZipFile.c"
151 #include "nat/BigInteger.c"
152 #include "nat/InetAddress.c"
153 #include "nat/InetAddressImpl.c"
154 #include "nat/DatagramPacket.c"
155 #include "nat/PlainDatagramSocketImpl.c"
156 #include "nat/PlainSocketImpl.c"
157 #include "nat/SocketInputStream.c"
158 #include "nat/SocketOutputStream.c"
159 #include "nat/AccessController.c"
160 #include "nat/ClassLoader_NativeLibrary.c"
161 #include "nat/UnixFileSystem.c"
163 /************************** tables for methods ********************************/
165 /* table for locating native methods */
166 static struct nativeref {
174 #include "nativetable.hh"
179 #define NATIVETABLESIZE (sizeof(nativetable)/sizeof(struct nativeref))
181 /* table for fast string comparison */
182 static struct nativecompref {
188 } nativecomptable [NATIVETABLESIZE];
190 /* string comparsion table initialized */
191 static bool nativecompdone = false;
194 /******************************************************************************/
195 /******************************************************************************/
196 #include "natcalls.h"
198 /* string call comparison table initialized */
200 /******************************************************************************/
201 /******************************************************************************/
203 /*--------------- native method calls & classes used -------------------------*/
208 /*********************** function: native_loadclasses **************************
210 load classes required for native methods
212 *******************************************************************************/
214 void native_loadclasses()
216 /* class_new adds the class to the list of classes to be loaded */
217 class_java_lang_Cloneable =
218 class_new ( utf_new_char ("java/lang/Cloneable") );
219 class_java_lang_CloneNotSupportedException =
220 class_new ( utf_new_char ("java/lang/CloneNotSupportedException") );
221 class_java_lang_Class =
222 class_new ( utf_new_char ("java/lang/Class") );
223 class_java_io_IOException =
224 class_new ( utf_new_char ("java/io/IOException") );
225 class_java_io_FileNotFoundException =
226 class_new ( utf_new_char ("java/io/FileNotFoundException") );
227 class_java_lang_ClassNotFoundException =
228 class_new ( utf_new_char ("java/lang/ClassNotFoundException") );
229 class_java_lang_InstantiationException =
230 class_new ( utf_new_char ("java/lang/InstantiationException") );
231 class_java_lang_NoSuchMethodError =
232 class_new ( utf_new_char ("java/lang/NoSuchMethodError") );
233 class_java_lang_NoSuchFieldError =
234 class_new ( utf_new_char ("java/lang/NoSuchFieldError") );
235 class_java_lang_ClassFormatError =
236 class_new ( utf_new_char ("java/lang/ClassFormatError") );
237 class_java_io_SyncFailedException =
238 class_new ( utf_new_char ("java/io/SyncFailedException") );
239 class_java_io_UnixFileSystem =
240 class_new ( utf_new_char ("java/io/UnixFileSystem") );
241 class_java_lang_System =
242 class_new ( utf_new_char ("java/lang/System") );
243 class_java_lang_ClassLoader =
244 class_new ( utf_new_char ("java/lang/ClassLoader") );
245 class_java_security_PrivilegedActionException =
246 class_new( utf_new_char("java/security/PrivilegedActionException"));
247 class_java_net_UnknownHostException =
248 loader_load( utf_new_char ("java/net/UnknownHostException") );
249 class_java_net_SocketException =
250 loader_load( utf_new_char ("java/net/SocketException") );
251 class_java_lang_IllegalArgumentException =
252 class_new( utf_new_char("java/lang/IllegalArgumentException"));
253 class_java_lang_ArrayIndexOutOfBoundsException =
254 class_new( utf_new_char ("java/lang/ArrayIndexOutOfBoundsException") );
255 class_java_lang_NoSuchFieldException =
256 class_new( utf_new_char ("java/lang/NoSuchFieldException") );
257 class_java_lang_NoSuchMethodException =
258 class_new( utf_new_char ("java/lang/NoSuchMethodException") );
260 /* load classes for wrapping primitive types */
261 class_java_lang_Double =
262 class_new( utf_new_char ("java/lang/Double") );
263 class_java_lang_Float =
264 class_new( utf_new_char ("java/lang/Float") );
265 class_java_lang_Character =
266 class_new( utf_new_char ("java/lang/Character") );
267 class_java_lang_Integer =
268 class_new( utf_new_char ("java/lang/Integer") );
269 class_java_lang_Long =
270 class_new( utf_new_char ("java/lang/Long") );
271 class_java_lang_Byte =
272 class_new( utf_new_char ("java/lang/Byte") );
273 class_java_lang_Short =
274 class_new( utf_new_char ("java/lang/Short") );
275 class_java_lang_Boolean =
276 class_new( utf_new_char ("java/lang/Boolean") );
277 class_java_lang_Void =
278 class_new( utf_new_char ("java/lang/Void") );
280 /* load to avoid dynamic classloading */
281 class_new(utf_new_char("sun/net/www/protocol/file/Handler"));
282 class_new(utf_new_char("sun/net/www/protocol/jar/Handler"));
283 class_new(utf_new_char("sun/io/CharToByteISO8859_1"));
285 /* start classloader */
286 loader_load(utf_new_char("sun/io/ByteToCharISO8859_1"));
290 /*************** adds a class to the vector of loaded classes ****************/
292 void systemclassloader_addclass(classinfo *c)
296 /* find method addClass of java.lang.ClassLoader */
297 m = class_resolvemethod (
298 class_java_lang_ClassLoader,
299 utf_new_char("addClass"),
300 utf_new_char("(Ljava/lang/Class;)")
303 if (!m) panic("warning: cannot initialize classloader");
305 /* prepare class to be passed as argument */
306 use_class_as_object (c);
308 /* call 'addClass' */
309 asm_calljavamethod(m,
310 (java_objectheader*) SystemClassLoader,
311 (java_objectheader*) c,
317 /*************** adds a library to the vector of loaded libraries *************/
319 void systemclassloader_addlibrary(java_objectheader *o)
323 /* find method addElement of java.util.Vector */
324 m = class_resolvemethod (
325 loader_load ( utf_new_char ("java/util/Vector") ),
326 utf_new_char("addElement"),
327 utf_new_char("(Ljava/lang/Object;)V")
330 if (!m) panic("cannot initialize classloader");
332 /* call 'addElement' */
333 asm_calljavamethod(m,
334 SystemClassLoader->nativeLibraries,
341 /*****************************************************************************
343 create systemclassloader object and initialize instance fields
345 ******************************************************************************/
347 void init_systemclassloader()
349 if (!SystemClassLoader) {
351 /* create object and call initializer */
352 SystemClassLoader = (java_lang_ClassLoader*) native_new_and_init(class_java_lang_ClassLoader);
353 heap_addreference((void**) &SystemClassLoader);
355 /* systemclassloader has no parent */
356 SystemClassLoader->parent = NULL;
357 SystemClassLoader->initialized = true;
362 /********************* add loaded library name *******************************/
364 void systemclassloader_addlibname(java_objectheader *o)
367 java_objectheader *LibraryNameVector;
370 m = class_resolvemethod (
371 loader_load ( utf_new_char ("java/util/Vector") ),
372 utf_new_char("addElement"),
373 utf_new_char("(Ljava/lang/Object;)V")
376 if (!m) panic("cannot initialize classloader");
378 id = env.GetStaticFieldID(&env,class_java_lang_ClassLoader,"loadedLibraryNames","Ljava/util/Vector;");
379 if (!id) panic("can not access ClassLoader");
381 asm_calljavamethod(m,
382 GetStaticObjectField(&env,class_java_lang_ClassLoader,id),
390 /********************* function: native_setclasspath **************************/
392 void native_setclasspath (char *path)
394 /* set searchpath for classfiles */
398 /***************** function: throw_classnotfoundexception *********************/
400 void throw_classnotfoundexception()
402 /* throws a ClassNotFoundException */
403 exceptionptr = native_new_and_init (class_java_lang_ClassNotFoundException);
407 /*********************** Function: native_findfunction *************************
409 Looks up a method (must have the same class name, method name, descriptor
410 and 'static'ness) and returns a function pointer to it.
411 Returns: function pointer or NULL (if there is no such method)
413 Remark: For faster operation, the names/descriptors are converted from C
414 strings to Unicode the first time this function is called.
416 *******************************************************************************/
418 functionptr native_findfunction (utf *cname, utf *mname,
419 utf *desc, bool isstatic)
422 /* entry of table for fast string comparison */
423 struct nativecompref *n;
424 /* for warning message if no function is found */
428 isstatic = isstatic ? true : false;
430 if (!nativecompdone) {
431 for (i = 0; i < NATIVETABLESIZE; i++) {
432 nativecomptable[i].classname =
433 utf_new_char(nativetable[i].classname);
434 nativecomptable[i].methodname =
435 utf_new_char(nativetable[i].methodname);
436 nativecomptable[i].descriptor =
437 utf_new_char(nativetable[i].descriptor);
438 nativecomptable[i].isstatic =
439 nativetable[i].isstatic;
440 nativecomptable[i].func =
443 nativecompdone = true;
446 for (i = 0; i < NATIVETABLESIZE; i++) {
447 n = &(nativecomptable[i]);
449 if (cname == n->classname && mname == n->methodname &&
450 desc == n->descriptor && isstatic == n->isstatic)
454 /* no function was found, display warning */
457 utf_strlen(cname) + utf_strlen(mname) + utf_strlen(desc) + 64;
459 buffer = MNEW(char, buffer_len);
461 strcpy(buffer, "warning: native function ");
462 utf_sprint(buffer+strlen(buffer), mname);
463 strcpy(buffer+strlen(buffer), ": ");
464 utf_sprint(buffer+strlen(buffer), desc);
465 strcpy(buffer+strlen(buffer), " not found in class ");
466 utf_sprint(buffer+strlen(buffer), cname);
470 MFREE(buffer, char, buffer_len);
476 /********************** function: javastring_new *******************************
478 creates a new object of type java/lang/String with the text of
479 the specified utf8-string
481 return: pointer to the string or NULL if memory is exhausted.
483 *******************************************************************************/
485 java_objectheader *javastring_new (utf *u)
487 char *utf_ptr = u->text; /* current utf character in utf string */
488 int utflength = utf_strlen(u); /* length of utf-string if uncompressed */
489 java_lang_String *s; /* result-string */
493 s = (java_lang_String*) builtin_new (class_java_lang_String);
494 a = builtin_newarray_char (utflength);
496 /* javastring or character-array could not be created */
500 /* decompress utf-string */
501 for (i = 0; i < utflength; i++)
502 a->data[i] = utf_nextu2(&utf_ptr);
504 /* set fields of the javastring-object */
507 s -> count = utflength;
509 return (java_objectheader*) s;
512 /********************** function: javastring_new_char **************************
514 creates a new java/lang/String object which contains the convertet
515 C-string passed via text.
517 return: the object pointer or NULL if memory is exhausted.
519 *******************************************************************************/
521 java_objectheader *javastring_new_char (char *text)
524 s4 len = strlen(text); /* length of the string */
525 java_lang_String *s; /* result-string */
528 s = (java_lang_String*) builtin_new (class_java_lang_String);
529 a = builtin_newarray_char (len);
531 /* javastring or character-array could not be created */
532 if ((!a) || (!s)) return NULL;
535 for (i = 0; i < len; i++)
536 a->data[i] = text[i];
538 /* set fields of the javastring-object */
543 return (java_objectheader*) s;
547 /************************* function javastring_tochar **************************
549 converts a Java string into a C string.
551 return: pointer to C string
553 Caution: every call of this function overwrites the previous string !!!
555 *******************************************************************************/
557 static char stringbuffer[MAXSTRINGSIZE];
559 char *javastring_tochar (java_objectheader *so)
561 java_lang_String *s = (java_lang_String*) so;
570 if (s->count > MAXSTRINGSIZE)
572 for (i = 0; i < s->count; i++)
573 stringbuffer[i] = a->data[s->offset+i];
574 stringbuffer[i] = '\0';
579 /****************** function class_findfield_approx ****************************
581 searches in 'classinfo'-structure for a field with the
584 *******************************************************************************/
586 fieldinfo *class_findfield_approx (classinfo *c, utf *name)
589 for (i = 0; i < c->fieldscount; i++) {
590 /* compare field names */
591 if ((c->fields[i].name == name))
592 return &(c->fields[i]);
595 /* field was not found, raise exception */
596 exceptionptr = native_new_and_init(class_java_lang_NoSuchFieldException);
601 /********************** function: native_new_and_init *************************
603 Creates a new object on the heap and calls the initializer.
604 Returns the object pointer or NULL if memory is exhausted.
606 *******************************************************************************/
608 java_objectheader *native_new_and_init (classinfo *c)
611 java_objectheader *o = builtin_new (c); /* create object */
615 /* find initializer */
617 m = class_findmethod(c, utf_new_char("<init>"), utf_new_char("()V"));
619 if (!m) { /* initializer not found */
621 sprintf(logtext, "Warning: class has no instance-initializer: ");
622 utf_sprint(logtext + strlen(logtext), c->name);
628 /* call initializer */
630 asm_calljavamethod (m, o, NULL, NULL, NULL);
634 /******************** function: stringtable_update ****************************
636 traverses the javastring hashtable and sets the vftbl-entries of
637 javastrings which were temporarily set to NULL, because
638 java.lang.Object was not yet loaded
640 *******************************************************************************/
642 void stringtable_update ()
644 java_lang_String *js;
646 literalstring *s; /* hashtable entry */
649 for (i = 0; i < string_hash.size; i++) {
650 s = string_hash.ptr[i];
654 js = (java_lang_String *) s->string;
656 if (!js || !(a = js->value))
657 /* error in hashtable found */
658 panic("invalid literalstring in hashtable");
660 if (!js->header.vftbl)
661 /* vftbl of javastring is NULL */
662 js->header.vftbl = class_java_lang_String -> vftbl;
664 if (!a->header.objheader.vftbl)
665 /* vftbl of character-array is NULL */
666 a->header.objheader.vftbl = class_array -> vftbl;
668 /* follow link in external hash chain */
676 /************************* function: u2_utflength ***************************
678 returns the utf length in bytes of a u2 array
680 *****************************************************************************/
683 u4 u2_utflength(u2 *text, u4 u2_length)
685 u4 result_len = 0; /* utf length in bytes */
686 u2 ch; /* current unicode character */
689 for (len = 0; len < u2_length; len++) {
691 /* next unicode character */
694 /* determine bytes required to store unicode character as utf */
695 if (ch && (ch < 0x80))
706 /********************* function: utf_new_u2 ***********************************
708 make utf symbol from u2 array,
709 if isclassname is true '.' is replaced by '/'
711 *******************************************************************************/
713 utf *utf_new_u2(u2 *unicode_pos, u4 unicode_length, bool isclassname)
715 char *buffer; /* memory buffer for unicode characters */
716 char *pos; /* pointer to current position in buffer */
717 u4 left; /* unicode characters left */
718 u4 buflength; /* utf length in bytes of the u2 array */
719 utf *result; /* resulting utf-string */
722 /* determine utf length in bytes and allocate memory */
723 buflength = u2_utflength(unicode_pos, unicode_length);
724 buffer = MNEW(char,buflength);
726 /* memory allocation failed */
727 if (!buffer) return NULL;
732 for (i = 0; i++ < unicode_length; unicode_pos++) {
733 /* next unicode character */
736 if ((c != 0) && (c < 0x80)) {
739 if ((int) left < 0) break;
740 /* convert classname */
741 if (isclassname && c=='.')
745 } else if (c < 0x800) {
747 unsigned char high = c >> 6;
748 unsigned char low = c & 0x3F;
750 if ((int) left < 0) break;
751 *pos++ = high | 0xC0;
756 char mid = (c >> 6) & 0x3F;
759 if ((int) left < 0) break;
760 *pos++ = high | 0xE0;
766 /* insert utf-string into symbol-table */
767 result = utf_new(buffer,buflength);
768 MFREE(buffer, char, buflength);
772 /********************* function: javastring_toutf *****************************
774 make utf symbol from javastring
776 *******************************************************************************/
778 utf *javastring_toutf(java_lang_String *string, bool isclassname)
780 java_lang_String *str = (java_lang_String *) string;
781 return utf_new_u2(str->value->data,str->count, isclassname);
784 /********************* function: literalstring_u2 *****************************
786 searches for the javastring with the specified u2-array in
787 the string hashtable, if there is no such string a new one is
790 if copymode is true a copy of the u2-array is made
792 *******************************************************************************/
794 java_objectheader *literalstring_u2 (java_chararray *a, u4 length, bool copymode )
796 literalstring *s; /* hashtable element */
797 java_lang_String *js; /* u2-array wrapped in javastring */
798 java_chararray *stringdata; /* copy of u2-array */
803 /* find location in hashtable */
804 key = unicode_hashkey (a->data, length);
805 slot = key & (string_hash.size-1);
806 s = string_hash.ptr[slot];
810 js = (java_lang_String *) s->string;
812 if (js->count == length) {
814 for (i=0; i<length; i++)
815 if (js->value->data[i] != a->data[i]) goto nomatch;
817 /* string already in hashtable, free memory */
819 lit_mem_free(a, sizeof(java_chararray) + sizeof(u2)*(length-1)+10);
821 return (java_objectheader *) js;
825 /* follow link in external hash chain */
830 /* create copy of u2-array for new javastring */
831 u4 arraysize = sizeof(java_chararray) + sizeof(u2)*(length-1)+10;
832 stringdata = lit_mem_alloc ( arraysize );
833 memcpy(stringdata, a, arraysize );
838 /* location in hashtable found, complete arrayheader */
839 if (class_array==NULL) panic("class_array not initialized");
840 stringdata -> header.objheader.vftbl = class_array -> vftbl;
841 stringdata -> header.size = length;
842 stringdata -> header.arraytype = ARRAYTYPE_CHAR;
844 /* create new javastring */
845 js = LNEW (java_lang_String);
846 js -> header.vftbl = class_java_lang_String -> vftbl;
847 js -> value = stringdata;
849 js -> count = length;
851 /* create new literalstring */
852 s = NEW (literalstring);
853 s->hashlink = string_hash.ptr[slot];
854 s->string = (java_objectheader *) js;
855 string_hash.ptr[slot] = s;
857 /* update numbe of hashtable entries */
858 string_hash.entries++;
860 /* reorganization of hashtable */
861 if ( string_hash.entries > (string_hash.size*2)) {
863 /* reorganization of hashtable, average length of
864 the external chains is approx. 2 */
868 hashtable newhash; /* the new hashtable */
870 /* create new hashtable, double the size */
871 init_hashtable(&newhash, string_hash.size*2);
872 newhash.entries=string_hash.entries;
874 /* transfer elements to new hashtable */
875 for (i=0; i<string_hash.size; i++) {
876 s = string_hash.ptr[i];
878 literalstring *nexts = s -> hashlink;
879 js = (java_lang_String*) s->string;
880 slot = (unicode_hashkey(js->value->data,js->count)) & (newhash.size-1);
882 s->hashlink = newhash.ptr[slot];
883 newhash.ptr[slot] = s;
885 /* follow link in external hash chain */
890 /* dispose old table */
891 MFREE (string_hash.ptr, void*, string_hash.size);
892 string_hash = newhash;
895 return (java_objectheader *) js;
898 /******************** Function: literalstring_new *****************************
900 creates a new javastring with the text of the utf-symbol
901 and inserts it into the string hashtable
903 *******************************************************************************/
905 java_objectheader *literalstring_new (utf *u)
907 char *utf_ptr = u->text; /* pointer to current unicode character in utf string */
908 u4 utflength = utf_strlen(u); /* length of utf-string if uncompressed */
909 java_chararray *a; /* u2-array constructed from utf string */
910 java_objectheader *js;
913 /* allocate memory */
914 a = lit_mem_alloc (sizeof(java_chararray) + sizeof(u2)*(utflength-1)+10 );
915 /* convert utf-string to u2-array */
916 for (i=0; i<utflength; i++) a->data[i] = utf_nextu2(&utf_ptr);
918 return literalstring_u2(a, utflength, false);
922 /********************** function: literalstring_free **************************
924 removes a javastring from memory
926 ******************************************************************************/
928 void literalstring_free (java_objectheader* sobj)
930 java_lang_String *s = (java_lang_String*) sobj;
931 java_chararray *a = s->value;
933 log_text("literalstring_free called");
935 /* dispose memory of java.lang.String object */
936 LFREE (s, java_lang_String);
937 /* dispose memory of java-characterarray */
938 LFREE (a, sizeof(java_chararray) + sizeof(u2)*(a->header.size-1)); /* +10 ?? */
944 void copy_vftbl(vftbl **dest, vftbl *src)
946 *dest = mem_alloc(sizeof(vftbl) + sizeof(methodptr)*(src->vftbllength-1));
947 memcpy(*dest, src, sizeof(vftbl) - sizeof(methodptr));
948 memcpy(&(*dest)->table, &src->table, src->vftbllength * sizeof(methodptr));
951 /*****************************************************************************/
952 /*****************************************************************************/
955 /*--------------------------------------------------------*/
956 void printNativeCall(nativeCall nc) {
959 printf("\n%s's Native Methods call:\n",nc.classname); fflush(stdout);
960 for (i=0; i<nc.methCnt; i++) {
961 printf("\tMethod=%s %s\n",nc.methods[i].methodname, nc.methods[i].descriptor);fflush(stdout);
963 for (j=0; j<nc.callCnt[i]; j++) {
964 printf("\t\t<%i,%i>aCalled = %s %s %s\n",i,j,
965 nc.methods[i].methodCalls[j].classname,
966 nc.methods[i].methodCalls[j].methodname,
967 nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
970 printf("-+++++--------------------\n");fflush(stdout);
973 /*--------------------------------------------------------*/
974 void printCompNativeCall(nativeCompCall nc) {
976 printf("printCompNativeCall BEGIN\n");fflush(stdout);
977 printf("\n%s's Native Comp Methods call:\n",nc.classname->text);fflush(stdout);
978 utf_display(nc.classname); fflush(stdout);
980 for (i=0; i<nc.methCnt; i++) {
981 printf("\tMethod=%s %s\n",nc.methods[i].methodname->text,nc.methods[i].descriptor->text);fflush(stdout);
982 utf_display(nc.methods[i].methodname); fflush(stdout);
983 utf_display(nc.methods[i].descriptor);fflush(stdout);
984 printf("\n");fflush(stdout);
986 for (j=0; j<nc.callCnt[i]; j++) {
987 printf("\t\t<%i,%i>bCalled = ",i,j);fflush(stdout);
988 utf_display(nc.methods[i].methodCalls[j].classname);fflush(stdout);
989 utf_display(nc.methods[i].methodCalls[j].methodname); fflush(stdout);
990 utf_display(nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
991 printf("\n");fflush(stdout);
994 printf("---------------------\n");fflush(stdout);
998 /*--------------------------------------------------------*/
999 classMeth findNativeMethodCalls(utf *c, utf *m, utf *d )
1011 /*--------------------------------------------------------*/
1012 nativeCall* findNativeClassCalls(char *aclassname ) {
1015 for (i=0;i<NATIVECALLSSIZE; i++) {
1016 // convert table to utf later to speed up search - see native.c
1017 if (strcmp(nativeCalls[i].classname, aclassname) == 0)
1018 return &nativeCalls[i];
1023 /*--------------------------------------------------------*/
1024 /*--------------------------------------------------------*/
1025 void utfNativeCall(nativeCall nc, nativeCompCall *ncc) {
1029 ncc->classname = utf_new_char(nc.classname);
1030 ncc->methCnt = nc.methCnt;
1032 for (i=0; i<nc.methCnt; i++) {
1033 ncc->methods[i].methodname = utf_new_char(nc.methods[i].methodname);
1034 ncc->methods[i].descriptor = utf_new_char(nc.methods[i].descriptor);
1035 ncc->callCnt[i] = nc.callCnt[i];
1037 for (j=0; j<nc.callCnt[i]; j++) {
1039 ncc->methods[i].methodCalls[j].classname = utf_new_char(nc.methods[i].methodCalls[j].classname);
1041 if (strcmp("", nc.methods[i].methodCalls[j].methodname) != 0) {
1042 ncc->methods[i].methodCalls[j].methodname = utf_new_char(nc.methods[i].methodCalls[j].methodname);
1043 ncc->methods[i].methodCalls[j].descriptor = utf_new_char(nc.methods[i].methodCalls[j].descriptor);
1046 ncc->methods[i].methodCalls[j].methodname = NULL;
1047 ncc->methods[i].methodCalls[j].descriptor = NULL;
1055 /*--------------------------------------------------------*/
1057 bool natcall2utf(bool natcallcompdone) {
1060 if (natcallcompdone)
1063 for (i=0;i<NATIVECALLSSIZE; i++) {
1064 utfNativeCall (nativeCalls[i], &nativeCompCalls[i]);
1069 /*--------------------------------------------------------*/