* src/vm/resolve.c (resolve_class_from_name): Call
[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_classnotfoundexception(utf *name)
334 {
335         fprintf(stderr, "java.lang.ClassNotFoundException: ");
336         utf_fprint_printable_ascii(stderr, name);
337         fputc('\n', stderr);
338
339         abort();
340 }
341
342 void exceptions_throw_nullpointerexception(void)
343 {
344         fprintf(stderr, "java.lang.NullPointerException\n");
345
346         abort();
347 }
348
349
350 /* finalizer ******************************************************************/
351
352 void finalizer_notify(void)
353 {
354         vm_abort("finalizer_notify");
355 }
356
357 void finalizer_run(void *o, void *p)
358 {
359         vm_abort("finalizer_run");
360 }
361
362
363 /* gc *************************************************************************/
364
365 s8 gc_get_heap_size(void)
366 {
367         return 0;
368 }
369
370 s8 gc_get_free_bytes(void)
371 {
372         return 0;
373 }
374
375 s8 gc_get_total_bytes(void)
376 {
377         return 0;
378 }
379
380 s8 gc_get_max_heap_size(void)
381 {
382         return 0;
383 }
384
385
386 /* heap ***********************************************************************/
387
388 void *heap_alloc_uncollectable(u4 bytelength)
389 {
390         return calloc(bytelength, 1);
391 }
392
393
394 /* jit ************************************************************************/
395
396 void jit_invalidate_code(methodinfo *m)
397 {
398         vm_abort("jit_invalidate_code");
399 }
400
401
402 /* lock ***********************************************************************/
403
404 void lock_init_object_lock(java_objectheader *o)
405 {
406 }
407
408 bool lock_monitor_enter(java_objectheader *o)
409 {
410         return true;
411 }
412
413 bool lock_monitor_exit(java_objectheader *o)
414 {
415         return true;
416 }
417
418
419 /* md *************************************************************************/
420
421 void md_param_alloc(methoddesc *md)
422 {
423 }
424
425
426 /* memory *********************************************************************/
427
428 void *mem_alloc(s4 size)
429 {
430         /* real implementation in src/mm/memory.c clears memory */
431
432         return calloc(size, 1);
433 }
434
435 void *mem_realloc(void *src, s4 len1, s4 len2)
436 {
437         return realloc(src, len2);
438 }
439
440 void mem_free(void *m, s4 size)
441 {
442         free(m);
443 }
444
445 void *dump_alloc(s4 size)
446 {
447         return malloc(size);
448 }
449
450 void dump_release(s4 size)
451 {
452 }
453
454 s4 dump_size(void)
455 {
456         return 0;
457 }
458
459
460 /* properties *****************************************************************/
461
462 char *properties_get(char *key)
463 {
464         return NULL;
465 }
466
467
468 /* resolve ********************************************************************/
469
470 bool resolve_class_from_typedesc(typedesc *d, bool checkaccess, bool link, classinfo **result)
471 {
472         abort();
473
474         return false;
475 }
476
477 /* stupid resolving implementation used by resolve_classref_or_classinfo_eager */
478 /* This function does eager resolving without any access checks.               */
479
480 static classinfo * dummy_resolve_class_from_name(classinfo *referer,
481                                                  utf *classname,
482                                                  bool checkaccess)
483 {
484         classinfo *cls = NULL;
485         char *utf_ptr;
486         int len;
487         
488         assert(referer);
489         assert(classname);
490         
491         /* lookup if this class has already been loaded */
492
493         cls = classcache_lookup(referer->classloader, classname);
494
495         if (!cls) {
496                 /* resolve array types */
497
498                 if (classname->text[0] == '[') {
499                         utf_ptr = classname->text + 1;
500                         len = classname->blength - 1;
501
502                         /* classname is an array type name */
503
504                         switch (*utf_ptr) {
505                                 case 'L':
506                                         utf_ptr++;
507                                         len -= 2;
508                                         /* FALLTHROUGH */
509                                 case '[':
510                                         /* the component type is a reference type */
511                                         /* resolve the component type */
512                                         if ((cls = dummy_resolve_class_from_name(referer,
513                                                                            utf_new(utf_ptr,len),
514                                                                            checkaccess)) == NULL)
515                                                 return NULL; /* exception */
516
517                                         /* create the array class */
518                                         cls = class_array_of(cls,false);
519                                         if (!cls)
520                                                 return NULL; /* exception */
521                         }
522                 }
523
524                 /* load the class */
525                 if (!cls) {
526                         if (!(cls = load_class_from_classloader(classname,
527                                                                                                         referer->classloader)))
528                                 return false; /* exception */
529                 }
530         }
531
532         /* the class is now loaded */
533         assert(cls);
534         assert(cls->state & CLASS_LOADED);
535
536         return cls;
537 }
538
539
540 classinfo * resolve_classref_or_classinfo_eager(classref_or_classinfo cls,
541                                                                                                 bool checkaccess)
542 {
543         classinfo         *c;
544         
545         assert(cls.any);
546
547         if (IS_CLASSREF(cls)) {
548                 /* we must resolve this reference */
549
550                 if ((c = dummy_resolve_class_from_name(cls.ref->referer, cls.ref->name,
551                                                                                    checkaccess)) == NULL)
552                         return NULL;
553         }
554         else {
555                 /* cls has already been resolved */
556                 c = cls.cls;
557         }
558
559         assert(c);
560         assert(c->state & CLASS_LOADED);
561
562         /* succeeded */
563         return c;
564 }
565
566
567 /* stacktrace *****************************************************************/
568
569 java_objectarray *stacktrace_getClassContext()
570 {
571         return NULL;
572 }
573
574
575 /* threads ********************************************************************/
576
577 pthread_key_t threads_current_threadobject_key;
578
579 ptrint threads_get_current_tid(void)
580 {
581         return 0;
582 }
583
584 void threads_cast_stopworld(void)
585 {
586 }
587
588 void threads_cast_startworld(void)
589 {
590 }
591
592
593 /* vm *************************************************************************/
594
595 void vm_abort(const char *text, ...)
596 {
597         va_list ap;
598
599         /* print the log message */
600
601         va_start(ap, text);
602         vfprintf(stderr, text, ap);
603         va_end(ap);
604
605         /* now abort the VM */
606
607         abort();
608 }
609
610 java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
611 {
612         return NULL;
613 }
614
615
616 /* XXX */
617
618 void stringtable_update(void)
619 {
620         log_println("stringtable_update: REMOVE ME!");
621 }
622
623 java_objectheader *literalstring_new(utf *u)
624 {
625         log_println("literalstring_new: REMOVE ME!");
626
627         return NULL;
628 }
629
630
631 void print_dynamic_super_statistics(void)
632 {
633 }
634
635
636 /*
637  * These are local overrides for various environment variables in Emacs.
638  * Please do not remove this and leave it at the end of the file, where
639  * Emacs will automagically detect them.
640  * ---------------------------------------------------------------------
641  * Local variables:
642  * mode: c
643  * indent-tabs-mode: t
644  * c-basic-offset: 4
645  * tab-width: 4
646  * End:
647  * vim:noexpandtab:sw=4:ts=4:
648  */