1 /* src/cacaoh/dummy.c - dummy functions for cacaoh
3 Copyright (C) 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
36 #include "mm/memory.h"
38 #include "native/llni.h"
40 #include "toolbox/logging.h"
42 #include "vm/exceptions.h"
43 #include "vm/global.h"
44 #include "vm/primitive.hpp"
47 #include "vm/jit/code.h"
49 #include "vmcore/class.h"
50 #include "vmcore/classcache.h"
51 #include "vmcore/field.h"
52 #include "vmcore/loader.h"
53 #include "vmcore/method.h"
54 #include "vmcore/utf8.h"
55 #include "vmcore/system.h"
58 /* global variables ***********************************************************/
60 bool vm_initializing = true;
61 char *_Jv_bootclasspath;
64 java_handle_t *javastring_new_slash_to_dot(utf *u)
66 vm_abort("javastring_new_slash_to_dot");
72 /* access *********************************************************************/
74 bool access_is_accessible_class(classinfo *referer, classinfo *cls)
79 bool access_is_accessible_member(classinfo *referer, classinfo *declarer,
82 vm_abort("access_is_accessible_member");
88 /* array **********************************************************************/
90 java_handle_t *array_objectarray_element_get(java_handle_objectarray_t *a, int32_t index)
96 log_println("array_objectarray_element_get(a=%p, index=%d): NullPointerException", a, index);
100 size = LLNI_array_size(a);
102 if ((index < 0) || (index > size)) {
103 log_println("array_objectarray_element_get(a=%p, index=%d): ArrayIndexOutOfBoundsException", a, index);
107 value = LLNI_WRAP(LLNI_array_direct(a, index));
112 void array_objectarray_element_set(java_handle_objectarray_t *a, int32_t index, java_handle_t *value)
117 log_println("array_objectarray_element_set(a=%p, index=%d): NullPointerException", a, index);
121 size = LLNI_array_size(a);
123 if ((index < 0) || (index > size)) {
124 log_println("array_objectarray_element_set(a=%p, index=%d): ArrayIndexOutOfBoundsException", a, index);
128 LLNI_array_direct(a, index) = LLNI_UNWRAP(value);
131 int32_t array_length_get(java_handle_t *a)
134 log_println("array_length_get(a=%p): NullPointerException", a);
138 return LLNI_array_size(a);
142 /* asm ************************************************************************/
144 void asm_abstractmethoderror(void)
149 void intrp_asm_abstractmethoderror(void)
155 /* builtin ********************************************************************/
157 java_handle_t *builtin_clone(void *env, java_handle_t *o)
159 vm_abort("builtin_clone: Not implemented.");
163 bool builtin_isanysubclass(classinfo *sub, classinfo *super)
165 vm_abort("builtin_isanysubclass: Not implemented.");
169 bool builtin_instanceof(java_handle_t *o, classinfo *class)
171 vm_abort("builtin_instanceof: Not implemented.");
175 java_handle_t *builtin_new(classinfo *c)
177 vm_abort("builtin_new: Not implemented.");
181 java_handle_objectarray_t *builtin_anewarray(int32_t size, classinfo *componentclass)
183 java_objectarray_t *oa = (java_objectarray_t*) mem_alloc(
184 sizeof(java_array_t) + size * sizeof(java_object_t*));
185 java_handle_objectarray_t *h = (java_handle_objectarray_t*) LLNI_WRAP(
186 (java_object_t*) oa);
189 LLNI_array_size(h) = size;
195 java_handle_bytearray_t *builtin_newarray_byte(int32_t size)
197 java_bytearray_t *ba = (java_bytearray_t*) mem_alloc(
198 sizeof(java_array_t) + size * sizeof(int8_t));
199 java_handle_bytearray_t *h = (java_handle_bytearray_t*) LLNI_WRAP(
200 (java_object_t*) ba);
203 LLNI_array_size(h) = size;
210 /* code ***********************************************************************/
212 void code_free_code_of_method(methodinfo *m)
217 methodinfo *code_get_methodinfo_for_pv(void *pv)
223 /* codegen ********************************************************************/
225 u1 *codegen_generate_stub_compiler(methodinfo *m)
230 codeinfo *codegen_generate_stub_native(methodinfo *m, functionptr f)
235 #if defined(ENABLE_INTRP)
236 u1 *intrp_createcompilerstub(methodinfo *m)
242 void removecompilerstub(u1 *stub)
246 void removenativestub(u1 *stub)
251 /* exceptions *****************************************************************/
253 void exceptions_clear_exception(void)
257 void exceptions_print_current_exception(void)
262 void exceptions_throw_abstractmethoderror(void)
264 fprintf(stderr, "java.lang.AbstractMethodError\n");
269 void exceptions_throw_classcircularityerror(classinfo *c)
271 fprintf(stderr, "java.lang.ClassCircularityError: ");
273 utf_display_printable_ascii(c->name);
279 void exceptions_throw_classformaterror(classinfo *c, const char *message, ...)
283 fprintf(stderr, "java.lang.ClassFormatError: ");
285 utf_display_printable_ascii(c->name);
286 fprintf(stderr, ": ");
288 va_start(ap, message);
289 vfprintf(stderr, message, ap);
297 void exceptions_throw_incompatibleclasschangeerror(classinfo *c, const char *message)
299 fprintf(stderr, "java.lang.IncompatibleClassChangeError: ");
302 utf_fprint_printable_ascii_classname(stderr, c->name);
309 void exceptions_throw_internalerror(const char *message, ...)
313 fprintf(stderr, "java.lang.InternalError: ");
315 va_start(ap, message);
316 vfprintf(stderr, message, ap);
322 void exceptions_throw_linkageerror(const char *message, classinfo *c)
324 fprintf(stderr, "java.lang.LinkageError: %s", message);
327 utf_fprint_printable_ascii_classname(stderr, c->name);
334 void exceptions_throw_noclassdeffounderror(utf *name)
336 fprintf(stderr, "java.lang.NoClassDefFoundError: ");
337 utf_fprint_printable_ascii(stderr, name);
343 void exceptions_throw_noclassdeffounderror_wrong_name(classinfo *c, utf *name)
345 fprintf(stderr, "java.lang.NoClassDefFoundError: ");
346 utf_fprint_printable_ascii(stderr, c->name);
347 fprintf(stderr, " (wrong name: ");
348 utf_fprint_printable_ascii(stderr, name);
349 fprintf(stderr, ")\n");
354 void exceptions_throw_verifyerror(methodinfo *m, const char *message, ...)
356 fprintf(stderr, "java.lang.VerifyError: ");
357 utf_fprint_printable_ascii(stderr, m->name);
358 fprintf(stderr, ": %s", message);
363 void exceptions_throw_nosuchfielderror(classinfo *c, utf *name)
365 fprintf(stderr, "java.lang.NoSuchFieldError: ");
366 utf_fprint_printable_ascii(stderr, c->name);
367 fprintf(stderr, ".");
368 utf_fprint_printable_ascii(stderr, name);
374 void exceptions_throw_nosuchmethoderror(classinfo *c, utf *name, utf *desc)
376 fprintf(stderr, "java.lang.NoSuchMethodError: ");
377 utf_fprint_printable_ascii(stderr, c->name);
378 fprintf(stderr, ".");
379 utf_fprint_printable_ascii(stderr, name);
380 utf_fprint_printable_ascii(stderr, desc);
386 void exceptions_throw_unsupportedclassversionerror(classinfo *c, u4 ma, u4 mi)
388 fprintf(stderr, "java.lang.UnsupportedClassVersionError: " );
389 utf_display_printable_ascii(c->name);
390 fprintf(stderr, " (Unsupported major.minor version %d.%d)\n", ma, mi);
395 void exceptions_throw_classnotfoundexception(utf *name)
397 fprintf(stderr, "java.lang.ClassNotFoundException: ");
398 utf_fprint_printable_ascii(stderr, name);
404 void exceptions_throw_nullpointerexception(void)
406 fprintf(stderr, "java.lang.NullPointerException\n");
412 /* finalizer ******************************************************************/
414 void finalizer_notify(void)
416 vm_abort("finalizer_notify");
419 void finalizer_run(void *o, void *p)
421 vm_abort("finalizer_run");
425 /* gc *************************************************************************/
427 void gc_reference_register(java_object_t **ref, int32_t reftype)
429 vm_abort("gc_reference_register");
432 int64_t gc_get_heap_size(void)
437 int64_t gc_get_free_bytes(void)
442 int64_t gc_get_total_bytes(void)
447 int64_t gc_get_max_heap_size(void)
453 /* heap ***********************************************************************/
455 void *heap_alloc_uncollectable(size_t bytelength)
457 return calloc(bytelength, 1);
460 s4 heap_get_hashcode(java_object_t *o)
466 /* instruction ****************************************************************/
468 methoddesc *instruction_call_site(const instruction *iptr)
474 /* jit ************************************************************************/
476 icmdtable_entry_t icmd_table[256] = {};
478 void jit_invalidate_code(methodinfo *m)
480 vm_abort("jit_invalidate_code");
484 /* llni ***********************************************************************/
486 void llni_critical_start()
490 void llni_critical_end()
495 /* localref *******************************************************************/
497 java_handle_t *localref_add(java_object_t *o)
499 #if defined(ENABLE_HANDLES)
500 java_handle_t *h = (java_handle_t*) mem_alloc(sizeof(java_handle_t));
506 return (java_handle_t*) o;
511 /* lock ***********************************************************************/
513 void lock_init_object_lock(java_object_t *o)
517 bool lock_monitor_enter(java_handle_t *o)
522 bool lock_monitor_exit(java_handle_t *o)
528 /* md *************************************************************************/
530 void md_param_alloc(methoddesc *md)
534 void md_param_alloc_native(methoddesc *md)
539 /* memory *********************************************************************/
541 void *mem_alloc(int32_t size)
543 /* real implementation in src/mm/memory.c clears memory */
545 return calloc(size, 1);
548 void *mem_realloc(void *src, int32_t len1, int32_t len2)
550 return realloc(src, len2);
553 void mem_free(void *m, int32_t size)
558 void *dumpmemory_get(size_t size)
563 int32_t dumpmemory_marker(void)
568 void dumpmemory_release(int32_t size)
573 /* package ********************************************************************/
575 /* void Package_add(java_handle_t *packagename) */
576 void Package_add(utf *packagename)
582 /* primitive ******************************************************************/
584 classinfo *Primitive_get_arrayclass_by_type(int type)
589 classinfo *Primitive_get_class_by_type(int type)
595 classinfo *Primitive_get_class_by_char(char ch)
602 /* properties *****************************************************************/
604 void properties_add(char *key, char *value)
608 char *properties_get(char *key)
614 /* reflect ********************************************************************/
616 java_handle_t *reflect_constructor_new(fieldinfo *f)
618 vm_abort("reflect_constructor_new: Not implemented.");
622 java_handle_t *reflect_field_new(fieldinfo *f)
624 vm_abort("reflect_field_new: Not implemented.");
628 java_handle_t *reflect_method_new(methodinfo *m)
630 vm_abort("reflect_method_new: Not implemented.");
635 /* resolve ********************************************************************/
637 void resolve_handle_pending_exception(bool throwError)
639 vm_abort("resolve_handle_pending_exception: Not implemented.");
642 bool resolve_class_from_typedesc(typedesc *d, bool checkaccess, bool link, classinfo **result)
649 /* stupid resolving implementation used by resolve_classref_or_classinfo_eager */
650 /* This function does eager resolving without any access checks. */
652 static classinfo * dummy_resolve_class_from_name(classinfo *referer,
656 classinfo *cls = NULL;
663 /* lookup if this class has already been loaded */
665 cls = classcache_lookup(referer->classloader, classname);
668 /* resolve array types */
670 if (classname->text[0] == '[') {
671 utf_ptr = classname->text + 1;
672 len = classname->blength - 1;
674 /* classname is an array type name */
682 /* the component type is a reference type */
683 /* resolve the component type */
684 if ((cls = dummy_resolve_class_from_name(referer,
685 utf_new(utf_ptr,len),
686 checkaccess)) == NULL)
687 return NULL; /* exception */
689 /* create the array class */
690 cls = class_array_of(cls,false);
692 return NULL; /* exception */
698 if (!(cls = load_class_from_classloader(classname,
699 referer->classloader)))
700 return false; /* exception */
704 /* the class is now loaded */
706 assert(cls->state & CLASS_LOADED);
712 classinfo * resolve_classref_or_classinfo_eager(classref_or_classinfo cls,
719 if (IS_CLASSREF(cls)) {
720 /* we must resolve this reference */
722 if ((c = dummy_resolve_class_from_name(cls.ref->referer, cls.ref->name,
723 checkaccess)) == NULL)
727 /* cls has already been resolved */
732 assert(c->state & CLASS_LOADED);
739 /* stacktrace *****************************************************************/
741 java_handle_objectarray_t *stacktrace_getClassContext()
747 /* threads ********************************************************************/
749 #if defined(HAVE___THREAD)
750 __thread threadobject *thread_current;
753 pthread_key_t thread_current_key;
756 intptr_t threads_get_current_tid(void)
761 void threads_cast_stopworld(void)
765 void threads_cast_startworld(void)
770 /* vm *************************************************************************/
772 void vm_printconfig(void)
776 void vm_abort(const char *text, ...)
781 vfprintf(stderr, text, ap);
787 void vm_abort_errno(const char *text, ...)
792 vm_abort_errnum(errno, text, ap);
796 void vm_abort_errnum(int errnum, const char *text, ...)
803 log_vprint(text, ap);
806 log_print(": %s", system_strerror(errnum));
812 java_handle_t *vm_call_method(methodinfo *m, java_handle_t *o, ...)
820 void stringtable_update(void)
822 log_println("stringtable_update: REMOVE ME!");
825 java_object_t *literalstring_new(utf *u)
827 log_println("literalstring_new: REMOVE ME!");
833 void print_dynamic_super_statistics(void)
838 #if defined(ENABLE_VMLOG)
839 void vmlog_cacao_set_prefix(const char *arg)
843 void vmlog_cacao_set_stringprefix(const char *arg)
847 void vmlog_cacao_set_ignoreprefix(const char *arg)
853 /* Legacy C interface *********************************************************/
855 bool VM_is_initializing() { return true; }
859 * These are local overrides for various environment variables in Emacs.
860 * Please do not remove this and leave it at the end of the file, where
861 * Emacs will automagically detect them.
862 * ---------------------------------------------------------------------
865 * indent-tabs-mode: t
869 * vim:noexpandtab:sw=4:ts=4: