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