Merged revisions 8245-8298 via svnmerge from
[cacao.git] / src / native / native.c
1 /* src/native/native.c - table of native functions
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    $Id: native.c 8299 2007-08-13 08:41:18Z michi $
26
27 */
28
29
30 #include "config.h"
31
32 #include <assert.h>
33 #include <ctype.h>
34
35 #if defined(ENABLE_LTDL) && defined(HAVE_LTDL_H)
36 # include <ltdl.h>
37 #endif
38
39 #include <stdint.h>
40
41 #include "vm/types.h"
42
43 #include "mm/memory.h"
44
45 #include "native/jni.h"
46 #include "native/native.h"
47
48 #include "native/vm/nativevm.h"
49
50 #include "threads/lock-common.h"
51
52 #include "toolbox/avl.h"
53 #include "toolbox/hashtable.h"
54 #include "toolbox/logging.h"
55
56 #include "vm/builtin.h"
57 #include "vm/exceptions.h"
58 #include "vm/global.h"
59 #include "vm/stringlocal.h"
60 #include "vm/vm.h"
61
62 #include "vm/jit/asmpart.h"
63 #include "vm/jit/jit.h"
64
65 #include "vmcore/loader.h"
66 #include "vmcore/options.h"
67 #include "vm/resolve.h"
68
69 #if defined(ENABLE_JVMTI)
70 #include "native/jvmti/cacaodbg.h"
71 #endif
72
73
74 /* include table of native functions ******************************************/
75
76 #if defined(WITH_STATIC_CLASSPATH)
77 # include "native/nativetable.inc"
78 #endif
79
80
81 /* tables for methods *********************************************************/
82
83 #if defined(WITH_STATIC_CLASSPATH)
84 #define NATIVETABLESIZE  (sizeof(nativetable)/sizeof(struct nativeref))
85
86 /* table for fast string comparison */
87 static nativecompref nativecomptable[NATIVETABLESIZE];
88
89 /* string comparsion table initialized */
90 static bool nativecompdone = false;
91 #endif
92
93
94 /* global variables ***********************************************************/
95
96 static avl_tree_t *tree_native_methods;
97
98 #if defined(ENABLE_LTDL)
99 static hashtable *hashtable_library;
100 #endif
101
102
103 /* prototypes *****************************************************************/
104
105 static s4 native_tree_native_methods_comparator(const void *treenode, const void *node);
106
107
108 /* native_init *****************************************************************
109
110    Initializes the native subsystem.
111
112 *******************************************************************************/
113
114 bool native_init(void)
115 {
116 #if defined(ENABLE_LTDL)
117         /* initialize libltdl */
118
119         if (lt_dlinit())
120                 vm_abort("native_init: lt_dlinit failed: %s\n", lt_dlerror());
121
122         /* initialize library hashtable, 10 entries should be enough */
123
124         hashtable_library = NEW(hashtable);
125
126         hashtable_create(hashtable_library, 10);
127 #endif
128
129         /* initialize the native methods table */
130
131         tree_native_methods = avl_create(&native_tree_native_methods_comparator);
132
133         /* everything's ok */
134
135         return true;
136 }
137
138
139 /* native_tree_native_methods_comparator ***************************************
140
141    Comparison function for AVL tree of native methods.
142
143    IN:
144        treenode....node in the tree
145            node........node to compare with tree-node
146
147    RETURN VALUE:
148        -1, 0, +1
149
150 *******************************************************************************/
151
152 static s4 native_tree_native_methods_comparator(const void *treenode, const void *node)
153 {
154         const native_methods_node_t *treenmn;
155         const native_methods_node_t *nmn;
156
157         treenmn = treenode;
158         nmn     = node;
159
160         /* these are for walking the tree */
161
162         if (treenmn->classname < nmn->classname)
163                 return -1;
164         else if (treenmn->classname > nmn->classname)
165                 return 1;
166
167         if (treenmn->name < nmn->name)
168                 return -1;
169         else if (treenmn->name > nmn->name)
170                 return 1;
171
172         if (treenmn->descriptor < nmn->descriptor)
173                 return -1;
174         else if (treenmn->descriptor > nmn->descriptor)
175                 return 1;
176
177         /* all pointers are equal, we have found the entry */
178
179         return 0;
180 }
181
182
183 /* native_make_overloaded_function *********************************************
184
185    XXX
186
187 *******************************************************************************/
188
189 #if !defined(WITH_STATIC_CLASSPATH)
190 static utf *native_make_overloaded_function(utf *name, utf *descriptor)
191 {
192         char *newname;
193         s4    namelen;
194         char *utf_ptr;
195         u2    c;
196         s4    i;
197         s4    dumpsize;
198         utf  *u;
199
200         /* mark memory */
201
202         dumpsize = dump_size();
203
204         utf_ptr = descriptor->text;
205         namelen = strlen(name->text) + strlen("__") + strlen("0");
206
207         /* calculate additional length */
208
209         while ((c = utf_nextu2(&utf_ptr)) != ')') {
210                 switch (c) {
211                 case 'Z':
212                 case 'B':
213                 case 'C':
214                 case 'S':
215                 case 'I':
216                 case 'J':
217                 case 'F':
218                 case 'D':
219                         namelen++;
220                         break;
221                 case '[':
222                         namelen += 2;
223                         break;
224                 case 'L':
225                         namelen++;
226                         while (utf_nextu2(&utf_ptr) != ';')
227                                 namelen++;
228                         namelen += 2;
229                         break;
230                 case '(':
231                         break;
232                 default:
233                         assert(0);
234                 }
235         }
236
237         /* reallocate memory */
238
239         i = strlen(name->text);
240
241         newname = DMNEW(char, namelen);
242         MCOPY(newname, name->text, char, i);
243
244         utf_ptr = descriptor->text;
245
246         newname[i++] = '_';
247         newname[i++] = '_';
248
249         while ((c = utf_nextu2(&utf_ptr)) != ')') {
250                 switch (c) {
251                 case 'Z':
252                 case 'B':
253                 case 'C':
254                 case 'S':
255                 case 'J':
256                 case 'I':
257                 case 'F':
258                 case 'D':
259                         newname[i++] = c;
260                         break;
261                 case '[':
262                         newname[i++] = '_';
263                         newname[i++] = '3';
264                         break;
265                 case 'L':
266                         newname[i++] = 'L';
267                         while ((c = utf_nextu2(&utf_ptr)) != ';')
268                                 if (((c >= 'a') && (c <= 'z')) ||
269                                         ((c >= 'A') && (c <= 'Z')) ||
270                                         ((c >= '0') && (c <= '9')))
271                                         newname[i++] = c;
272                                 else
273                                         newname[i++] = '_';
274                         newname[i++] = '_';
275                         newname[i++] = '2';
276                         break;
277                 case '(':
278                         break;
279                 default:
280                         assert(0);
281                 }
282         }
283
284         /* close string */
285
286         newname[i] = '\0';
287
288         /* make a utf-string */
289
290         u = utf_new_char(newname);
291
292         /* release memory */
293
294         dump_release(dumpsize);
295
296         return u;
297 }
298
299
300 /* native_insert_char **********************************************************
301
302    Inserts the passed UTF character into the native method name.  If
303    necessary it is escaped properly.
304
305 *******************************************************************************/
306
307 static s4 native_insert_char(char *name, u4 pos, u2 c)
308 {
309         s4 val;
310         s4 i;
311
312         switch (c) {
313         case '/':
314         case '.':
315                 /* replace '/' or '.' with '_' */
316                 name[pos] = '_';
317                 break;
318
319         case '_':
320                 /* escape sequence for '_' is '_1' */
321                 name[pos]   = '_';
322                 name[++pos] = '1';
323                 break;
324
325         case ';':
326                 /* escape sequence for ';' is '_2' */
327                 name[pos]   = '_';
328                 name[++pos] = '2';
329                 break;
330
331         case '[':
332                 /* escape sequence for '[' is '_1' */
333                 name[pos]   = '_';
334                 name[++pos] = '3';
335                 break;
336
337         default:
338                 if (isalnum(c))
339                         name[pos] = c;
340                 else {
341                         /* unicode character */
342                         name[pos]   = '_';
343                         name[++pos] = '0';
344
345                         for (i = 0; i < 4; ++i) {
346                                 val = c & 0x0f;
347                                 name[pos + 4 - i] = (val > 10) ? ('a' + val - 10) : ('0' + val);
348                                 c >>= 4;
349                         }
350
351                         pos += 4;
352                 }
353                 break;
354         }
355
356         /* return the new buffer index */
357
358         return pos;
359 }
360
361
362 /* native_method_symbol ********************************************************
363
364    Generate a method-symbol string out of the class name and the
365    method name.
366
367 *******************************************************************************/
368
369 static utf *native_method_symbol(utf *classname, utf *methodname)
370 {
371         char *name;
372         s4    namelen;
373         char *utf_ptr;
374         char *utf_endptr;
375         u2    c;
376         u4    pos;
377         s4    dumpsize;
378         utf  *u;
379
380         /* mark memory */
381
382         dumpsize = dump_size();
383
384         /* Calculate length of native function name.  We multiply the
385            class and method name length by 6 as this is the maxium
386            escape-sequence that can be generated (unicode). */
387
388         namelen =
389                 strlen("Java_") +
390                 utf_get_number_of_u2s(classname) * 6 +
391                 strlen("_") +
392                 utf_get_number_of_u2s(methodname) * 6 +
393                 strlen("0");
394
395         /* allocate memory */
396
397         name = DMNEW(char, namelen);
398
399         /* generate name of native functions */
400
401         strcpy(name, "Java_");
402         pos = strlen("Java_");
403
404         utf_ptr    = classname->text;
405         utf_endptr = UTF_END(classname);
406
407         for (; utf_ptr < utf_endptr; utf_ptr++, pos++) {
408                 c   = *utf_ptr;
409                 pos = native_insert_char(name, pos, c);
410         }
411
412         /* seperator between class and method */
413
414         name[pos++] = '_';
415
416         utf_ptr    = methodname->text;
417         utf_endptr = UTF_END(methodname);
418
419         for (; utf_ptr < utf_endptr; utf_ptr++, pos++) {
420                 c   = *utf_ptr;
421                 pos = native_insert_char(name, pos, c);
422         }
423
424         /* close string */
425
426         name[pos] = '\0';
427
428         /* check for an buffer overflow */
429
430         assert(pos <= namelen);
431
432         /* make a utf-string */
433
434         u = utf_new_char(name);
435
436         /* release memory */
437
438         dump_release(dumpsize);
439
440         return u;
441 }
442
443
444 /* native_method_register ******************************************************
445
446    Register a native method in the native method table.
447
448 *******************************************************************************/
449
450 void native_method_register(utf *classname, const JNINativeMethod *methods,
451                                                         int32_t count)
452 {
453         native_methods_node_t *nmn;
454         utf                   *name;
455         utf                   *descriptor;
456         int32_t                i;
457
458         /* insert all methods passed */
459
460         for (i = 0; i < count; i++) {
461                 if (opt_verbosejni) {
462                         printf("[Registering JNI native method ");
463                         utf_display_printable_ascii_classname(classname);
464                         printf(".%s]\n", methods[i].name);
465                 }
466
467                 /* generate the utf8 names */
468
469                 name       = utf_new_char(methods[i].name);
470                 descriptor = utf_new_char(methods[i].signature);
471
472                 /* allocate a new tree node */
473
474                 nmn = NEW(native_methods_node_t);
475
476                 nmn->classname  = classname;
477                 nmn->name       = name;
478                 nmn->descriptor = descriptor;
479                 nmn->function   = (functionptr) (ptrint) methods[i].fnPtr;
480
481                 /* insert the method into the tree */
482
483                 avl_insert(tree_native_methods, nmn);
484         }
485 }
486
487
488 /* native_method_find **********************************************************
489
490    Find a native method in the native method table.
491
492 *******************************************************************************/
493
494 static functionptr native_method_find(methodinfo *m)
495 {
496         native_methods_node_t  tmpnmn;
497         native_methods_node_t *nmn;
498
499         /* fill the temporary structure used for searching the tree */
500
501         tmpnmn.classname  = m->class->name;
502         tmpnmn.name       = m->name;
503         tmpnmn.descriptor = m->descriptor;
504
505         /* find the entry in the AVL-tree */
506
507         nmn = avl_find(tree_native_methods, &tmpnmn);
508
509         if (nmn == NULL)
510                 return NULL;
511
512         return nmn->function;
513 }
514
515
516 /* native_library_open *********************************************************
517
518    Open a native library with the given utf8 name.
519
520 *******************************************************************************/
521
522 #if defined(ENABLE_LTDL)
523 lt_dlhandle native_library_open(utf *filename)
524 {
525         lt_dlhandle handle;
526
527         if (opt_verbosejni) {
528                 printf("[Loading native library ");
529                 utf_display_printable_ascii(filename);
530                 printf(" ... ");
531         }
532
533         /* try to open the library */
534
535         handle = lt_dlopen(filename->text);
536
537         if (handle == NULL) {
538                 if (opt_verbose) {
539                         log_start();
540                         log_print("native_library_load: lt_dlopen failed: ");
541                         log_print(lt_dlerror());
542                         log_finish();
543                 }
544
545                 return NULL;
546         }
547
548         return handle;
549 }
550 #endif
551
552
553 /* native_library_add **********************************************************
554
555    Adds an entry to the native library hashtable.
556
557 *******************************************************************************/
558
559 #if defined(ENABLE_LTDL)
560 void native_library_add(utf *filename, classloader *loader, lt_dlhandle handle)
561 {
562         hashtable_classloader_entry    *cle;
563         hashtable_library_loader_entry *le;
564         hashtable_library_name_entry   *ne; /* library name                       */
565         u4   key;                           /* hashkey                            */
566         u4   slot;                          /* slot in hashtable                  */
567
568         LOCK_MONITOR_ENTER(hashtable_library->header);
569
570         /* insert loader into the classloader hashtable */
571
572         cle = loader_hashtable_classloader_add(loader);
573
574         /* normally addresses are aligned to 4, 8 or 16 bytes */
575
576         key  = ((u4) (ptrint) cle) >> 4;        /* align to 16-byte boundaries    */
577         slot = key & (hashtable_library->size - 1);
578         le   = hashtable_library->ptr[slot];
579
580         /* search external hash chain for the entry */
581
582         while (le) {
583                 if (le->cle == cle)
584                         break;
585
586                 le = le->hashlink;                  /* next element in external chain */
587         }
588
589         /* no loader found? create a new entry */
590
591         if (le == NULL) {
592                 le = NEW(hashtable_library_loader_entry);
593
594                 le->cle   = cle;
595                 le->namelink = NULL;
596
597                 /* insert entry into hashtable */
598
599                 le->hashlink =
600                         (hashtable_library_loader_entry *) hashtable_library->ptr[slot];
601                 hashtable_library->ptr[slot] = le;
602
603                 /* update number of hashtable-entries */
604
605                 hashtable_library->entries++;
606         }
607
608
609         /* search for library name */
610
611         ne = le->namelink;
612
613         while (ne) {
614                 if (ne->name == filename) {
615                         LOCK_MONITOR_EXIT(hashtable_library->header);
616
617                         return;
618                 }
619
620                 ne = ne->hashlink;                  /* next element in external chain */
621         }
622
623         /* not found? add the library name to the classloader */
624
625         ne = NEW(hashtable_library_name_entry);
626
627         ne->name   = filename;
628         ne->handle = handle;
629
630         /* insert entry into external chain */
631
632         ne->hashlink = le->namelink;
633         le->namelink = ne;
634
635         LOCK_MONITOR_EXIT(hashtable_library->header);
636 }
637 #endif
638
639
640 /* native_library_find *********************************************************
641
642    Find an entry in the native library hashtable.
643
644 *******************************************************************************/
645
646 #if defined(ENABLE_LTDL)
647 hashtable_library_name_entry *native_library_find(utf *filename,
648                                                                                                   classloader *loader)
649 {
650         hashtable_classloader_entry    *cle;
651         hashtable_library_loader_entry *le;
652         hashtable_library_name_entry   *ne; /* library name                       */
653         u4   key;                           /* hashkey                            */
654         u4   slot;                          /* slot in hashtable                  */
655
656         /* search loader in the classloader hashtable */
657
658         cle = loader_hashtable_classloader_find(loader);
659
660         if (!cle)
661                 return NULL;
662
663         /* normally addresses are aligned to 4, 8 or 16 bytes */
664
665         key  = ((u4) (ptrint) cle) >> 4;        /* align to 16-byte boundaries    */
666         slot = key & (hashtable_library->size - 1);
667         le   = hashtable_library->ptr[slot];
668
669         /* search external hash chain for the entry */
670
671         while (le) {
672                 if (le->cle == cle)
673                         break;
674
675                 le = le->hashlink;                  /* next element in external chain */
676         }
677
678         /* no loader found? return NULL */
679
680         if (le == NULL)
681                 return NULL;
682
683         /* search for library name */
684
685         ne = le->namelink;
686
687         while (ne) {
688                 if (ne->name == filename)
689                         return ne;
690
691                 ne = ne->hashlink;                  /* next element in external chain */
692         }
693
694         /* return entry, if no entry was found, ne is NULL */
695
696         return ne;
697 }
698 #endif /* !defined(WITH_STATIC_CLASSPATH) */
699
700
701 /* native_findfunction *********************************************************
702
703    Looks up a method (must have the same class name, method name,
704    descriptor and 'static'ness) and returns a function pointer to it.
705    Returns: function pointer or NULL (if there is no such method)
706
707    Remark: For faster operation, the names/descriptors are converted
708    from C strings to Unicode the first time this function is called.
709
710 *******************************************************************************/
711
712 #if defined(WITH_STATIC_CLASSPATH)
713 functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
714                                                                 bool isstatic)
715 {
716         /* entry of table for fast string comparison */
717         struct nativecompref *n;
718         s4 i;
719
720         isstatic = isstatic ? true : false;
721         
722         if (!nativecompdone) {
723                 for (i = 0; i < NATIVETABLESIZE; i++) {
724                         nativecomptable[i].classname  = 
725                                 utf_new_char(nativetable[i].classname);
726
727                         nativecomptable[i].methodname = 
728                                 utf_new_char(nativetable[i].methodname);
729
730                         nativecomptable[i].descriptor =
731                                 utf_new_char(nativetable[i].descriptor);
732
733                         nativecomptable[i].isstatic   = nativetable[i].isstatic;
734                         nativecomptable[i].func       = nativetable[i].func;
735                 }
736
737                 nativecompdone = true;
738         }
739
740         for (i = 0; i < NATIVETABLESIZE; i++) {
741                 n = &(nativecomptable[i]);
742
743                 if (cname == n->classname && mname == n->methodname &&
744                     desc == n->descriptor && isstatic == n->isstatic)
745                         return n->func;
746         }
747
748         /* no function was found, throw exception */
749
750         exceptions_throw_unsatisfiedlinkerror(mname);
751
752         return NULL;
753 }
754 #endif /* defined(WITH_STATIC_CLASSPATH) */
755
756
757 /* native_resolve_function *****************************************************
758
759    Resolves a native function, maybe from a dynamic library.
760
761 *******************************************************************************/
762
763 functionptr native_resolve_function(methodinfo *m)
764 {
765         classloader                    *cl;
766         utf                            *name;
767         utf                            *newname;
768         functionptr                     f;
769 #if defined(ENABLE_LTDL)
770         hashtable_library_loader_entry *le;
771         hashtable_library_name_entry   *ne;
772         u4                              key;    /* hashkey                        */
773         u4                              slot;   /* slot in hashtable              */
774 #endif
775 #if defined(WITH_CLASSPATH_SUN)
776         methodinfo                     *method_findNative;
777         java_handle_t                  *s;
778 #endif
779
780         cl = m->class->classloader;
781
782         /* verbose output */
783
784         if (opt_verbosejni) {
785                 printf("[Dynamic-linking native method ");
786                 utf_display_printable_ascii_classname(m->class->name);
787                 printf(".");
788                 utf_display_printable_ascii(m->name);
789                 printf(" ... ");
790         }
791
792         /* generate method symbol string */
793
794         name = native_method_symbol(m->class->name, m->name);
795
796         /* generate overloaded function (having the types in it's name)           */
797
798         newname = native_make_overloaded_function(name, m->descriptor);
799
800         /* check the library hash entries of the classloader of the
801            methods's class  */
802
803         f = NULL;
804
805 #if defined(ENABLE_LTDL)
806         /* normally addresses are aligned to 4, 8 or 16 bytes */
807
808         key  = ((u4) (ptrint) cl) >> 4;                       /* align to 16-byte */
809         slot = key & (hashtable_library->size - 1);
810         le   = hashtable_library->ptr[slot];
811
812         /* iterate through loaders in this hash slot */
813
814         while ((le != NULL) && (f == NULL)) {
815                 /* iterate through names in this loader */
816
817                 ne = le->namelink;
818                         
819                 while ((ne != NULL) && (f == NULL)) {
820                         f = (functionptr) (ptrint) lt_dlsym(ne->handle, name->text);
821
822                         if (f == NULL)
823                                 f = (functionptr) (ptrint) lt_dlsym(ne->handle, newname->text);
824
825                         ne = ne->hashlink;
826                 }
827
828                 le = le->hashlink;
829         }
830
831 # if defined(WITH_CLASSPATH_SUN)
832         if (f == NULL) {
833                 /* We can resolve the function directly from
834                    java.lang.ClassLoader as it's a static function. */
835                 /* XXX should be done in native_init */
836
837                 method_findNative =
838                         class_resolveclassmethod(class_java_lang_ClassLoader,
839                                                                          utf_findNative,
840                                                                          utf_java_lang_ClassLoader_java_lang_String__J,
841                                                                          class_java_lang_ClassLoader,
842                                                                          true);
843
844                 if (method_findNative == NULL)
845                         return NULL;
846
847                 /* try the normal name */
848
849                 s = javastring_new(name);
850
851                 f = (functionptr) (intptr_t) vm_call_method_long(method_findNative,
852                                                                                                                  NULL, cl, s);
853
854                 /* if not found, try the mangled name */
855
856                 if (f == NULL) {
857                         s = javastring_new(newname);
858
859                         f = (functionptr) (intptr_t) vm_call_method_long(method_findNative,
860                                                                                                                          NULL, cl, s);
861                 }
862         }
863 # endif
864
865         if (f != NULL)
866                 if (opt_verbosejni)
867                         printf("JNI ]\n");
868 #endif
869
870         /* If not found, try to find the native function symbol in the
871            main program. */
872
873         if (f == NULL) {
874                 f = native_method_find(m);
875
876                 if (f != NULL)
877                         if (opt_verbosejni)
878                                 printf("internal ]\n");
879         }
880
881 #if defined(ENABLE_JVMTI)
882         /* fire Native Method Bind event */
883         if (jvmti) jvmti_NativeMethodBind(m, f, &f);
884 #endif
885
886         /* no symbol found? throw exception */
887
888         if (f == NULL) {
889                 if (opt_verbosejni)
890                         printf("failed ]\n");
891
892                 exceptions_throw_unsatisfiedlinkerror(m->name);
893         }
894
895         return f;
896 }
897 #endif /* !defined(WITH_STATIC_CLASSPATH) */
898
899
900 /* native_new_and_init *********************************************************
901
902    Creates a new object on the heap and calls the initializer.
903    Returns the object pointer or NULL if memory is exhausted.
904                         
905 *******************************************************************************/
906
907 java_handle_t *native_new_and_init(classinfo *c)
908 {
909         methodinfo    *m;
910         java_handle_t *o;
911
912         if (c == NULL)
913                 vm_abort("native_new_and_init: c == NULL");
914
915         /* create object */
916
917         o = builtin_new(c);
918         
919         if (o == NULL)
920                 return NULL;
921
922         /* try to find the initializer */
923
924         m = class_findmethod(c, utf_init, utf_void__void);
925                                                       
926         /* ATTENTION: returning the object here is ok, since the class may
927        not have an initializer */
928
929         if (m == NULL)
930                 return o;
931
932         /* call initializer */
933
934         (void) vm_call_method(m, o);
935
936         return o;
937 }
938
939
940 java_handle_t *native_new_and_init_string(classinfo *c, java_handle_t *s)
941 {
942         methodinfo    *m;
943         java_handle_t *o;
944
945         if (c == NULL)
946                 vm_abort("native_new_and_init_string: c == NULL");
947
948         /* create object */
949
950         o = builtin_new(c);
951
952         if (o == NULL)
953                 return NULL;
954
955         /* find initializer */
956
957         m = class_findmethod(c, utf_init, utf_java_lang_String__void);
958
959         /* initializer not found */
960
961         if (m == NULL)
962                 return NULL;
963
964         /* call initializer */
965
966         (void) vm_call_method(m, o, s);
967
968         return o;
969 }
970
971
972 /*
973  * These are local overrides for various environment variables in Emacs.
974  * Please do not remove this and leave it at the end of the file, where
975  * Emacs will automagically detect them.
976  * ---------------------------------------------------------------------
977  * Local variables:
978  * mode: c
979  * indent-tabs-mode: t
980  * c-basic-offset: 4
981  * tab-width: 4
982  * End:
983  */