* src/vm/jit/i386/darwin/md-os.c (md_replace_executionstate_read):
[cacao.git] / src / cacaoh / dummy.c
1 /* src/cacaoh/dummy.c - dummy functions for cacaoh
2
3    Copyright (C) 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <assert.h>
29 #include <errno.h>
30 #include <stdarg.h>
31 #include <stdint.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34
35 #include "mm/memory.h"
36
37 #include "native/llni.h"
38
39 #include "toolbox/logging.h"
40
41 #include "vm/exceptions.h"
42 #include "vm/global.h"
43 #include "vm/primitive.h"
44 #include "vm/vm.h"
45
46 #include "vm/jit/code.h"
47
48 #include "vmcore/class.h"
49 #include "vmcore/classcache.h"
50 #include "vmcore/loader.h"
51 #include "vmcore/method.h"
52 #include "vmcore/utf8.h"
53 #include "vmcore/system.h"
54
55
56 /* global variables ***********************************************************/
57
58 bool  vm_initializing = true;
59 char *_Jv_bootclasspath;
60
61
62 java_handle_t *javastring_new_slash_to_dot(utf *u)
63 {
64         vm_abort("javastring_new_slash_to_dot");
65
66         return NULL;
67 }
68
69
70 /* access *********************************************************************/
71
72 bool access_is_accessible_class(classinfo *referer, classinfo *cls)
73 {
74         return true;
75 }
76
77 bool access_is_accessible_member(classinfo *referer, classinfo *declarer,
78                                                                  int32_t memberflags)
79 {
80         vm_abort("access_is_accessible_member");
81
82         return true;
83 }
84
85
86 /* array **********************************************************************/
87
88 java_handle_t *array_objectarray_element_get(java_handle_objectarray_t *a, int32_t index)
89 {
90         java_handle_t *value;
91         int32_t        size;
92
93         if (a == NULL) {
94                 log_println("array_objectarray_element_get(a=%p, index=%d): NullPointerException", a, index);
95                 return NULL;
96         }
97
98         size = LLNI_array_size(a);
99
100         if ((index < 0) || (index > size)) {
101                 log_println("array_objectarray_element_get(a=%p, index=%d): ArrayIndexOutOfBoundsException", a, index);
102                 return NULL;
103         }
104
105         value = LLNI_WRAP(LLNI_array_direct(a, index));
106
107         return value;
108 }
109
110 void array_objectarray_element_set(java_handle_objectarray_t *a, int32_t index, java_handle_t *value)
111 {
112         int32_t size;
113
114         if (a == NULL) {
115                 log_println("array_objectarray_element_set(a=%p, index=%d): NullPointerException", a, index);
116                 return;
117         }
118
119         size = LLNI_array_size(a);
120
121         if ((index < 0) || (index > size)) {
122                 log_println("array_objectarray_element_set(a=%p, index=%d): ArrayIndexOutOfBoundsException", a, index);
123                 return;
124         }
125
126         LLNI_array_direct(a, index) = LLNI_UNWRAP(value);
127 }
128
129 int32_t array_length_get(java_handle_t *a)
130 {
131         if (a == NULL) {
132                 log_println("array_length_get(a=%p): NullPointerException", a);
133                 return 0;
134         }
135
136         return LLNI_array_size(a);
137 }
138
139
140 /* asm ************************************************************************/
141
142 void asm_abstractmethoderror(void)
143 {
144         abort();
145 }
146
147 void intrp_asm_abstractmethoderror(void)
148 {
149         abort();
150 }
151
152 void asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out)
153 {
154         abort();
155 }
156
157 void intrp_asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out)
158 {
159         abort();
160 }
161
162
163 /* builtin ********************************************************************/
164
165 java_handle_t *builtin_clone(void *env, java_handle_t *o)
166 {
167         abort();
168
169         return NULL;
170 }
171
172 int32_t builtin_isanysubclass(classinfo *sub, classinfo *super)
173 {
174         abort();
175
176         return 0;
177 }
178
179 java_handle_t *builtin_new(classinfo *c)
180 {
181         abort();
182
183         return NULL;
184 }
185
186 java_handle_objectarray_t *builtin_anewarray(int32_t size, classinfo *componentclass)
187 {
188         java_objectarray_t *oa = (java_objectarray_t*) mem_alloc(
189                 sizeof(java_array_t) + size * sizeof(java_object_t*));
190         java_handle_objectarray_t *h = (java_handle_objectarray_t*) LLNI_WRAP(
191                 (java_object_t*) oa);
192
193         if (h != NULL) {
194                 LLNI_array_size(h) = size;
195         }
196
197         return h;
198 }
199
200 java_handle_bytearray_t *builtin_newarray_byte(int32_t size)
201 {
202         java_bytearray_t *ba = (java_bytearray_t*) mem_alloc(
203                 sizeof(java_array_t) + size * sizeof(int8_t));
204         java_handle_bytearray_t *h = (java_handle_bytearray_t*) LLNI_WRAP(
205                 (java_object_t*) ba);
206
207         if (h != NULL) {
208                 LLNI_array_size(h) = size;
209         }
210         
211         return h;
212 }
213
214
215 /* code ***********************************************************************/
216
217 void code_free_code_of_method(methodinfo *m)
218 {
219 }
220
221
222 methodinfo *code_get_methodinfo_for_pv(void *pv)
223 {
224         return NULL;
225 }
226
227
228 /* codegen ********************************************************************/
229
230 u1 *codegen_generate_stub_compiler(methodinfo *m)
231 {
232         return NULL;
233 }
234
235 codeinfo *codegen_generate_stub_native(methodinfo *m, functionptr f)
236 {
237         return NULL;
238 }
239
240 #if defined(ENABLE_INTRP)
241 u1 *intrp_createcompilerstub(methodinfo *m)
242 {
243         return NULL;
244 }
245 #endif
246
247 void removecompilerstub(u1 *stub)
248 {
249 }
250
251 void removenativestub(u1 *stub)
252 {
253 }
254
255
256 /* exceptions *****************************************************************/
257
258 void exceptions_clear_exception(void)
259 {
260 }
261
262 void exceptions_print_current_exception(void)
263 {
264         abort();
265 }
266
267 void exceptions_throw_abstractmethoderror(void)
268 {
269         fprintf(stderr, "java.lang.AbstractMethodError\n");
270
271         abort();
272 }
273
274 void exceptions_throw_classcircularityerror(classinfo *c)
275 {
276         fprintf(stderr, "java.lang.ClassCircularityError: ");
277
278         utf_display_printable_ascii(c->name);
279         fputc('\n', stderr);
280
281         abort();
282 }
283
284 void exceptions_throw_classformaterror(classinfo *c, const char *message, ...)
285 {
286         va_list ap;
287
288         fprintf(stderr, "java.lang.ClassFormatError: ");
289
290         utf_display_printable_ascii(c->name);
291         fprintf(stderr, ": ");
292
293         va_start(ap, message);
294         vfprintf(stderr, message, ap);
295         va_end(ap);
296
297         fputc('\n', stderr);
298
299         abort();
300 }
301
302 void exceptions_throw_incompatibleclasschangeerror(classinfo *c, const char *message)
303 {
304         fprintf(stderr, "java.lang.IncompatibleClassChangeError: ");
305
306         if (c != NULL)
307                 utf_fprint_printable_ascii_classname(stderr, c->name);
308
309         fputc('\n', stderr);
310
311         abort();
312 }
313
314 void exceptions_throw_internalerror(const char *message, ...)
315 {
316         va_list ap;
317
318         fprintf(stderr, "java.lang.InternalError: ");
319
320         va_start(ap, message);
321         vfprintf(stderr, message, ap);
322         va_end(ap);
323
324         abort();
325 }
326
327 void exceptions_throw_linkageerror(const char *message, classinfo *c)
328 {
329         fprintf(stderr, "java.lang.LinkageError: %s", message);
330
331         if (c != NULL)
332                 utf_fprint_printable_ascii_classname(stderr, c->name);
333
334         fputc('\n', stderr);
335
336         abort();
337 }
338
339 void exceptions_throw_noclassdeffounderror(utf *name)
340 {
341         fprintf(stderr, "java.lang.NoClassDefFoundError: ");
342         utf_fprint_printable_ascii(stderr, name);
343         fputc('\n', stderr);
344
345         abort();
346 }
347
348 void exceptions_throw_noclassdeffounderror_wrong_name(classinfo *c, utf *name)
349 {
350         fprintf(stderr, "java.lang.NoClassDefFoundError: ");
351         utf_fprint_printable_ascii(stderr, c->name);
352         fprintf(stderr, " (wrong name: ");
353         utf_fprint_printable_ascii(stderr, name);
354         fprintf(stderr, ")\n");
355
356         abort();
357 }
358
359 void exceptions_throw_verifyerror(methodinfo *m, const char *message, ...)
360 {
361         fprintf(stderr, "java.lang.VerifyError: ");
362         utf_fprint_printable_ascii(stderr, m->name);
363         fprintf(stderr, ": %s", message);
364
365         abort();
366 }
367
368 void exceptions_throw_nosuchfielderror(classinfo *c, utf *name)
369 {
370         fprintf(stderr, "java.lang.NoSuchFieldError: ");
371         utf_fprint_printable_ascii(stderr, c->name);
372         fprintf(stderr, ".");
373         utf_fprint_printable_ascii(stderr, name);
374         fputc('\n', stderr);
375
376         abort();
377 }
378
379 void exceptions_throw_nosuchmethoderror(classinfo *c, utf *name, utf *desc)
380 {
381         fprintf(stderr, "java.lang.NoSuchMethodError: ");
382         utf_fprint_printable_ascii(stderr, c->name);
383         fprintf(stderr, ".");
384         utf_fprint_printable_ascii(stderr, name);
385         utf_fprint_printable_ascii(stderr, desc);
386         fputc('\n', stderr);
387
388         abort();
389 }
390
391 void exceptions_throw_unsupportedclassversionerror(classinfo *c, u4 ma, u4 mi)
392 {
393         fprintf(stderr, "java.lang.UnsupportedClassVersionError: " );
394         utf_display_printable_ascii(c->name);
395         fprintf(stderr, " (Unsupported major.minor version %d.%d)\n", ma, mi);
396
397         abort();
398 }
399
400 void exceptions_throw_classnotfoundexception(utf *name)
401 {
402         fprintf(stderr, "java.lang.ClassNotFoundException: ");
403         utf_fprint_printable_ascii(stderr, name);
404         fputc('\n', stderr);
405
406         abort();
407 }
408
409 void exceptions_throw_nullpointerexception(void)
410 {
411         fprintf(stderr, "java.lang.NullPointerException\n");
412
413         abort();
414 }
415
416
417 /* finalizer ******************************************************************/
418
419 void finalizer_notify(void)
420 {
421         vm_abort("finalizer_notify");
422 }
423
424 void finalizer_run(void *o, void *p)
425 {
426         vm_abort("finalizer_run");
427 }
428
429
430 /* gc *************************************************************************/
431
432 void gc_reference_register(java_object_t **ref, int32_t reftype)
433 {
434         vm_abort("gc_reference_register");
435 }
436
437 int64_t gc_get_heap_size(void)
438 {
439         return 0;
440 }
441
442 int64_t gc_get_free_bytes(void)
443 {
444         return 0;
445 }
446
447 int64_t gc_get_total_bytes(void)
448 {
449         return 0;
450 }
451
452 int64_t gc_get_max_heap_size(void)
453 {
454         return 0;
455 }
456
457
458 /* heap ***********************************************************************/
459
460 void *heap_alloc_uncollectable(uint32_t bytelength)
461 {
462         return calloc(bytelength, 1);
463 }
464
465 s4 heap_get_hashcode(java_object_t *o)
466 {
467         return 0;
468 }
469
470
471 /* jit ************************************************************************/
472
473 void jit_invalidate_code(methodinfo *m)
474 {
475         vm_abort("jit_invalidate_code");
476 }
477
478
479 /* llni ***********************************************************************/
480
481 void llni_critical_start()
482 {
483 }
484
485 void llni_critical_end()
486 {
487 }
488
489
490 /* localref *******************************************************************/
491
492 java_handle_t *localref_add(java_object_t *o)
493 {
494 #if defined(ENABLE_HANDLES)
495         java_handle_t *h = (java_handle_t*) mem_alloc(sizeof(java_handle_t));
496
497         h->heap_object = o;
498
499         return h;
500 #else
501         return (java_handle_t*) o;
502 #endif
503 }
504
505
506 /* lock ***********************************************************************/
507
508 void lock_init_object_lock(java_object_t *o)
509 {
510 }
511
512 bool lock_monitor_enter(java_handle_t *o)
513 {
514         return true;
515 }
516
517 bool lock_monitor_exit(java_handle_t *o)
518 {
519         return true;
520 }
521
522
523 /* md *************************************************************************/
524
525 void md_param_alloc(methoddesc *md)
526 {
527 }
528
529 void md_param_alloc_native(methoddesc *md)
530 {
531 }
532
533
534 /* memory *********************************************************************/
535
536 void *mem_alloc(int32_t size)
537 {
538         /* real implementation in src/mm/memory.c clears memory */
539
540         return calloc(size, 1);
541 }
542
543 void *mem_realloc(void *src, int32_t len1, int32_t len2)
544 {
545         return realloc(src, len2);
546 }
547
548 void mem_free(void *m, int32_t size)
549 {
550         free(m);
551 }
552
553 void *dumpmemory_get(size_t size)
554 {
555         return malloc(size);
556 }
557
558 int32_t dumpmemory_marker(void)
559 {
560         return 0;
561 }
562
563 void dumpmemory_release(int32_t size)
564 {
565 }
566
567
568 /* package ********************************************************************/
569
570 /* void package_add(java_handle_t *packagename) */
571 void package_add(utf *packagename)
572 {
573         /* Do nothing. */
574 }
575
576
577 /* primitive ******************************************************************/
578
579 classinfo *primitive_arrayclass_get_by_type(int type)
580 {
581         return NULL;
582 }
583
584 classinfo *primitive_class_get_by_type(int type)
585 {
586         abort();
587         return NULL;
588 }
589
590 classinfo *primitive_class_get_by_char(char ch)
591 {
592         abort();
593         return NULL;
594 }
595
596
597 /* properties *****************************************************************/
598
599 void properties_add(char *key, char *value)
600 {
601 }
602
603 char *properties_get(char *key)
604 {
605         return NULL;
606 }
607
608
609 /* resolve ********************************************************************/
610
611 bool resolve_class_from_typedesc(typedesc *d, bool checkaccess, bool link, classinfo **result)
612 {
613         abort();
614
615         return false;
616 }
617
618 /* stupid resolving implementation used by resolve_classref_or_classinfo_eager */
619 /* This function does eager resolving without any access checks.               */
620
621 static classinfo * dummy_resolve_class_from_name(classinfo *referer,
622                                                  utf *classname,
623                                                  bool checkaccess)
624 {
625         classinfo *cls = NULL;
626         char *utf_ptr;
627         int len;
628         
629         assert(referer);
630         assert(classname);
631         
632         /* lookup if this class has already been loaded */
633
634         cls = classcache_lookup(referer->classloader, classname);
635
636         if (!cls) {
637                 /* resolve array types */
638
639                 if (classname->text[0] == '[') {
640                         utf_ptr = classname->text + 1;
641                         len = classname->blength - 1;
642
643                         /* classname is an array type name */
644
645                         switch (*utf_ptr) {
646                                 case 'L':
647                                         utf_ptr++;
648                                         len -= 2;
649                                         /* FALLTHROUGH */
650                                 case '[':
651                                         /* the component type is a reference type */
652                                         /* resolve the component type */
653                                         if ((cls = dummy_resolve_class_from_name(referer,
654                                                                            utf_new(utf_ptr,len),
655                                                                            checkaccess)) == NULL)
656                                                 return NULL; /* exception */
657
658                                         /* create the array class */
659                                         cls = class_array_of(cls,false);
660                                         if (!cls)
661                                                 return NULL; /* exception */
662                         }
663                 }
664
665                 /* load the class */
666                 if (!cls) {
667                         if (!(cls = load_class_from_classloader(classname,
668                                                                                                         referer->classloader)))
669                                 return false; /* exception */
670                 }
671         }
672
673         /* the class is now loaded */
674         assert(cls);
675         assert(cls->state & CLASS_LOADED);
676
677         return cls;
678 }
679
680
681 classinfo * resolve_classref_or_classinfo_eager(classref_or_classinfo cls,
682                                                                                                 bool checkaccess)
683 {
684         classinfo         *c;
685         
686         assert(cls.any);
687
688         if (IS_CLASSREF(cls)) {
689                 /* we must resolve this reference */
690
691                 if ((c = dummy_resolve_class_from_name(cls.ref->referer, cls.ref->name,
692                                                                                    checkaccess)) == NULL)
693                         return NULL;
694         }
695         else {
696                 /* cls has already been resolved */
697                 c = cls.cls;
698         }
699
700         assert(c);
701         assert(c->state & CLASS_LOADED);
702
703         /* succeeded */
704         return c;
705 }
706
707
708 /* stacktrace *****************************************************************/
709
710 java_handle_objectarray_t *stacktrace_getClassContext()
711 {
712         return NULL;
713 }
714
715
716 /* threads ********************************************************************/
717
718 intptr_t threads_get_current_tid(void)
719 {
720         return 0;
721 }
722
723 void threads_cast_stopworld(void)
724 {
725 }
726
727 void threads_cast_startworld(void)
728 {
729 }
730
731
732 /* vm *************************************************************************/
733
734 void vm_printconfig(void)
735 {
736 }
737
738 void vm_abort(const char *text, ...)
739 {
740         va_list ap;
741
742         va_start(ap, text);
743         vfprintf(stderr, text, ap);
744         va_end(ap);
745
746         system_abort();
747 }
748
749 void vm_abort_errno(const char *text, ...)
750 {
751         va_list ap;
752
753         va_start(ap, text);
754         vm_abort_errnum(errno, text, ap);
755         va_end(ap);
756 }
757
758 void vm_abort_errnum(int errnum, const char *text, ...)
759 {
760         va_list ap;
761
762         log_start();
763
764         va_start(ap, text);
765         log_vprint(text, ap);
766         va_end(ap);
767
768         log_print(": %s", system_strerror(errnum));
769         log_finish();
770
771         system_abort();
772 }
773
774 java_handle_t *vm_call_method(methodinfo *m, java_handle_t *o, ...)
775 {
776         return NULL;
777 }
778
779
780 /* XXX */
781
782 void stringtable_update(void)
783 {
784         log_println("stringtable_update: REMOVE ME!");
785 }
786
787 java_object_t *literalstring_new(utf *u)
788 {
789         log_println("literalstring_new: REMOVE ME!");
790
791         return NULL;
792 }
793
794
795 void print_dynamic_super_statistics(void)
796 {
797 }
798
799
800 #if defined(ENABLE_VMLOG)
801 void vmlog_cacao_set_prefix(const char *arg)
802 {
803 }
804
805 void vmlog_cacao_set_stringprefix(const char *arg)
806 {
807 }
808
809 void vmlog_cacao_set_ignoreprefix(const char *arg)
810 {
811 }
812 #endif
813
814
815 /*
816  * These are local overrides for various environment variables in Emacs.
817  * Please do not remove this and leave it at the end of the file, where
818  * Emacs will automagically detect them.
819  * ---------------------------------------------------------------------
820  * Local variables:
821  * mode: c
822  * indent-tabs-mode: t
823  * c-basic-offset: 4
824  * tab-width: 4
825  * End:
826  * vim:noexpandtab:sw=4:ts=4:
827  */