* Merged in twisti-branch.
[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: headers.c 6286 2007-01-10 10:03:38Z twisti $
26
27 */
28
29
30 #include "config.h"
31
32 #include <stdarg.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <assert.h>
36
37 #if defined(ENABLE_THREADS)
38 # include <pthread.h>
39 #endif
40
41 #include "toolbox/logging.h"
42
43 #include "vm/types.h"
44
45 #include "vm/global.h"
46 #include "vm/vm.h"
47
48 #include "vmcore/class.h"
49 #include "vmcore/method.h"
50 #include "vmcore/utf8.h"
51 #include "vmcore/classcache.h"
52 #include "vmcore/loader.h"
53
54
55 /* global variables ***********************************************************/
56
57 char *_Jv_bootclasspath;
58
59
60 void compiler_lock()
61 {
62 }
63
64 void compiler_unlock()
65 {
66 }
67
68 java_objectheader *javastring_new_slash_to_dot(utf *u)
69 {
70         vm_abort("javastring_new_slash_to_dot");
71
72         return NULL;
73 }
74
75
76 /* access *********************************************************************/
77
78 bool access_is_accessible_class(classinfo *referer, classinfo *cls)
79 {
80         return true;
81 }
82
83 bool access_is_accessible_member(classinfo *referer, classinfo *declarer,
84                                                                  s4 memberflags)
85 {
86         vm_abort("access_is_accessible_member");
87
88         return true;
89 }
90
91
92 /* asm ************************************************************************/
93
94 void asm_abstractmethoderror(void)
95 {
96         abort();
97 }
98
99 void intrp_asm_abstractmethoderror(void)
100 {
101         abort();
102 }
103
104 void asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out)
105 {
106         abort();
107 }
108
109 void intrp_asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out)
110 {
111         abort();
112 }
113
114
115 /* builtin ********************************************************************/
116
117 java_objectheader *builtin_clone(void *env, java_objectheader *o)
118 {
119         abort();
120
121         return NULL;
122 }
123
124 s4 builtin_isanysubclass(classinfo *sub, classinfo *super)
125 {
126         abort();
127
128         return 0;
129 }
130
131 java_objectheader *builtin_new(classinfo *c)
132 {
133         abort();
134
135         return NULL;
136 }
137
138 java_objectarray *builtin_anewarray(s4 size, classinfo *componentclass)
139 {
140         abort();
141
142         return NULL;
143 }
144
145
146 /* code ***********************************************************************/
147
148 void code_free_code_of_method(methodinfo *m)
149 {
150 }
151
152
153 methodinfo *code_get_methodinfo_for_pv(u1 *pv)
154 {
155         return NULL;
156 }
157
158
159 /* codegen ********************************************************************/
160
161 codeinfo *codegen_createnativestub(functionptr f, methodinfo *m)
162 {
163         return NULL;
164 }
165
166 u1 *createcompilerstub(methodinfo *m)
167 {
168         return NULL;
169 }
170
171 #if defined(ENABLE_INTRP)
172 u1 *intrp_createcompilerstub(methodinfo *m)
173 {
174         return NULL;
175 }
176 #endif
177
178 void removecompilerstub(u1 *stub)
179 {
180 }
181
182 void removenativestub(u1 *stub)
183 {
184 }
185
186
187 /* exceptions *****************************************************************/
188
189 void exceptions_clear_exception(void)
190 {
191 }
192
193 void exceptions_print_current_exception(void)
194 {
195 }
196
197 void exceptions_throw_abstractmethoderror(void)
198 {
199         fprintf(stderr, "java.lang.AbstractMethodError\n");
200
201         abort();
202 }
203
204 void exceptions_throw_classcircularityerror(classinfo *c)
205 {
206         fprintf(stderr, "java.lang.ClassCircularityError: ");
207
208         utf_display_printable_ascii(c->name);
209         fputc('\n', stderr);
210
211         abort();
212 }
213
214 void exceptions_throw_classformaterror(classinfo *c, const char *message, ...)
215 {
216         va_list ap;
217
218         fprintf(stderr, "java.lang.ClassFormatError: ");
219
220         utf_display_printable_ascii(c->name);
221         fprintf(stderr, ": ");
222
223         va_start(ap, message);
224         vfprintf(stderr, message, ap);
225         va_end(ap);
226
227         fputc('\n', stderr);
228
229         abort();
230 }
231
232 void exceptions_throw_incompatibleclasschangeerror(classinfo *c)
233 {
234         fprintf(stderr, "java.lang.IncompatibleClassChangeError: ");
235
236         if (c != NULL)
237                 utf_fprint_printable_ascii_classname(stderr, c->name);
238
239         fputc('\n', stderr);
240
241         abort();
242 }
243
244 void exceptions_throw_internalerror(const char *message, ...)
245 {
246         va_list ap;
247
248         fprintf(stderr, "java.lang.InternalError: ");
249
250         va_start(ap, message);
251         vfprintf(stderr, message, ap);
252         va_end(ap);
253
254         abort();
255 }
256
257 void exceptions_throw_linkageerror(const char *message, classinfo *c)
258 {
259         fprintf(stderr, "java.lang.LinkageError: %s", message);
260
261         if (c != NULL)
262                 utf_fprint_printable_ascii_classname(stderr, c->name);
263
264         fputc('\n', stderr);
265
266         abort();
267 }
268
269 void exceptions_throw_noclassdeffounderror(utf *name)
270 {
271         fprintf(stderr, "java.lang.NoClassDefFoundError: ");
272         utf_fprint_printable_ascii(stderr, name);
273         fputc('\n', stderr);
274
275         abort();
276 }
277
278 void exceptions_throw_noclassdeffounderror_wrong_name(classinfo *c, utf *name)
279 {
280         fprintf(stderr, "java.lang.NoClassDefFoundError: ");
281         utf_fprint_printable_ascii(stderr, c->name);
282         fprintf(stderr, " (wrong name: ");
283         utf_fprint_printable_ascii(stderr, name);
284         fprintf(stderr, ")\n");
285
286         abort();
287 }
288
289 void exceptions_throw_outofmemoryerror(void)
290 {
291         fprintf(stderr, "java.lang.OutOfMemoryError\n");
292
293         abort();
294 }
295
296 void exceptions_throw_verifyerror(methodinfo *m, const char *message)
297 {
298         fprintf(stderr, "java.lang.VerifyError: ");
299         utf_fprint_printable_ascii(stderr, m->name);
300         fprintf(stderr, ": %s", message);
301
302         abort();
303 }
304
305 void exceptions_throw_nosuchfielderror(classinfo *c, utf *name)
306 {
307         fprintf(stderr, "java.lang.NoSuchFieldError: ");
308         utf_fprint_printable_ascii(stderr, c->name);
309         fprintf(stderr, ".");
310         utf_fprint_printable_ascii(stderr, name);
311         fputc('\n', stderr);
312
313         abort();
314 }
315
316 void exceptions_throw_nosuchmethoderror(classinfo *c, utf *name, utf *desc)
317 {
318         fprintf(stderr, "java.lang.NoSuchMethodError: ");
319         utf_fprint_printable_ascii(stderr, c->name);
320         fprintf(stderr, ".");
321         utf_fprint_printable_ascii(stderr, name);
322         utf_fprint_printable_ascii(stderr, desc);
323         fputc('\n', stderr);
324
325         abort();
326 }
327
328 void exceptions_throw_unsupportedclassversionerror(classinfo *c,
329                                                                                                    const char *message, ...)
330 {
331         va_list ap;
332
333         fprintf(stderr, "java.lang.UnsupportedClassVersionError: " );
334
335         utf_display_printable_ascii(c->name);
336         fprintf(stderr, ": ");
337
338         va_start(ap, message);
339         vfprintf(stderr, message, ap);
340         va_end(ap);
341
342         fputc('\n', stderr);
343
344         abort();
345 }
346
347 void exceptions_throw_illegalaccessexception(classinfo *c)
348 {
349         fprintf(stderr, "java.lang.IllegalAccessException: ");
350
351         if (c != NULL)
352                 utf_fprint_printable_ascii_classname(stderr, c->name);
353
354         fputc('\n', stderr);
355
356         abort();
357 }
358
359 void exceptions_throw_nullpointerexception(void)
360 {
361         fprintf(stderr, "java.lang.NullPointerException\n");
362
363         abort();
364 }
365
366 void classnotfoundexception_to_noclassdeffounderror(void)
367 {
368         /* Can that one happen? */
369
370         abort();
371 }
372
373
374 /* finalizer ******************************************************************/
375
376 void finalizer_notify(void)
377 {
378         vm_abort("finalizer_notify");
379 }
380
381 void finalizer_run(void *o, void *p)
382 {
383         vm_abort("finalizer_run");
384 }
385
386
387 /* gc *************************************************************************/
388
389 s8 gc_get_heap_size(void)
390 {
391         return 0;
392 }
393
394 s8 gc_get_free_bytes(void)
395 {
396         return 0;
397 }
398
399 s8 gc_get_total_bytes(void)
400 {
401         return 0;
402 }
403
404 s8 gc_get_max_heap_size(void)
405 {
406         return 0;
407 }
408
409
410 /* heap ***********************************************************************/
411
412 void *heap_alloc_uncollectable(u4 bytelength)
413 {
414         return calloc(bytelength, 1);
415 }
416
417
418 /* jit ************************************************************************/
419
420 void jit_invalidate_code(methodinfo *m)
421 {
422         vm_abort("jit_invalidate_code");
423 }
424
425
426 /* lock ***********************************************************************/
427
428 void lock_init_object_lock(java_objectheader *o)
429 {
430 }
431
432 bool lock_monitor_enter(java_objectheader *o)
433 {
434         return true;
435 }
436
437 bool lock_monitor_exit(java_objectheader *o)
438 {
439         return true;
440 }
441
442
443 /* md *************************************************************************/
444
445 void md_param_alloc(methoddesc *md)
446 {
447 }
448
449
450 /* memory *********************************************************************/
451
452 void *mem_alloc(s4 size)
453 {
454         /* real implementation in src/mm/memory.c clears memory */
455
456         return calloc(size, 1);
457 }
458
459 void *mem_realloc(void *src, s4 len1, s4 len2)
460 {
461         return realloc(src, len2);
462 }
463
464 void mem_free(void *m, s4 size)
465 {
466         free(m);
467 }
468
469 void *dump_alloc(s4 size)
470 {
471         return malloc(size);
472 }
473
474 void dump_release(s4 size)
475 {
476 }
477
478 s4 dump_size(void)
479 {
480         return 0;
481 }
482
483
484 /* properties *****************************************************************/
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_objectarray *stacktrace_getClassContext()
594 {
595         return NULL;
596 }
597
598
599 /* threads ********************************************************************/
600
601 pthread_key_t threads_current_threadobject_key;
602
603 ptrint threads_get_current_tid(void)
604 {
605         return 0;
606 }
607
608
609 /* vm *************************************************************************/
610
611 void vm_abort(const char *text, ...)
612 {
613         va_list ap;
614
615         /* print the log message */
616
617         va_start(ap, text);
618         vfprintf(stderr, text, ap);
619         va_end(ap);
620
621         /* now abort the VM */
622
623         abort();
624 }
625
626 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
627 {
628         return NULL;
629 }
630
631
632 /* XXX */
633
634 void stringtable_update(void)
635 {
636         log_println("stringtable_update: REMOVE ME!");
637 }
638
639 java_objectheader *literalstring_new(utf *u)
640 {
641         log_println("literalstring_new: REMOVE ME!");
642
643         return NULL;
644 }
645
646
647 void print_dynamic_super_statistics(void)
648 {
649 }
650
651
652 /*
653  * These are local overrides for various environment variables in Emacs.
654  * Please do not remove this and leave it at the end of the file, where
655  * Emacs will automagically detect them.
656  * ---------------------------------------------------------------------
657  * Local variables:
658  * mode: c
659  * indent-tabs-mode: t
660  * c-basic-offset: 4
661  * tab-width: 4
662  * End:
663  * vim:noexpandtab:sw=4:ts=4:
664  */