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