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