Merged revisions 7797-7917 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 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_generate_stub_native(methodinfo *m, functionptr f)
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         abort();
188 }
189
190 void exceptions_throw_abstractmethoderror(void)
191 {
192         fprintf(stderr, "java.lang.AbstractMethodError\n");
193
194         abort();
195 }
196
197 void exceptions_throw_classcircularityerror(classinfo *c)
198 {
199         fprintf(stderr, "java.lang.ClassCircularityError: ");
200
201         utf_display_printable_ascii(c->name);
202         fputc('\n', stderr);
203
204         abort();
205 }
206
207 void exceptions_throw_classformaterror(classinfo *c, const char *message, ...)
208 {
209         va_list ap;
210
211         fprintf(stderr, "java.lang.ClassFormatError: ");
212
213         utf_display_printable_ascii(c->name);
214         fprintf(stderr, ": ");
215
216         va_start(ap, message);
217         vfprintf(stderr, message, ap);
218         va_end(ap);
219
220         fputc('\n', stderr);
221
222         abort();
223 }
224
225 void exceptions_throw_incompatibleclasschangeerror(classinfo *c)
226 {
227         fprintf(stderr, "java.lang.IncompatibleClassChangeError: ");
228
229         if (c != NULL)
230                 utf_fprint_printable_ascii_classname(stderr, c->name);
231
232         fputc('\n', stderr);
233
234         abort();
235 }
236
237 void exceptions_throw_internalerror(const char *message, ...)
238 {
239         va_list ap;
240
241         fprintf(stderr, "java.lang.InternalError: ");
242
243         va_start(ap, message);
244         vfprintf(stderr, message, ap);
245         va_end(ap);
246
247         abort();
248 }
249
250 void exceptions_throw_linkageerror(const char *message, classinfo *c)
251 {
252         fprintf(stderr, "java.lang.LinkageError: %s", message);
253
254         if (c != NULL)
255                 utf_fprint_printable_ascii_classname(stderr, c->name);
256
257         fputc('\n', stderr);
258
259         abort();
260 }
261
262 void exceptions_throw_noclassdeffounderror(utf *name)
263 {
264         fprintf(stderr, "java.lang.NoClassDefFoundError: ");
265         utf_fprint_printable_ascii(stderr, name);
266         fputc('\n', stderr);
267
268         abort();
269 }
270
271 void exceptions_throw_noclassdeffounderror_wrong_name(classinfo *c, utf *name)
272 {
273         fprintf(stderr, "java.lang.NoClassDefFoundError: ");
274         utf_fprint_printable_ascii(stderr, c->name);
275         fprintf(stderr, " (wrong name: ");
276         utf_fprint_printable_ascii(stderr, name);
277         fprintf(stderr, ")\n");
278
279         abort();
280 }
281
282 void exceptions_throw_verifyerror(methodinfo *m, const char *message)
283 {
284         fprintf(stderr, "java.lang.VerifyError: ");
285         utf_fprint_printable_ascii(stderr, m->name);
286         fprintf(stderr, ": %s", message);
287
288         abort();
289 }
290
291 void exceptions_throw_nosuchfielderror(classinfo *c, utf *name)
292 {
293         fprintf(stderr, "java.lang.NoSuchFieldError: ");
294         utf_fprint_printable_ascii(stderr, c->name);
295         fprintf(stderr, ".");
296         utf_fprint_printable_ascii(stderr, name);
297         fputc('\n', stderr);
298
299         abort();
300 }
301
302 void exceptions_throw_nosuchmethoderror(classinfo *c, utf *name, utf *desc)
303 {
304         fprintf(stderr, "java.lang.NoSuchMethodError: ");
305         utf_fprint_printable_ascii(stderr, c->name);
306         fprintf(stderr, ".");
307         utf_fprint_printable_ascii(stderr, name);
308         utf_fprint_printable_ascii(stderr, desc);
309         fputc('\n', stderr);
310
311         abort();
312 }
313
314 void exceptions_throw_unsupportedclassversionerror(classinfo *c,
315                                                                                                    const char *message, ...)
316 {
317         va_list ap;
318
319         fprintf(stderr, "java.lang.UnsupportedClassVersionError: " );
320
321         utf_display_printable_ascii(c->name);
322         fprintf(stderr, ": ");
323
324         va_start(ap, message);
325         vfprintf(stderr, message, ap);
326         va_end(ap);
327
328         fputc('\n', stderr);
329
330         abort();
331 }
332
333 void exceptions_throw_nullpointerexception(void)
334 {
335         fprintf(stderr, "java.lang.NullPointerException\n");
336
337         abort();
338 }
339
340 void classnotfoundexception_to_noclassdeffounderror(void)
341 {
342         /* Can that one happen? */
343
344         abort();
345 }
346
347
348 /* finalizer ******************************************************************/
349
350 void finalizer_notify(void)
351 {
352         vm_abort("finalizer_notify");
353 }
354
355 void finalizer_run(void *o, void *p)
356 {
357         vm_abort("finalizer_run");
358 }
359
360
361 /* gc *************************************************************************/
362
363 s8 gc_get_heap_size(void)
364 {
365         return 0;
366 }
367
368 s8 gc_get_free_bytes(void)
369 {
370         return 0;
371 }
372
373 s8 gc_get_total_bytes(void)
374 {
375         return 0;
376 }
377
378 s8 gc_get_max_heap_size(void)
379 {
380         return 0;
381 }
382
383
384 /* heap ***********************************************************************/
385
386 void *heap_alloc_uncollectable(u4 bytelength)
387 {
388         return calloc(bytelength, 1);
389 }
390
391 s4 heap_get_hashcode(java_objectheader *o)
392 {
393         return 0;
394 }
395
396
397 /* jit ************************************************************************/
398
399 void jit_invalidate_code(methodinfo *m)
400 {
401         vm_abort("jit_invalidate_code");
402 }
403
404
405 /* lock ***********************************************************************/
406
407 void lock_init_object_lock(java_objectheader *o)
408 {
409 }
410
411 bool lock_monitor_enter(java_objectheader *o)
412 {
413         return true;
414 }
415
416 bool lock_monitor_exit(java_objectheader *o)
417 {
418         return true;
419 }
420
421
422 /* md *************************************************************************/
423
424 void md_param_alloc(methoddesc *md)
425 {
426 }
427
428
429 /* memory *********************************************************************/
430
431 void *mem_alloc(s4 size)
432 {
433         /* real implementation in src/mm/memory.c clears memory */
434
435         return calloc(size, 1);
436 }
437
438 void *mem_realloc(void *src, s4 len1, s4 len2)
439 {
440         return realloc(src, len2);
441 }
442
443 void mem_free(void *m, s4 size)
444 {
445         free(m);
446 }
447
448 void *dump_alloc(s4 size)
449 {
450         return malloc(size);
451 }
452
453 void dump_release(s4 size)
454 {
455 }
456
457 s4 dump_size(void)
458 {
459         return 0;
460 }
461
462
463 /* properties *****************************************************************/
464
465 char *properties_get(char *key)
466 {
467         return NULL;
468 }
469
470
471 /* resolve ********************************************************************/
472
473 bool resolve_class_from_typedesc(typedesc *d, bool checkaccess, bool link, classinfo **result)
474 {
475         abort();
476
477         return false;
478 }
479
480 /* stupid resolving implementation used by resolve_classref_or_classinfo_eager */
481 /* This function does eager resolving without any access checks.               */
482
483 static classinfo * dummy_resolve_class_from_name(classinfo *referer,
484                                                  utf *classname,
485                                                  bool checkaccess)
486 {
487         classinfo *cls = NULL;
488         char *utf_ptr;
489         int len;
490         
491         assert(referer);
492         assert(classname);
493         
494         /* lookup if this class has already been loaded */
495
496         cls = classcache_lookup(referer->classloader, classname);
497
498         if (!cls) {
499                 /* resolve array types */
500
501                 if (classname->text[0] == '[') {
502                         utf_ptr = classname->text + 1;
503                         len = classname->blength - 1;
504
505                         /* classname is an array type name */
506
507                         switch (*utf_ptr) {
508                                 case 'L':
509                                         utf_ptr++;
510                                         len -= 2;
511                                         /* FALLTHROUGH */
512                                 case '[':
513                                         /* the component type is a reference type */
514                                         /* resolve the component type */
515                                         if ((cls = dummy_resolve_class_from_name(referer,
516                                                                            utf_new(utf_ptr,len),
517                                                                            checkaccess)) == NULL)
518                                                 return NULL; /* exception */
519
520                                         /* create the array class */
521                                         cls = class_array_of(cls,false);
522                                         if (!cls)
523                                                 return NULL; /* exception */
524                         }
525                 }
526
527                 /* load the class */
528                 if (!cls) {
529                         if (!(cls = load_class_from_classloader(classname,
530                                                                                                         referer->classloader)))
531                                 return false; /* exception */
532                 }
533         }
534
535         /* the class is now loaded */
536         assert(cls);
537         assert(cls->state & CLASS_LOADED);
538
539         return cls;
540 }
541
542
543 classinfo * resolve_classref_or_classinfo_eager(classref_or_classinfo cls,
544                                                                                                 bool checkaccess)
545 {
546         classinfo         *c;
547         
548         assert(cls.any);
549
550         if (IS_CLASSREF(cls)) {
551                 /* we must resolve this reference */
552
553                 if ((c = dummy_resolve_class_from_name(cls.ref->referer, cls.ref->name,
554                                                                                    checkaccess)) == NULL)
555                         return NULL;
556         }
557         else {
558                 /* cls has already been resolved */
559                 c = cls.cls;
560         }
561
562         assert(c);
563         assert(c->state & CLASS_LOADED);
564
565         /* succeeded */
566         return c;
567 }
568
569
570 /* stacktrace *****************************************************************/
571
572 java_objectarray *stacktrace_getClassContext()
573 {
574         return NULL;
575 }
576
577
578 /* threads ********************************************************************/
579
580 pthread_key_t threads_current_threadobject_key;
581
582 ptrint threads_get_current_tid(void)
583 {
584         return 0;
585 }
586
587 void threads_cast_stopworld(void)
588 {
589 }
590
591 void threads_cast_startworld(void)
592 {
593 }
594
595
596 /* vm *************************************************************************/
597
598 void vm_abort(const char *text, ...)
599 {
600         va_list ap;
601
602         /* print the log message */
603
604         va_start(ap, text);
605         vfprintf(stderr, text, ap);
606         va_end(ap);
607
608         /* now abort the VM */
609
610         abort();
611 }
612
613 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
614 {
615         return NULL;
616 }
617
618
619 /* XXX */
620
621 void stringtable_update(void)
622 {
623         log_println("stringtable_update: REMOVE ME!");
624 }
625
626 java_objectheader *literalstring_new(utf *u)
627 {
628         log_println("literalstring_new: REMOVE ME!");
629
630         return NULL;
631 }
632
633
634 void print_dynamic_super_statistics(void)
635 {
636 }
637
638
639 /*
640  * These are local overrides for various environment variables in Emacs.
641  * Please do not remove this and leave it at the end of the file, where
642  * Emacs will automagically detect them.
643  * ---------------------------------------------------------------------
644  * Local variables:
645  * mode: c
646  * indent-tabs-mode: t
647  * c-basic-offset: 4
648  * tab-width: 4
649  * End:
650  * vim:noexpandtab:sw=4:ts=4:
651  */