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