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