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
35 #include "mm/gc-common.h"
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.h"
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 /* jit ************************************************************************/
468 void jit_invalidate_code(methodinfo *m)
470 vm_abort("jit_invalidate_code");
474 /* llni ***********************************************************************/
476 void llni_critical_start()
480 void llni_critical_end()
485 /* localref *******************************************************************/
487 java_handle_t *localref_add(java_object_t *o)
489 #if defined(ENABLE_HANDLES)
490 java_handle_t *h = (java_handle_t*) mem_alloc(sizeof(java_handle_t));
496 return (java_handle_t*) o;
501 /* lock ***********************************************************************/
503 void lock_init_object_lock(java_object_t *o)
507 bool lock_monitor_enter(java_handle_t *o)
512 bool lock_monitor_exit(java_handle_t *o)
518 /* md *************************************************************************/
520 void md_param_alloc(methoddesc *md)
524 void md_param_alloc_native(methoddesc *md)
529 /* memory *********************************************************************/
531 void *mem_alloc(int32_t size)
533 /* real implementation in src/mm/memory.c clears memory */
535 return calloc(size, 1);
538 void *mem_realloc(void *src, int32_t len1, int32_t len2)
540 return realloc(src, len2);
543 void mem_free(void *m, int32_t size)
548 void *dumpmemory_get(size_t size)
553 int32_t dumpmemory_marker(void)
558 void dumpmemory_release(int32_t size)
563 /* package ********************************************************************/
565 /* void package_add(java_handle_t *packagename) */
566 void package_add(utf *packagename)
572 /* primitive ******************************************************************/
574 classinfo *primitive_arrayclass_get_by_type(int type)
579 classinfo *primitive_class_get_by_type(int type)
585 classinfo *primitive_class_get_by_char(char ch)
592 /* properties *****************************************************************/
594 void properties_add(char *key, char *value)
598 char *properties_get(char *key)
604 /* reflect ********************************************************************/
606 java_handle_t *reflect_constructor_new(fieldinfo *f)
608 vm_abort("reflect_constructor_new: Not implemented.");
612 java_handle_t *reflect_field_new(fieldinfo *f)
614 vm_abort("reflect_field_new: Not implemented.");
618 java_handle_t *reflect_method_new(methodinfo *m)
620 vm_abort("reflect_method_new: Not implemented.");
625 /* resolve ********************************************************************/
627 void resolve_handle_pending_exception(bool throwError)
629 vm_abort("resolve_handle_pending_exception: Not implemented.");
632 bool resolve_class_from_typedesc(typedesc *d, bool checkaccess, bool link, classinfo **result)
639 /* stupid resolving implementation used by resolve_classref_or_classinfo_eager */
640 /* This function does eager resolving without any access checks. */
642 static classinfo * dummy_resolve_class_from_name(classinfo *referer,
646 classinfo *cls = NULL;
653 /* lookup if this class has already been loaded */
655 cls = classcache_lookup(referer->classloader, classname);
658 /* resolve array types */
660 if (classname->text[0] == '[') {
661 utf_ptr = classname->text + 1;
662 len = classname->blength - 1;
664 /* classname is an array type name */
672 /* the component type is a reference type */
673 /* resolve the component type */
674 if ((cls = dummy_resolve_class_from_name(referer,
675 utf_new(utf_ptr,len),
676 checkaccess)) == NULL)
677 return NULL; /* exception */
679 /* create the array class */
680 cls = class_array_of(cls,false);
682 return NULL; /* exception */
688 if (!(cls = load_class_from_classloader(classname,
689 referer->classloader)))
690 return false; /* exception */
694 /* the class is now loaded */
696 assert(cls->state & CLASS_LOADED);
702 classinfo * resolve_classref_or_classinfo_eager(classref_or_classinfo cls,
709 if (IS_CLASSREF(cls)) {
710 /* we must resolve this reference */
712 if ((c = dummy_resolve_class_from_name(cls.ref->referer, cls.ref->name,
713 checkaccess)) == NULL)
717 /* cls has already been resolved */
722 assert(c->state & CLASS_LOADED);
729 /* stacktrace *****************************************************************/
731 java_handle_objectarray_t *stacktrace_getClassContext()
737 /* threads ********************************************************************/
739 intptr_t threads_get_current_tid(void)
744 void threads_cast_stopworld(void)
748 void threads_cast_startworld(void)
753 /* vm *************************************************************************/
755 void vm_printconfig(void)
759 void vm_abort(const char *text, ...)
764 vfprintf(stderr, text, ap);
770 void vm_abort_errno(const char *text, ...)
775 vm_abort_errnum(errno, text, ap);
779 void vm_abort_errnum(int errnum, const char *text, ...)
786 log_vprint(text, ap);
789 log_print(": %s", system_strerror(errnum));
795 java_handle_t *vm_call_method(methodinfo *m, java_handle_t *o, ...)
803 void stringtable_update(void)
805 log_println("stringtable_update: REMOVE ME!");
808 java_object_t *literalstring_new(utf *u)
810 log_println("literalstring_new: REMOVE ME!");
816 void print_dynamic_super_statistics(void)
821 #if defined(ENABLE_VMLOG)
822 void vmlog_cacao_set_prefix(const char *arg)
826 void vmlog_cacao_set_stringprefix(const char *arg)
830 void vmlog_cacao_set_ignoreprefix(const char *arg)
837 * These are local overrides for various environment variables in Emacs.
838 * Please do not remove this and leave it at the end of the file, where
839 * Emacs will automagically detect them.
840 * ---------------------------------------------------------------------
843 * indent-tabs-mode: t
847 * vim:noexpandtab:sw=4:ts=4: