b73599689d10260af935ee284dc511d890a36db9
[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 8318 2007-08-16 10:05:34Z 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 int64_t gc_get_heap_size(void)
369 {
370         return 0;
371 }
372
373 int64_t gc_get_free_bytes(void)
374 {
375         return 0;
376 }
377
378 int64_t gc_get_total_bytes(void)
379 {
380         return 0;
381 }
382
383 int64_t gc_get_max_heap_size(void)
384 {
385         return 0;
386 }
387
388
389 /* heap ***********************************************************************/
390
391 void *heap_alloc_uncollectable(uint32_t bytelength)
392 {
393         return calloc(bytelength, 1);
394 }
395
396
397 /* jit ************************************************************************/
398
399 void jit_invalidate_code(methodinfo *m)
400 {
401         vm_abort("jit_invalidate_code");
402 }
403
404
405 /* lock ***********************************************************************/
406
407 void lock_init_object_lock(java_object_t *o)
408 {
409 }
410
411 bool lock_monitor_enter(java_object_t *o)
412 {
413         return true;
414 }
415
416 bool lock_monitor_exit(java_object_t *o)
417 {
418         return true;
419 }
420
421
422 /* md *************************************************************************/
423
424 void md_param_alloc(methoddesc *md)
425 {
426 }
427
428 void md_param_alloc_native(methoddesc *md)
429 {
430 }
431
432
433 /* memory *********************************************************************/
434
435 void *mem_alloc(int32_t size)
436 {
437         /* real implementation in src/mm/memory.c clears memory */
438
439         return calloc(size, 1);
440 }
441
442 void *mem_realloc(void *src, int32_t len1, int32_t len2)
443 {
444         return realloc(src, len2);
445 }
446
447 void mem_free(void *m, int32_t size)
448 {
449         free(m);
450 }
451
452 void *dump_alloc(int32_t size)
453 {
454         return malloc(size);
455 }
456
457 void dump_release(int32_t size)
458 {
459 }
460
461 int32_t dump_size(void)
462 {
463         return 0;
464 }
465
466
467 /* primitive ******************************************************************/
468
469 classinfo *primitive_class_get_by_type(int type)
470 {
471         abort();
472         return NULL;
473 }
474
475 classinfo *primitive_class_get_by_char(char ch)
476 {
477         abort();
478         return NULL;
479 }
480
481
482 /* properties *****************************************************************/
483
484 void properties_add(char *key, char *value)
485 {
486 }
487
488 char *properties_get(char *key)
489 {
490         return NULL;
491 }
492
493
494 /* resolve ********************************************************************/
495
496 bool resolve_class_from_typedesc(typedesc *d, bool checkaccess, bool link, classinfo **result)
497 {
498         abort();
499
500         return false;
501 }
502
503 /* stupid resolving implementation used by resolve_classref_or_classinfo_eager */
504 /* This function does eager resolving without any access checks.               */
505
506 static classinfo * dummy_resolve_class_from_name(classinfo *referer,
507                                                  utf *classname,
508                                                  bool checkaccess)
509 {
510         classinfo *cls = NULL;
511         char *utf_ptr;
512         int len;
513         
514         assert(referer);
515         assert(classname);
516         
517         /* lookup if this class has already been loaded */
518
519         cls = classcache_lookup(referer->classloader, classname);
520
521         if (!cls) {
522                 /* resolve array types */
523
524                 if (classname->text[0] == '[') {
525                         utf_ptr = classname->text + 1;
526                         len = classname->blength - 1;
527
528                         /* classname is an array type name */
529
530                         switch (*utf_ptr) {
531                                 case 'L':
532                                         utf_ptr++;
533                                         len -= 2;
534                                         /* FALLTHROUGH */
535                                 case '[':
536                                         /* the component type is a reference type */
537                                         /* resolve the component type */
538                                         if ((cls = dummy_resolve_class_from_name(referer,
539                                                                            utf_new(utf_ptr,len),
540                                                                            checkaccess)) == NULL)
541                                                 return NULL; /* exception */
542
543                                         /* create the array class */
544                                         cls = class_array_of(cls,false);
545                                         if (!cls)
546                                                 return NULL; /* exception */
547                         }
548                 }
549
550                 /* load the class */
551                 if (!cls) {
552                         if (!(cls = load_class_from_classloader(classname,
553                                                                                                         referer->classloader)))
554                                 return false; /* exception */
555                 }
556         }
557
558         /* the class is now loaded */
559         assert(cls);
560         assert(cls->state & CLASS_LOADED);
561
562         return cls;
563 }
564
565
566 classinfo * resolve_classref_or_classinfo_eager(classref_or_classinfo cls,
567                                                                                                 bool checkaccess)
568 {
569         classinfo         *c;
570         
571         assert(cls.any);
572
573         if (IS_CLASSREF(cls)) {
574                 /* we must resolve this reference */
575
576                 if ((c = dummy_resolve_class_from_name(cls.ref->referer, cls.ref->name,
577                                                                                    checkaccess)) == NULL)
578                         return NULL;
579         }
580         else {
581                 /* cls has already been resolved */
582                 c = cls.cls;
583         }
584
585         assert(c);
586         assert(c->state & CLASS_LOADED);
587
588         /* succeeded */
589         return c;
590 }
591
592
593 /* stacktrace *****************************************************************/
594
595 java_handle_objectarray_t *stacktrace_getClassContext()
596 {
597         return NULL;
598 }
599
600
601 /* threads ********************************************************************/
602
603 intptr_t threads_get_current_tid(void)
604 {
605         return 0;
606 }
607
608 void threads_cast_stopworld(void)
609 {
610 }
611
612 void threads_cast_startworld(void)
613 {
614 }
615
616
617 /* vm *************************************************************************/
618
619 void vm_printconfig(void)
620 {
621 }
622
623 void vm_abort(const char *text, ...)
624 {
625         va_list ap;
626
627         /* print the log message */
628
629         va_start(ap, text);
630         vfprintf(stderr, text, ap);
631         va_end(ap);
632
633         /* now abort the VM */
634
635         abort();
636 }
637
638 java_handle_t *vm_call_method(methodinfo *m, java_handle_t *o, ...)
639 {
640         return NULL;
641 }
642
643
644 /* XXX */
645
646 void stringtable_update(void)
647 {
648         log_println("stringtable_update: REMOVE ME!");
649 }
650
651 java_object_t *literalstring_new(utf *u)
652 {
653         log_println("literalstring_new: REMOVE ME!");
654
655         return NULL;
656 }
657
658
659 void print_dynamic_super_statistics(void)
660 {
661 }
662
663
664 /*
665  * These are local overrides for various environment variables in Emacs.
666  * Please do not remove this and leave it at the end of the file, where
667  * Emacs will automagically detect them.
668  * ---------------------------------------------------------------------
669  * Local variables:
670  * mode: c
671  * indent-tabs-mode: t
672  * c-basic-offset: 4
673  * tab-width: 4
674  * End:
675  * vim:noexpandtab:sw=4:ts=4:
676  */