* autogen.sh: Made executeable.
[cacao.git] / src / cacaoh / dummy.c
1 /* src/cacaoh/dummy.c - dummy functions for cacaoh
2
3    Copyright (C) 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 */
26
27
28 #include "config.h"
29
30 #include <assert.h>
31 #include <stdarg.h>
32 #include <stdint.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35
36 #include "mm/memory.h"
37
38 #include "native/llni.h"
39
40 #include "toolbox/logging.h"
41
42 #include "vm/global.h"
43 #include "vm/primitive.h"
44 #include "vm/vm.h"
45
46 #include "vmcore/class.h"
47 #include "vmcore/method.h"
48 #include "vmcore/utf8.h"
49 #include "vmcore/classcache.h"
50 #include "vmcore/loader.h"
51
52
53 /* global variables ***********************************************************/
54
55 char *_Jv_bootclasspath;
56
57
58 java_handle_t *javastring_new_slash_to_dot(utf *u)
59 {
60         vm_abort("javastring_new_slash_to_dot");
61
62         return NULL;
63 }
64
65
66 /* access *********************************************************************/
67
68 bool access_is_accessible_class(classinfo *referer, classinfo *cls)
69 {
70         return true;
71 }
72
73 bool access_is_accessible_member(classinfo *referer, classinfo *declarer,
74                                                                  int32_t memberflags)
75 {
76         vm_abort("access_is_accessible_member");
77
78         return true;
79 }
80
81
82 /* array **********************************************************************/
83
84 java_handle_t *array_objectarray_element_get(java_handle_objectarray_t *a, int32_t index)
85 {
86         java_handle_t *value;
87         int32_t        size;
88
89         if (a == NULL) {
90                 log_println("array_objectarray_element_get(a=%p, index=%d): NullPointerException", a, index);
91                 return NULL;
92         }
93
94         size = LLNI_array_size(a);
95
96         if ((index < 0) || (index > size)) {
97                 log_println("array_objectarray_element_get(a=%p, index=%d): ArrayIndexOutOfBoundsException", a, index);
98                 return NULL;
99         }
100
101         value = LLNI_array_direct(a, index);
102
103         return value;
104 }
105
106 void array_objectarray_element_set(java_handle_objectarray_t *a, int32_t index, java_handle_t *value)
107 {
108         int32_t size;
109
110         if (a == NULL) {
111                 log_println("array_objectarray_element_set(a=%p, index=%d): NullPointerException", a, index);
112                 return;
113         }
114
115         size = LLNI_array_size(a);
116
117         if ((index < 0) || (index > size)) {
118                 log_println("array_objectarray_element_set(a=%p, index=%d): ArrayIndexOutOfBoundsException", a, index);
119                 return;
120         }
121
122         LLNI_array_direct(a, index) = value;
123 }
124
125 int32_t array_length_get(java_handle_t *a)
126 {
127         if (a == NULL) {
128                 log_println("array_length_get(a=%p): NullPointerException", a);
129                 return 0;
130         }
131
132         return LLNI_array_size(a);
133 }
134
135
136 /* asm ************************************************************************/
137
138 void asm_abstractmethoderror(void)
139 {
140         abort();
141 }
142
143 void intrp_asm_abstractmethoderror(void)
144 {
145         abort();
146 }
147
148 void asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out)
149 {
150         abort();
151 }
152
153 void intrp_asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out)
154 {
155         abort();
156 }
157
158
159 /* builtin ********************************************************************/
160
161 java_handle_t *builtin_clone(void *env, java_handle_t *o)
162 {
163         abort();
164
165         return NULL;
166 }
167
168 int32_t builtin_isanysubclass(classinfo *sub, classinfo *super)
169 {
170         abort();
171
172         return 0;
173 }
174
175 java_handle_t *builtin_new(classinfo *c)
176 {
177         abort();
178
179         return NULL;
180 }
181
182 java_handle_objectarray_t *builtin_anewarray(int32_t size, classinfo *componentclass)
183 {
184         java_handle_objectarray_t *oa = (java_handle_objectarray_t*)mem_alloc(
185                 sizeof(java_array_t) + size * sizeof(java_object_t*));
186
187         if (oa != NULL) {
188                 LLNI_array_size(oa) = size;
189         }
190
191         return oa;
192 }
193
194 java_handle_bytearray_t *builtin_newarray_byte(int32_t size)
195 {
196         java_handle_bytearray_t *ba = (java_handle_bytearray_t*)mem_alloc(
197                 sizeof(java_array_t) + size * sizeof(int8_t));
198
199         if (ba != NULL) {
200                 LLNI_array_size(ba) = size;
201         }
202         
203         return ba;
204 }
205
206
207 /* code ***********************************************************************/
208
209 void code_free_code_of_method(methodinfo *m)
210 {
211 }
212
213
214 methodinfo *code_get_methodinfo_for_pv(u1 *pv)
215 {
216         return NULL;
217 }
218
219
220 /* codegen ********************************************************************/
221
222 u1 *codegen_generate_stub_compiler(methodinfo *m)
223 {
224         return NULL;
225 }
226
227 codeinfo *codegen_generate_stub_native(methodinfo *m, functionptr f)
228 {
229         return NULL;
230 }
231
232 #if defined(ENABLE_INTRP)
233 u1 *intrp_createcompilerstub(methodinfo *m)
234 {
235         return NULL;
236 }
237 #endif
238
239 void removecompilerstub(u1 *stub)
240 {
241 }
242
243 void removenativestub(u1 *stub)
244 {
245 }
246
247
248 /* exceptions *****************************************************************/
249
250 void exceptions_clear_exception(void)
251 {
252 }
253
254 void exceptions_print_current_exception(void)
255 {
256         abort();
257 }
258
259 void exceptions_throw_abstractmethoderror(void)
260 {
261         fprintf(stderr, "java.lang.AbstractMethodError\n");
262
263         abort();
264 }
265
266 void exceptions_throw_classcircularityerror(classinfo *c)
267 {
268         fprintf(stderr, "java.lang.ClassCircularityError: ");
269
270         utf_display_printable_ascii(c->name);
271         fputc('\n', stderr);
272
273         abort();
274 }
275
276 void exceptions_throw_classformaterror(classinfo *c, const char *message, ...)
277 {
278         va_list ap;
279
280         fprintf(stderr, "java.lang.ClassFormatError: ");
281
282         utf_display_printable_ascii(c->name);
283         fprintf(stderr, ": ");
284
285         va_start(ap, message);
286         vfprintf(stderr, message, ap);
287         va_end(ap);
288
289         fputc('\n', stderr);
290
291         abort();
292 }
293
294 void exceptions_throw_incompatibleclasschangeerror(classinfo *c)
295 {
296         fprintf(stderr, "java.lang.IncompatibleClassChangeError: ");
297
298         if (c != NULL)
299                 utf_fprint_printable_ascii_classname(stderr, c->name);
300
301         fputc('\n', stderr);
302
303         abort();
304 }
305
306 void exceptions_throw_internalerror(const char *message, ...)
307 {
308         va_list ap;
309
310         fprintf(stderr, "java.lang.InternalError: ");
311
312         va_start(ap, message);
313         vfprintf(stderr, message, ap);
314         va_end(ap);
315
316         abort();
317 }
318
319 void exceptions_throw_linkageerror(const char *message, classinfo *c)
320 {
321         fprintf(stderr, "java.lang.LinkageError: %s", message);
322
323         if (c != NULL)
324                 utf_fprint_printable_ascii_classname(stderr, c->name);
325
326         fputc('\n', stderr);
327
328         abort();
329 }
330
331 void exceptions_throw_noclassdeffounderror(utf *name)
332 {
333         fprintf(stderr, "java.lang.NoClassDefFoundError: ");
334         utf_fprint_printable_ascii(stderr, name);
335         fputc('\n', stderr);
336
337         abort();
338 }
339
340 void exceptions_throw_noclassdeffounderror_wrong_name(classinfo *c, utf *name)
341 {
342         fprintf(stderr, "java.lang.NoClassDefFoundError: ");
343         utf_fprint_printable_ascii(stderr, c->name);
344         fprintf(stderr, " (wrong name: ");
345         utf_fprint_printable_ascii(stderr, name);
346         fprintf(stderr, ")\n");
347
348         abort();
349 }
350
351 void exceptions_throw_verifyerror(methodinfo *m, const char *message)
352 {
353         fprintf(stderr, "java.lang.VerifyError: ");
354         utf_fprint_printable_ascii(stderr, m->name);
355         fprintf(stderr, ": %s", message);
356
357         abort();
358 }
359
360 void exceptions_throw_nosuchfielderror(classinfo *c, utf *name)
361 {
362         fprintf(stderr, "java.lang.NoSuchFieldError: ");
363         utf_fprint_printable_ascii(stderr, c->name);
364         fprintf(stderr, ".");
365         utf_fprint_printable_ascii(stderr, name);
366         fputc('\n', stderr);
367
368         abort();
369 }
370
371 void exceptions_throw_nosuchmethoderror(classinfo *c, utf *name, utf *desc)
372 {
373         fprintf(stderr, "java.lang.NoSuchMethodError: ");
374         utf_fprint_printable_ascii(stderr, c->name);
375         fprintf(stderr, ".");
376         utf_fprint_printable_ascii(stderr, name);
377         utf_fprint_printable_ascii(stderr, desc);
378         fputc('\n', stderr);
379
380         abort();
381 }
382
383 void exceptions_throw_unsupportedclassversionerror(classinfo *c,
384                                                                                                    const char *message, ...)
385 {
386         va_list ap;
387
388         fprintf(stderr, "java.lang.UnsupportedClassVersionError: " );
389
390         utf_display_printable_ascii(c->name);
391         fprintf(stderr, ": ");
392
393         va_start(ap, message);
394         vfprintf(stderr, message, ap);
395         va_end(ap);
396
397         fputc('\n', stderr);
398
399         abort();
400 }
401
402 void exceptions_throw_classnotfoundexception(utf *name)
403 {
404         fprintf(stderr, "java.lang.ClassNotFoundException: ");
405         utf_fprint_printable_ascii(stderr, name);
406         fputc('\n', stderr);
407
408         abort();
409 }
410
411 void exceptions_throw_nullpointerexception(void)
412 {
413         fprintf(stderr, "java.lang.NullPointerException\n");
414
415         abort();
416 }
417
418
419 /* finalizer ******************************************************************/
420
421 void finalizer_notify(void)
422 {
423         vm_abort("finalizer_notify");
424 }
425
426 void finalizer_run(void *o, void *p)
427 {
428         vm_abort("finalizer_run");
429 }
430
431
432 /* gc *************************************************************************/
433
434 int64_t gc_get_heap_size(void)
435 {
436         return 0;
437 }
438
439 int64_t gc_get_free_bytes(void)
440 {
441         return 0;
442 }
443
444 int64_t gc_get_total_bytes(void)
445 {
446         return 0;
447 }
448
449 int64_t gc_get_max_heap_size(void)
450 {
451         return 0;
452 }
453
454
455 /* heap ***********************************************************************/
456
457 void *heap_alloc_uncollectable(uint32_t bytelength)
458 {
459         return calloc(bytelength, 1);
460 }
461
462
463 /* jit ************************************************************************/
464
465 void jit_invalidate_code(methodinfo *m)
466 {
467         vm_abort("jit_invalidate_code");
468 }
469
470
471 /* lock ***********************************************************************/
472
473 void lock_init_object_lock(java_object_t *o)
474 {
475 }
476
477 bool lock_monitor_enter(java_object_t *o)
478 {
479         return true;
480 }
481
482 bool lock_monitor_exit(java_object_t *o)
483 {
484         return true;
485 }
486
487
488 /* md *************************************************************************/
489
490 void md_param_alloc(methoddesc *md)
491 {
492 }
493
494 void md_param_alloc_native(methoddesc *md)
495 {
496 }
497
498
499 /* memory *********************************************************************/
500
501 void *mem_alloc(int32_t size)
502 {
503         /* real implementation in src/mm/memory.c clears memory */
504
505         return calloc(size, 1);
506 }
507
508 void *mem_realloc(void *src, int32_t len1, int32_t len2)
509 {
510         return realloc(src, len2);
511 }
512
513 void mem_free(void *m, int32_t size)
514 {
515         free(m);
516 }
517
518 void *dump_alloc(int32_t size)
519 {
520         return malloc(size);
521 }
522
523 void dump_release(int32_t size)
524 {
525 }
526
527 int32_t dump_size(void)
528 {
529         return 0;
530 }
531
532
533 /* primitive ******************************************************************/
534
535 classinfo *primitive_arrayclass_get_by_type(int type)
536 {
537         return NULL;
538 }
539
540 classinfo *primitive_class_get_by_type(int type)
541 {
542         abort();
543         return NULL;
544 }
545
546 classinfo *primitive_class_get_by_char(char ch)
547 {
548         abort();
549         return NULL;
550 }
551
552
553 /* properties *****************************************************************/
554
555 void properties_add(char *key, char *value)
556 {
557 }
558
559 char *properties_get(char *key)
560 {
561         return NULL;
562 }
563
564
565 /* resolve ********************************************************************/
566
567 bool resolve_class_from_typedesc(typedesc *d, bool checkaccess, bool link, classinfo **result)
568 {
569         abort();
570
571         return false;
572 }
573
574 /* stupid resolving implementation used by resolve_classref_or_classinfo_eager */
575 /* This function does eager resolving without any access checks.               */
576
577 static classinfo * dummy_resolve_class_from_name(classinfo *referer,
578                                                  utf *classname,
579                                                  bool checkaccess)
580 {
581         classinfo *cls = NULL;
582         char *utf_ptr;
583         int len;
584         
585         assert(referer);
586         assert(classname);
587         
588         /* lookup if this class has already been loaded */
589
590         cls = classcache_lookup(referer->classloader, classname);
591
592         if (!cls) {
593                 /* resolve array types */
594
595                 if (classname->text[0] == '[') {
596                         utf_ptr = classname->text + 1;
597                         len = classname->blength - 1;
598
599                         /* classname is an array type name */
600
601                         switch (*utf_ptr) {
602                                 case 'L':
603                                         utf_ptr++;
604                                         len -= 2;
605                                         /* FALLTHROUGH */
606                                 case '[':
607                                         /* the component type is a reference type */
608                                         /* resolve the component type */
609                                         if ((cls = dummy_resolve_class_from_name(referer,
610                                                                            utf_new(utf_ptr,len),
611                                                                            checkaccess)) == NULL)
612                                                 return NULL; /* exception */
613
614                                         /* create the array class */
615                                         cls = class_array_of(cls,false);
616                                         if (!cls)
617                                                 return NULL; /* exception */
618                         }
619                 }
620
621                 /* load the class */
622                 if (!cls) {
623                         if (!(cls = load_class_from_classloader(classname,
624                                                                                                         referer->classloader)))
625                                 return false; /* exception */
626                 }
627         }
628
629         /* the class is now loaded */
630         assert(cls);
631         assert(cls->state & CLASS_LOADED);
632
633         return cls;
634 }
635
636
637 classinfo * resolve_classref_or_classinfo_eager(classref_or_classinfo cls,
638                                                                                                 bool checkaccess)
639 {
640         classinfo         *c;
641         
642         assert(cls.any);
643
644         if (IS_CLASSREF(cls)) {
645                 /* we must resolve this reference */
646
647                 if ((c = dummy_resolve_class_from_name(cls.ref->referer, cls.ref->name,
648                                                                                    checkaccess)) == NULL)
649                         return NULL;
650         }
651         else {
652                 /* cls has already been resolved */
653                 c = cls.cls;
654         }
655
656         assert(c);
657         assert(c->state & CLASS_LOADED);
658
659         /* succeeded */
660         return c;
661 }
662
663
664 /* stacktrace *****************************************************************/
665
666 java_handle_objectarray_t *stacktrace_getClassContext()
667 {
668         return NULL;
669 }
670
671
672 /* threads ********************************************************************/
673
674 intptr_t threads_get_current_tid(void)
675 {
676         return 0;
677 }
678
679 void threads_cast_stopworld(void)
680 {
681 }
682
683 void threads_cast_startworld(void)
684 {
685 }
686
687
688 /* vm *************************************************************************/
689
690 void vm_printconfig(void)
691 {
692 }
693
694 void vm_abort(const char *text, ...)
695 {
696         va_list ap;
697
698         /* print the log message */
699
700         va_start(ap, text);
701         vfprintf(stderr, text, ap);
702         va_end(ap);
703
704         /* now abort the VM */
705
706         abort();
707 }
708
709 java_handle_t *vm_call_method(methodinfo *m, java_handle_t *o, ...)
710 {
711         return NULL;
712 }
713
714
715 /* XXX */
716
717 void stringtable_update(void)
718 {
719         log_println("stringtable_update: REMOVE ME!");
720 }
721
722 java_object_t *literalstring_new(utf *u)
723 {
724         log_println("literalstring_new: REMOVE ME!");
725
726         return NULL;
727 }
728
729
730 void print_dynamic_super_statistics(void)
731 {
732 }
733
734
735 /*
736  * These are local overrides for various environment variables in Emacs.
737  * Please do not remove this and leave it at the end of the file, where
738  * Emacs will automagically detect them.
739  * ---------------------------------------------------------------------
740  * Local variables:
741  * mode: c
742  * indent-tabs-mode: t
743  * c-basic-offset: 4
744  * tab-width: 4
745  * End:
746  * vim:noexpandtab:sw=4:ts=4:
747  */