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