1 /* src/cacaoh/dummy.cpp - 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.hpp"
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/os.hpp"
58 // Below this line are C exports.
61 /* global variables ***********************************************************/
63 bool vm_initializing = true;
64 char *_Jv_bootclasspath;
67 java_handle_t *javastring_new_slash_to_dot(utf *u)
69 vm_abort("javastring_new_slash_to_dot");
75 /* access *********************************************************************/
77 bool access_is_accessible_class(classinfo *referer, classinfo *cls)
82 bool access_is_accessible_member(classinfo *referer, classinfo *declarer,
85 vm_abort("access_is_accessible_member");
91 /* array **********************************************************************/
93 java_handle_t *array_objectarray_element_get(java_handle_objectarray_t *a, int32_t index)
99 log_println("array_objectarray_element_get(a=%p, index=%d): NullPointerException", a, index);
103 size = LLNI_array_size(a);
105 if ((index < 0) || (index > size)) {
106 log_println("array_objectarray_element_get(a=%p, index=%d): ArrayIndexOutOfBoundsException", a, index);
110 value = LLNI_WRAP(LLNI_array_direct(a, index));
115 void array_objectarray_element_set(java_handle_objectarray_t *a, int32_t index, java_handle_t *value)
120 log_println("array_objectarray_element_set(a=%p, index=%d): NullPointerException", a, index);
124 size = LLNI_array_size(a);
126 if ((index < 0) || (index > size)) {
127 log_println("array_objectarray_element_set(a=%p, index=%d): ArrayIndexOutOfBoundsException", a, index);
131 LLNI_array_direct(a, index) = LLNI_UNWRAP(value);
134 int32_t array_length_get(java_handle_t *a)
137 log_println("array_length_get(a=%p): NullPointerException", a);
141 return LLNI_array_size(a);
145 /* asm ************************************************************************/
147 void asm_abstractmethoderror(void)
152 void intrp_asm_abstractmethoderror(void)
158 /* builtin ********************************************************************/
160 java_handle_t *builtin_clone(void *env, java_handle_t *o)
162 vm_abort("builtin_clone: Not implemented.");
166 bool builtin_isanysubclass(classinfo *sub, classinfo *super)
168 vm_abort("builtin_isanysubclass: Not implemented.");
172 bool builtin_instanceof(java_handle_t *o, classinfo *c)
174 vm_abort("builtin_instanceof: Not implemented.");
178 java_handle_t *builtin_new(classinfo *c)
180 vm_abort("builtin_new: Not implemented.");
184 java_handle_objectarray_t *builtin_anewarray(int32_t size, classinfo *componentclass)
186 java_objectarray_t *oa = (java_objectarray_t*) mem_alloc(
187 sizeof(java_array_t) + size * sizeof(java_object_t*));
188 java_handle_objectarray_t *h = (java_handle_objectarray_t*) LLNI_WRAP(
189 (java_object_t*) oa);
192 LLNI_array_size(h) = size;
198 java_handle_bytearray_t *builtin_newarray_byte(int32_t size)
200 java_bytearray_t *ba = (java_bytearray_t*) mem_alloc(
201 sizeof(java_array_t) + size * sizeof(int8_t));
202 java_handle_bytearray_t *h = (java_handle_bytearray_t*) LLNI_WRAP(
203 (java_object_t*) ba);
206 LLNI_array_size(h) = size;
213 /* code ***********************************************************************/
215 void code_free_code_of_method(methodinfo *m)
220 methodinfo *code_get_methodinfo_for_pv(void *pv)
226 /* codegen ********************************************************************/
228 u1 *codegen_generate_stub_compiler(methodinfo *m)
233 codeinfo *codegen_generate_stub_native(methodinfo *m, functionptr f)
238 #if defined(ENABLE_INTRP)
239 u1 *intrp_createcompilerstub(methodinfo *m)
245 void removecompilerstub(u1 *stub)
249 void removenativestub(u1 *stub)
254 /* exceptions *****************************************************************/
256 void exceptions_clear_exception(void)
260 void exceptions_print_current_exception(void)
265 void exceptions_throw_abstractmethoderror(void)
267 fprintf(stderr, "java.lang.AbstractMethodError\n");
272 void exceptions_throw_classcircularityerror(classinfo *c)
274 fprintf(stderr, "java.lang.ClassCircularityError: ");
276 utf_display_printable_ascii(c->name);
282 void exceptions_throw_classformaterror(classinfo *c, const char *message, ...)
286 fprintf(stderr, "java.lang.ClassFormatError: ");
288 utf_display_printable_ascii(c->name);
289 fprintf(stderr, ": ");
291 va_start(ap, message);
292 vfprintf(stderr, message, ap);
300 void exceptions_throw_incompatibleclasschangeerror(classinfo *c, const char *message)
302 fprintf(stderr, "java.lang.IncompatibleClassChangeError: ");
305 utf_fprint_printable_ascii_classname(stderr, c->name);
312 void exceptions_throw_internalerror(const char *message, ...)
316 fprintf(stderr, "java.lang.InternalError: ");
318 va_start(ap, message);
319 vfprintf(stderr, message, ap);
325 void exceptions_throw_linkageerror(const char *message, classinfo *c)
327 fprintf(stderr, "java.lang.LinkageError: %s", message);
330 utf_fprint_printable_ascii_classname(stderr, c->name);
337 void exceptions_throw_noclassdeffounderror(utf *name)
339 fprintf(stderr, "java.lang.NoClassDefFoundError: ");
340 utf_fprint_printable_ascii(stderr, name);
346 void exceptions_throw_noclassdeffounderror_wrong_name(classinfo *c, utf *name)
348 fprintf(stderr, "java.lang.NoClassDefFoundError: ");
349 utf_fprint_printable_ascii(stderr, c->name);
350 fprintf(stderr, " (wrong name: ");
351 utf_fprint_printable_ascii(stderr, name);
352 fprintf(stderr, ")\n");
357 void exceptions_throw_verifyerror(methodinfo *m, const char *message, ...)
359 fprintf(stderr, "java.lang.VerifyError: ");
360 utf_fprint_printable_ascii(stderr, m->name);
361 fprintf(stderr, ": %s", message);
366 void exceptions_throw_nosuchfielderror(classinfo *c, utf *name)
368 fprintf(stderr, "java.lang.NoSuchFieldError: ");
369 utf_fprint_printable_ascii(stderr, c->name);
370 fprintf(stderr, ".");
371 utf_fprint_printable_ascii(stderr, name);
377 void exceptions_throw_nosuchmethoderror(classinfo *c, utf *name, utf *desc)
379 fprintf(stderr, "java.lang.NoSuchMethodError: ");
380 utf_fprint_printable_ascii(stderr, c->name);
381 fprintf(stderr, ".");
382 utf_fprint_printable_ascii(stderr, name);
383 utf_fprint_printable_ascii(stderr, desc);
389 void exceptions_throw_unsupportedclassversionerror(classinfo *c, u4 ma, u4 mi)
391 fprintf(stderr, "java.lang.UnsupportedClassVersionError: " );
392 utf_display_printable_ascii(c->name);
393 fprintf(stderr, " (Unsupported major.minor version %d.%d)\n", ma, mi);
398 void exceptions_throw_classnotfoundexception(utf *name)
400 fprintf(stderr, "java.lang.ClassNotFoundException: ");
401 utf_fprint_printable_ascii(stderr, name);
407 void exceptions_throw_nullpointerexception(void)
409 fprintf(stderr, "java.lang.NullPointerException\n");
415 /* finalizer ******************************************************************/
417 void finalizer_notify(void)
419 vm_abort("finalizer_notify");
422 void finalizer_run(void *o, void *p)
424 vm_abort("finalizer_run");
428 /* gc *************************************************************************/
430 void gc_reference_register(java_object_t **ref, int32_t reftype)
432 vm_abort("gc_reference_register");
435 int64_t gc_get_heap_size(void)
440 int64_t gc_get_free_bytes(void)
445 int64_t gc_get_total_bytes(void)
450 int64_t gc_get_max_heap_size(void)
456 /* heap ***********************************************************************/
458 void *heap_alloc_uncollectable(size_t bytelength)
460 return calloc(bytelength, 1);
463 s4 heap_get_hashcode(java_object_t *o)
469 /* instruction ****************************************************************/
471 methoddesc *instruction_call_site(const instruction *iptr)
477 /* jit ************************************************************************/
479 icmdtable_entry_t icmd_table[256] = {};
481 void jit_invalidate_code(methodinfo *m)
483 vm_abort("jit_invalidate_code");
487 /* llni ***********************************************************************/
489 void llni_critical_start()
493 void llni_critical_end()
498 /* localref *******************************************************************/
500 java_handle_t *localref_add(java_object_t *o)
502 #if defined(ENABLE_HANDLES)
503 java_handle_t *h = (java_handle_t*) mem_alloc(sizeof(java_handle_t));
509 return (java_handle_t*) o;
514 /* lock ***********************************************************************/
516 void lock_init_object_lock(java_object_t *o)
520 bool lock_monitor_enter(java_handle_t *o)
525 bool lock_monitor_exit(java_handle_t *o)
531 /* md *************************************************************************/
533 void md_param_alloc(methoddesc *md)
537 void md_param_alloc_native(methoddesc *md)
542 /* memory *********************************************************************/
544 void *mem_alloc(int32_t size)
546 /* real implementation in src/mm/memory.c clears memory */
548 return calloc(size, 1);
551 void *mem_realloc(void *src, int32_t len1, int32_t len2)
553 return realloc(src, len2);
556 void mem_free(void *m, int32_t size)
561 void *dumpmemory_get(size_t size)
566 int32_t dumpmemory_marker(void)
571 void dumpmemory_release(int32_t size)
576 /* package ********************************************************************/
578 /* void Package_add(java_handle_t *packagename) */
579 void Package_add(utf *packagename)
585 /* primitive ******************************************************************/
587 classinfo *Primitive_get_arrayclass_by_type(int type)
592 classinfo *Primitive_get_class_by_type(int type)
598 classinfo *Primitive_get_class_by_char(char ch)
605 /* properties *****************************************************************/
607 void properties_add(char *key, char *value)
611 char *properties_get(char *key)
617 /* reflect ********************************************************************/
619 java_handle_t *reflect_constructor_new(fieldinfo *f)
621 vm_abort("reflect_constructor_new: Not implemented.");
625 java_handle_t *reflect_field_new(fieldinfo *f)
627 vm_abort("reflect_field_new: Not implemented.");
631 java_handle_t *reflect_method_new(methodinfo *m)
633 vm_abort("reflect_method_new: Not implemented.");
638 /* resolve ********************************************************************/
640 void resolve_handle_pending_exception(bool throwError)
642 vm_abort("resolve_handle_pending_exception: Not implemented.");
645 bool resolve_class_from_typedesc(typedesc *d, bool checkaccess, bool link, classinfo **result)
652 /* stupid resolving implementation used by resolve_classref_or_classinfo_eager */
653 /* This function does eager resolving without any access checks. */
655 static classinfo * dummy_resolve_class_from_name(classinfo *referer,
659 classinfo *cls = NULL;
666 /* lookup if this class has already been loaded */
668 cls = classcache_lookup(referer->classloader, classname);
671 /* resolve array types */
673 if (classname->text[0] == '[') {
674 utf_ptr = classname->text + 1;
675 len = classname->blength - 1;
677 /* classname is an array type name */
685 /* the component type is a reference type */
686 /* resolve the component type */
687 if ((cls = dummy_resolve_class_from_name(referer,
688 utf_new(utf_ptr,len),
689 checkaccess)) == NULL)
690 return NULL; /* exception */
692 /* create the array class */
693 cls = class_array_of(cls,false);
695 return NULL; /* exception */
701 if (!(cls = load_class_from_classloader(classname,
702 referer->classloader)))
703 return false; /* exception */
707 /* the class is now loaded */
709 assert(cls->state & CLASS_LOADED);
715 classinfo * resolve_classref_or_classinfo_eager(classref_or_classinfo cls,
722 if (IS_CLASSREF(cls)) {
723 /* we must resolve this reference */
725 if ((c = dummy_resolve_class_from_name(cls.ref->referer, cls.ref->name,
726 checkaccess)) == NULL)
730 /* cls has already been resolved */
735 assert(c->state & CLASS_LOADED);
742 /* stacktrace *****************************************************************/
744 java_handle_objectarray_t *stacktrace_getClassContext()
750 /* threads ********************************************************************/
752 #if defined(HAVE___THREAD)
753 __thread threadobject *thread_current;
756 pthread_key_t thread_current_key;
759 intptr_t threads_get_current_tid(void)
764 void threads_cast_stopworld(void)
768 void threads_cast_startworld(void)
773 /* vm *************************************************************************/
775 void vm_printconfig(void)
779 void vm_abort(const char *text, ...)
784 vfprintf(stderr, text, ap);
790 void vm_abort_errno(const char *text, ...)
795 vm_abort_errnum(errno, text, ap);
799 void vm_abort_errnum(int errnum, const char *text, ...)
806 log_vprint(text, ap);
809 log_print(": %s", os::strerror(errnum));
815 java_handle_t *vm_call_method(methodinfo *m, java_handle_t *o, ...)
823 void stringtable_update(void)
825 log_println("stringtable_update: REMOVE ME!");
828 java_object_t *literalstring_new(utf *u)
830 log_println("literalstring_new: REMOVE ME!");
836 void print_dynamic_super_statistics(void)
841 #if defined(ENABLE_VMLOG)
842 void vmlog_cacao_set_prefix(const char *arg)
846 void vmlog_cacao_set_stringprefix(const char *arg)
850 void vmlog_cacao_set_ignoreprefix(const char *arg)
856 /* Legacy C interface *********************************************************/
858 bool VM_is_initializing() { return true; }
864 * These are local overrides for various environment variables in Emacs.
865 * Please do not remove this and leave it at the end of the file, where
866 * Emacs will automagically detect them.
867 * ---------------------------------------------------------------------
870 * indent-tabs-mode: t
874 * vim:noexpandtab:sw=4:ts=4: