Merged revisions 8034-8055 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 8056 2007-06-10 14:49:57Z michi $
26
27 */
28
29
30 #include "config.h"
31
32 #include <assert.h>
33 #include <ctype.h>
34
35 #if !defined(WITH_STATIC_CLASSPATH)
36 # include <ltdl.h>
37 #endif
38
39 #include "vm/types.h"
40
41 #include "mm/memory.h"
42
43 #include "native/jni.h"
44 #include "native/native.h"
45
46 #include "native/vm/nativevm.h"
47
48 #include "threads/lock-common.h"
49
50 #include "toolbox/avl.h"
51 #include "toolbox/hashtable.h"
52 #include "toolbox/logging.h"
53
54 #include "vm/builtin.h"
55 #include "vm/exceptions.h"
56 #include "vm/global.h"
57 #include "vm/stringlocal.h"
58 #include "vm/vm.h"
59
60 #include "vm/jit/asmpart.h"
61 #include "vm/jit/jit.h"
62
63 #include "vmcore/loader.h"
64 #include "vmcore/options.h"
65 #include "vm/resolve.h"
66
67 #if defined(ENABLE_JVMTI)
68 #include "native/jvmti/cacaodbg.h"
69 #endif
70
71
72 /* include table of native functions ******************************************/
73
74 #if defined(WITH_STATIC_CLASSPATH)
75 # include "native/nativetable.inc"
76 #endif
77
78
79 /* tables for methods *********************************************************/
80
81 #if defined(WITH_STATIC_CLASSPATH)
82 #define NATIVETABLESIZE  (sizeof(nativetable)/sizeof(struct nativeref))
83
84 /* table for fast string comparison */
85 static nativecompref nativecomptable[NATIVETABLESIZE];
86
87 /* string comparsion table initialized */
88 static bool nativecompdone = false;
89 #endif
90
91
92 /* global variables ***********************************************************/
93
94 static avl_tree_t *tree_native_methods;
95 static hashtable *hashtable_library;
96
97
98 /* prototypes *****************************************************************/
99
100 static s4 native_tree_native_methods_comparator(const void *treenode, const void *node);
101
102
103 /* native_init *****************************************************************
104
105    Initializes the native subsystem.
106
107 *******************************************************************************/
108
109 bool native_init(void)
110 {
111 #if !defined(WITH_STATIC_CLASSPATH)
112         /* initialize libltdl */
113
114         if (lt_dlinit())
115                 vm_abort("native_init: lt_dlinit failed: %s\n", lt_dlerror());
116
117         /* initialize library hashtable, 10 entries should be enough */
118
119         hashtable_library = NEW(hashtable);
120
121         hashtable_create(hashtable_library, 10);
122 #endif
123
124         /* initialize the native methods table */
125
126         tree_native_methods = avl_create(&native_tree_native_methods_comparator);
127
128         /* register the intern native functions */
129
130         if (!nativevm_init())
131                 return false;
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, JNINativeMethod *methods, s4 count)
451 {
452         native_methods_node_t *nmn;
453         utf                   *name;
454         utf                   *descriptor;
455         s4                     i;
456
457         /* insert all methods passed */
458
459         for (i = 0; i < count; i++) {
460                 if (opt_verbosejni) {
461                         printf("[Registering JNI native method ");
462                         utf_display_printable_ascii_classname(classname);
463                         printf(".%s]\n", methods[i].name);
464                 }
465
466                 /* generate the utf8 names */
467
468                 name       = utf_new_char(methods[i].name);
469                 descriptor = utf_new_char(methods[i].signature);
470
471                 /* allocate a new tree node */
472
473                 nmn = NEW(native_methods_node_t);
474
475                 nmn->classname  = classname;
476                 nmn->name       = name;
477                 nmn->descriptor = descriptor;
478                 nmn->function   = (functionptr) (ptrint) methods[i].fnPtr;
479
480                 /* insert the method into the tree */
481
482                 avl_insert(tree_native_methods, nmn);
483         }
484 }
485
486
487 /* native_method_find **********************************************************
488
489    Find a native method in the native method table.
490
491 *******************************************************************************/
492
493 static functionptr native_method_find(methodinfo *m)
494 {
495         native_methods_node_t  tmpnmn;
496         native_methods_node_t *nmn;
497
498         /* fill the temporary structure used for searching the tree */
499
500         tmpnmn.classname  = m->class->name;
501         tmpnmn.name       = m->name;
502         tmpnmn.descriptor = m->descriptor;
503
504         /* find the entry in the AVL-tree */
505
506         nmn = avl_find(tree_native_methods, &tmpnmn);
507
508         if (nmn == NULL)
509                 return NULL;
510
511         return nmn->function;
512 }
513
514
515 /* native_library_open *********************************************************
516
517    Open a native library with the given utf8 name.
518
519 *******************************************************************************/
520
521 #if !defined(WITH_STATIC_CLASSPATH)
522 lt_dlhandle native_library_open(utf *filename)
523 {
524         lt_dlhandle handle;
525
526         /* try to open the library */
527
528         handle = lt_dlopen(filename->text);
529
530         if (handle == NULL) {
531                 if (opt_verbose) {
532                         log_start();
533                         log_print("native_library_load: lt_dlopen failed: ");
534                         log_print(lt_dlerror());
535                         log_finish();
536                 }
537
538                 return NULL;
539         }
540
541         return handle;
542 }
543 #endif
544
545
546 /* native_library_add **********************************************************
547
548    Adds an entry to the native library hashtable.
549
550 *******************************************************************************/
551
552 #if !defined(WITH_STATIC_CLASSPATH)
553 void native_library_add(utf *filename, java_objectheader *loader,
554                                                 lt_dlhandle handle)
555 {
556         hashtable_classloader_entry    *cle;
557         hashtable_library_loader_entry *le;
558         hashtable_library_name_entry   *ne; /* library name                       */
559         u4   key;                           /* hashkey                            */
560         u4   slot;                          /* slot in hashtable                  */
561
562         LOCK_MONITOR_ENTER(hashtable_library->header);
563
564         /* insert loader into the classloader hashtable */
565
566         cle = loader_hashtable_classloader_add(loader);
567
568         /* normally addresses are aligned to 4, 8 or 16 bytes */
569
570         key  = ((u4) (ptrint) cle) >> 4;        /* align to 16-byte boundaries    */
571         slot = key & (hashtable_library->size - 1);
572         le   = hashtable_library->ptr[slot];
573
574         /* search external hash chain for the entry */
575
576         while (le) {
577                 if (le->cle == cle)
578                         break;
579
580                 le = le->hashlink;                  /* next element in external chain */
581         }
582
583         /* no loader found? create a new entry */
584
585         if (le == NULL) {
586                 le = NEW(hashtable_library_loader_entry);
587
588                 le->cle   = cle;
589                 le->namelink = NULL;
590
591                 /* insert entry into hashtable */
592
593                 le->hashlink =
594                         (hashtable_library_loader_entry *) hashtable_library->ptr[slot];
595                 hashtable_library->ptr[slot] = le;
596
597                 /* update number of hashtable-entries */
598
599                 hashtable_library->entries++;
600         }
601
602
603         /* search for library name */
604
605         ne = le->namelink;
606
607         while (ne) {
608                 if (ne->name == filename) {
609                         LOCK_MONITOR_EXIT(hashtable_library->header);
610
611                         return;
612                 }
613
614                 ne = ne->hashlink;                  /* next element in external chain */
615         }
616
617         /* not found? add the library name to the classloader */
618
619         ne = NEW(hashtable_library_name_entry);
620
621         ne->name   = filename;
622         ne->handle = handle;
623
624         /* insert entry into external chain */
625
626         ne->hashlink = le->namelink;
627         le->namelink = ne;
628
629         LOCK_MONITOR_EXIT(hashtable_library->header);
630 }
631 #endif /* !defined(WITH_STATIC_CLASSPATH) */
632
633
634 /* native_library_find *********************************************************
635
636    Find an entry in the native library hashtable.
637
638 *******************************************************************************/
639
640 #if !defined(WITH_STATIC_CLASSPATH)
641 hashtable_library_name_entry *native_library_find(utf *filename,
642                                                                                                   java_objectheader *loader)
643 {
644         hashtable_classloader_entry    *cle;
645         hashtable_library_loader_entry *le;
646         hashtable_library_name_entry   *ne; /* library name                       */
647         u4   key;                           /* hashkey                            */
648         u4   slot;                          /* slot in hashtable                  */
649
650         /* search loader in the classloader hashtable */
651
652         cle = loader_hashtable_classloader_find(loader);
653
654         if (!cle)
655                 return NULL;
656
657         /* normally addresses are aligned to 4, 8 or 16 bytes */
658
659         key  = ((u4) (ptrint) cle) >> 4;        /* align to 16-byte boundaries    */
660         slot = key & (hashtable_library->size - 1);
661         le   = hashtable_library->ptr[slot];
662
663         /* search external hash chain for the entry */
664
665         while (le) {
666                 if (le->cle == cle)
667                         break;
668
669                 le = le->hashlink;                  /* next element in external chain */
670         }
671
672         /* no loader found? return NULL */
673
674         if (le == NULL)
675                 return NULL;
676
677         /* search for library name */
678
679         ne = le->namelink;
680
681         while (ne) {
682                 if (ne->name == filename)
683                         return ne;
684
685                 ne = ne->hashlink;                  /* next element in external chain */
686         }
687
688         /* return entry, if no entry was found, ne is NULL */
689
690         return ne;
691 }
692 #endif /* !defined(WITH_STATIC_CLASSPATH) */
693
694
695 /* native_findfunction *********************************************************
696
697    Looks up a method (must have the same class name, method name,
698    descriptor and 'static'ness) and returns a function pointer to it.
699    Returns: function pointer or NULL (if there is no such method)
700
701    Remark: For faster operation, the names/descriptors are converted
702    from C strings to Unicode the first time this function is called.
703
704 *******************************************************************************/
705
706 #if defined(WITH_STATIC_CLASSPATH)
707 functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
708                                                                 bool isstatic)
709 {
710         /* entry of table for fast string comparison */
711         struct nativecompref *n;
712         s4 i;
713
714         isstatic = isstatic ? true : false;
715         
716         if (!nativecompdone) {
717                 for (i = 0; i < NATIVETABLESIZE; i++) {
718                         nativecomptable[i].classname  = 
719                                 utf_new_char(nativetable[i].classname);
720
721                         nativecomptable[i].methodname = 
722                                 utf_new_char(nativetable[i].methodname);
723
724                         nativecomptable[i].descriptor =
725                                 utf_new_char(nativetable[i].descriptor);
726
727                         nativecomptable[i].isstatic   = nativetable[i].isstatic;
728                         nativecomptable[i].func       = nativetable[i].func;
729                 }
730
731                 nativecompdone = true;
732         }
733
734         for (i = 0; i < NATIVETABLESIZE; i++) {
735                 n = &(nativecomptable[i]);
736
737                 if (cname == n->classname && mname == n->methodname &&
738                     desc == n->descriptor && isstatic == n->isstatic)
739                         return n->func;
740         }
741
742         /* no function was found, throw exception */
743
744         *exceptionptr =
745                         new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
746                                                                          mname);
747
748         return NULL;
749 }
750 #endif /* defined(WITH_STATIC_CLASSPATH) */
751
752
753 /* native_resolve_function *****************************************************
754
755    Resolves a native function, maybe from a dynamic library.
756
757 *******************************************************************************/
758
759 functionptr native_resolve_function(methodinfo *m)
760 {
761         utf                            *name;
762         utf                            *newname;
763         functionptr                     f;
764         hashtable_library_loader_entry *le;
765         hashtable_library_name_entry   *ne;
766         u4                              key;    /* hashkey                        */
767         u4                              slot;   /* slot in hashtable              */
768
769         /* verbose output */
770
771         if (opt_verbosejni) {
772                 printf("[Dynamic-linking native method ");
773                 utf_display_printable_ascii_classname(m->class->name);
774                 printf(".");
775                 utf_display_printable_ascii(m->name);
776                 printf(" ... ");
777         }
778
779         /* generate method symbol string */
780
781         name = native_method_symbol(m->class->name, m->name);
782
783         /* generate overloaded function (having the types in it's name)           */
784
785         newname = native_make_overloaded_function(name, m->descriptor);
786
787         /* check the library hash entries of the classloader of the
788            methods's class  */
789
790         f = NULL;
791
792         /* normally addresses are aligned to 4, 8 or 16 bytes */
793
794         key  = ((u4) (ptrint) m->class->classloader) >> 4;    /* align to 16-byte */
795         slot = key & (hashtable_library->size - 1);
796         le   = hashtable_library->ptr[slot];
797
798         /* iterate through loaders in this hash slot */
799
800         while ((le != NULL) && (f == NULL)) {
801                 /* iterate through names in this loader */
802
803                 ne = le->namelink;
804                         
805                 while ((ne != NULL) && (f == NULL)) {
806                         f = (functionptr) (ptrint) lt_dlsym(ne->handle, name->text);
807
808                         if (f == NULL)
809                                 f = (functionptr) (ptrint) lt_dlsym(ne->handle, newname->text);
810
811                         ne = ne->hashlink;
812                 }
813
814                 le = le->hashlink;
815         }
816
817         if (f != NULL)
818                 if (opt_verbosejni)
819                         printf("JNI ]\n");
820
821         /* If not found, try to find the native function symbol in the
822            main program. */
823
824         if (f == NULL) {
825                 f = native_method_find(m);
826
827                 if (f != NULL)
828                         if (opt_verbosejni)
829                                 printf("internal ]\n");
830         }
831
832 #if defined(ENABLE_JVMTI)
833         /* fire Native Method Bind event */
834         if (jvmti) jvmti_NativeMethodBind(m, f, &f);
835 #endif
836
837         /* no symbol found? throw exception */
838
839         if (f == NULL) {
840                 if (opt_verbosejni)
841                         printf("failed ]\n");
842
843                 exceptions_throw_unsatisfiedlinkerror(m->name);
844         }
845
846         return f;
847 }
848 #endif /* !defined(WITH_STATIC_CLASSPATH) */
849
850
851 /* native_new_and_init *********************************************************
852
853    Creates a new object on the heap and calls the initializer.
854    Returns the object pointer or NULL if memory is exhausted.
855                         
856 *******************************************************************************/
857
858 java_objectheader *native_new_and_init(classinfo *c)
859 {
860         methodinfo *m;
861         java_objectheader *o;
862
863         if (c == NULL)
864                 vm_abort("native_new_and_init: c == NULL");
865
866         /* create object */
867
868         o = builtin_new(c);
869         
870         if (o == NULL)
871                 return NULL;
872
873         /* try to find the initializer */
874
875         m = class_findmethod(c, utf_init, utf_void__void);
876                                                       
877         /* ATTENTION: returning the object here is ok, since the class may
878        not have an initializer */
879
880         if (m == NULL)
881                 return o;
882
883         /* call initializer */
884
885         (void) vm_call_method(m, o);
886
887         return o;
888 }
889
890
891 java_objectheader *native_new_and_init_string(classinfo *c, java_objectheader *s)
892 {
893         methodinfo        *m;
894         java_objectheader *o;
895
896         if (c == NULL)
897                 vm_abort("native_new_and_init_string: c == NULL");
898
899         /* create object */
900
901         o = builtin_new(c);
902
903         if (o == NULL)
904                 return NULL;
905
906         /* find initializer */
907
908         m = class_resolveclassmethod(c,
909                                                                  utf_init,
910                                                                  utf_java_lang_String__void,
911                                                                  NULL,
912                                                                  true);
913
914         /* initializer not found */
915
916         if (m == NULL)
917                 return NULL;
918
919         /* call initializer */
920
921         (void) vm_call_method(m, o, s);
922
923         return o;
924 }
925
926
927 java_objectheader *native_new_and_init_throwable(classinfo *c, java_objectheader *t)
928 {
929         java_objectheader *o;
930         methodinfo        *m;
931
932         if (c == NULL)
933                 vm_abort("native_new_and_init_throwable: c == NULL");
934
935         /* create object */
936
937         o = builtin_new(c);
938         
939         if (o == NULL)
940                 return NULL;
941
942         /* find initializer */
943
944         m = class_findmethod(c, utf_init, utf_java_lang_Throwable__void);
945                                                       
946         /* initializer not found */
947
948         if (m == NULL)
949                 return NULL;
950
951         /* call initializer */
952
953         (void) vm_call_method(m, o, t);
954
955         return o;
956 }
957
958
959 java_objectheader *native_new_and_init_exception(classinfo *c, java_objectheader *e)
960 {
961         java_objectheader *o;
962         methodinfo        *m;
963
964         if (c == NULL)
965                 vm_abort("native_new_and_init_exception: c == NULL");
966
967         /* create object */
968
969         o = builtin_new(c);
970         
971         if (o == NULL)
972                 return NULL;
973
974         /* find initializer */
975
976         m = class_findmethod(c, utf_init, utf_java_lang_Exception__V);
977                                                       
978         /* initializer not found */
979
980         if (m == NULL)
981                 return NULL;
982
983         /* call initializer */
984
985         (void) vm_call_method(m, o, e);
986
987         return o;
988 }
989
990
991 /*
992  * These are local overrides for various environment variables in Emacs.
993  * Please do not remove this and leave it at the end of the file, where
994  * Emacs will automagically detect them.
995  * ---------------------------------------------------------------------
996  * Local variables:
997  * mode: c
998  * indent-tabs-mode: t
999  * c-basic-offset: 4
1000  * tab-width: 4
1001  * End:
1002  */