/* src/native/native.c - table of native functions
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
J. Wenninger, Institut f. Computersprachen - TU Wien
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- Contact: cacao@cacaojvm.org
-
- Authors: Reinhard Grafl
- Roman Obermaisser
- Andreas Krall
- Christian Thalinger
-
- $Id: native.c 6035 2006-11-21 23:21:18Z twisti $
+ $Id: native.c 7305 2007-02-09 11:08:14Z twisti $
*/
#include "mm/memory.h"
#include "native/jni.h"
#include "native/native.h"
+#include "native/include/java_lang_String.h"
#include "native/include/java_lang_Throwable.h"
#if defined(ENABLE_THREADS)
# include "threads/none/lock.h"
#endif
+#include "toolbox/hashtable.h"
#include "toolbox/logging.h"
+
#include "vm/builtin.h"
#include "vm/exceptions.h"
#include "vm/global.h"
-#include "vm/hashtable.h"
-#include "vm/loader.h"
-#include "vm/options.h"
-#include "vm/resolve.h"
#include "vm/stringlocal.h"
#include "vm/vm.h"
+
#include "vm/jit/asmpart.h"
#include "vm/jit/jit.h"
+#include "vmcore/loader.h"
+#include "vmcore/options.h"
+#include "vmcore/resolve.h"
+
#if defined(ENABLE_JVMTI)
#include "native/jvmti/cacaodbg.h"
#endif
/* include table of native functions ******************************************/
-#include "native/include/java_lang_Cloneable.h"
-#include "native/include/java_util_Properties.h"
+#if defined(ENABLE_JAVASE)
+
#include "native/include/java_io_InputStream.h"
#include "native/include/java_io_PrintStream.h"
+#include "native/include/java_lang_Cloneable.h"
+#include "native/include/java_util_Properties.h"
+
+#include "native/include/java_lang_Object.h"
+
#include "native/include/gnu_classpath_VMStackWalker.h"
#include "native/include/gnu_classpath_VMSystemProperties.h"
#include "native/include/gnu_java_lang_management_VMClassLoadingMXBeanImpl.h"
#include "native/include/gnu_java_lang_management_VMMemoryMXBeanImpl.h"
#include "native/include/gnu_java_lang_management_VMRuntimeMXBeanImpl.h"
-#include "native/include/java_lang_Class.h"
-#include "native/include/java_lang_Object.h"
#include "native/include/java_lang_VMClass.h"
+#include "native/include/java_security_ProtectionDomain.h" /* required by... */
#include "native/include/java_lang_VMClassLoader.h"
#include "native/include/java_lang_VMObject.h"
#include "native/include/java_lang_VMRuntime.h"
#include "native/include/gnu_classpath_jdwp_VMMethod.h"
#endif
+#elif defined(ENABLE_JAVAME_CLDC1_1)
+
+#include "native/include/com_sun_cldchi_io_ConsoleOutputStream.h"
+#include "native/include/java_lang_Class.h"
+#include "native/include/java_lang_Double.h"
+#include "native/include/java_lang_Float.h"
+#include "native/include/java_lang_Math.h"
+#include "native/include/java_lang_Runtime.h"
+#include "native/include/java_lang_System.h"
+#include "native/include/java_lang_Thread.h"
+
+#endif
+
#if defined(WITH_STATIC_CLASSPATH)
/* these are required to prevent compiler warnings */
*******************************************************************************/
functionptr dummynativetable[] = {
+#if defined(ENABLE_JAVASE)
(functionptr) Java_gnu_classpath_VMStackWalker_getClassContext,
(functionptr) Java_gnu_classpath_VMStackWalker_getCallingClass,
(functionptr) Java_gnu_classpath_VMStackWalker_getCallingClassLoader,
(functionptr) Java_gnu_classpath_jdwp_VMMethod_getVariableTable
#endif
+#elif defined(ENABLE_JAVAME_CLDC1_1)
+ (functionptr) Java_com_sun_cldc_io_ResourceInputStream_open,
+
+ (functionptr) Java_com_sun_cldc_io_j2me_socket_Protocol_open0,
+ (functionptr) Java_com_sun_cldc_io_j2me_socket_Protocol_readBuf,
+ (functionptr) Java_com_sun_cldc_io_j2me_socket_Protocol_writeByte,
+
+ (functionptr) Java_com_sun_cldchi_io_ConsoleOutputStream_write,
+
+ (functionptr) Java_java_lang_Class_forName,
+ (functionptr) Java_java_lang_Class_newInstance,
+ (functionptr) Java_java_lang_Class_isInstance,
+ (functionptr) Java_java_lang_Class_isAssignableFrom,
+ (functionptr) Java_java_lang_Class_isInterface,
+ (functionptr) Java_java_lang_Class_isArray,
+ (functionptr) Java_java_lang_Class_getName,
+
+ (functionptr) Java_java_lang_Double_doubleToLongBits,
+
+ (functionptr) Java_java_lang_Float_floatToIntBits,
+
+ (functionptr) Java_java_lang_Math_ceil,
+ (functionptr) Java_java_lang_Math_cos,
+ (functionptr) Java_java_lang_Math_floor,
+ (functionptr) Java_java_lang_Math_sin,
+ (functionptr) Java_java_lang_Math_sqrt,
+ (functionptr) Java_java_lang_Math_tan,
+
+ (functionptr) Java_java_lang_Object_hashCode,
+ (functionptr) Java_java_lang_Object_notify,
+ (functionptr) Java_java_lang_Object_wait,
+
+ (functionptr) Java_java_lang_Runtime_exitInternal,
+ (functionptr) Java_java_lang_Runtime_freeMemory,
+ (functionptr) Java_java_lang_Runtime_totalMemory,
+ (functionptr) Java_java_lang_Runtime_gc,
+
+ (functionptr) Java_java_lang_String_hashCode,
+ (functionptr) Java_java_lang_String_indexOf__I,
+ (functionptr) Java_java_lang_String_indexOf__II,
+ (functionptr) Java_java_lang_String_lastIndexOf__II,
+ (functionptr) Java_java_lang_String_intern,
+
+ (functionptr) Java_java_lang_System_getProperty0,
+
+ (functionptr) Java_java_lang_Thread_currentThread,
+ (functionptr) Java_java_lang_Thread_setPriority0,
+ (functionptr) Java_java_lang_Thread_start0,
+ (functionptr) Java_java_lang_Thread_yield,
+
+ (functionptr) Java_java_lang_Throwable_printStackTrace,
+ (functionptr) Java_java_lang_Throwable_fillInStackTrace
+#endif
};
#endif /* defined(ENABLE_LIBJVM) */
/* initialize libltdl */
if (lt_dlinit())
- vm_abort("lt_dlinit failed: %s\n", lt_dlerror());
+ vm_abort("native_init: lt_dlinit failed: %s\n", lt_dlerror());
/* Get the handle for the main program or for the libjvm.so,
depends on the configuration. */
if (!(mainhandle = lt_dlopenext("libjvm")))
if (!(mainhandle = lt_dlopenext(cacao_libjvm)))
- vm_abort("lt_dlopenext failed: %s\n", lt_dlerror());
+ vm_abort("native_init: lt_dlopenext failed: %s\n", lt_dlerror());
# else
if (!(mainhandle = lt_dlopen(NULL)))
- vm_abort("lt_dlopen failed: %s\n", lt_dlerror());
+ vm_abort("native_init: lt_dlopen failed: %s\n", lt_dlerror());
# endif
/* initialize library hashtable, 10 entries should be enough */
return n->func;
}
-
/* no function was found, throw exception */
*exceptionptr =
if (opt_verbosejni)
printf("failed ]\n");
- *exceptionptr =
- new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
- m->name);
+ exceptions_throw_unsatisfiedlinkerror(m->name);
}
/* release memory */
methodinfo *m;
java_objectheader *o;
- if (!c)
- return *exceptionptr;
+ if (c == NULL)
+ vm_abort("native_new_and_init: c == NULL");
/* create object */
o = builtin_new(c);
- if (!o)
+ if (o == NULL)
return NULL;
/* try to find the initializer */
/* ATTENTION: returning the object here is ok, since the class may
not have an initializer */
- if (!m)
+ if (m == NULL)
return o;
/* call initializer */
}
-java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s)
+java_objectheader *native_new_and_init_string(classinfo *c, java_objectheader *s)
{
- methodinfo *m;
+ methodinfo *m;
java_objectheader *o;
- if (!c)
- return *exceptionptr;
+ if (c == NULL)
+ vm_abort("native_new_and_init_string: c == NULL");
/* create object */
o = builtin_new(c);
- if (!o)
+ if (o == NULL)
return NULL;
/* find initializer */
/* initializer not found */
- if (!m)
+ if (m == NULL)
return NULL;
/* call initializer */
methodinfo *m;
java_objectheader *o;
- if (!c)
- return *exceptionptr;
+ if (c == NULL)
+ vm_abort("native_new_and_init_int: c == NULL");
/* create object */
o = builtin_new(c);
- if (!o)
+ if (o == NULL)
return NULL;
/* find initializer */
/* initializer not found */
- if (!m)
+ if (m == NULL)
return NULL;
/* call initializer */
}
-java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t)
+java_objectheader *native_new_and_init_throwable(classinfo *c, java_objectheader *t)
{
- methodinfo *m;
java_objectheader *o;
+ methodinfo *m;
- if (!c)
- return *exceptionptr;
+ if (c == NULL)
+ vm_abort("native_new_and_init_throwable: c == NULL");
/* create object */
o = builtin_new(c);
- if (!o)
+ if (o == NULL)
return NULL;
/* find initializer */
/* initializer not found */
- if (!m)
+ if (m == NULL)
return NULL;
/* call initializer */
}
-/* native_class_getname ********************************************************
+/* native_class_getdeclaredannotations *****************************************
- Implementation for java.lang.Class.getName()Ljava/lang/String;
+ Implementation for
+ java.lang.Class.getDeclaredAnnotations(Ljava/lang/Class;)[Ljava/lang/annotation/Annotation;
*******************************************************************************/
-java_lang_String *native_class_getname(classinfo *c)
+#if defined(ENABLE_JAVASE)
+java_objectarray *native_class_getdeclaredannotations(classinfo *c)
{
- java_lang_String *s;
- u4 i;
+ java_objectarray *oa;
+ s4 count;
+ s4 i;
+
+ classinfo *class_java_lang_annotation_Annotation;
- s = (java_lang_String *) javastring_new(c->name);
+ /* create Annotation-array */
- if (s == NULL)
+ /* XXX should we cache that class? */
+ if (!(class_java_lang_annotation_Annotation =
+ load_class_bootstrap(utf_new_char("java/lang/annotation/Annotation"))))
return NULL;
- /* return string where '/' is replaced by '.' */
+ count = c->runtimevisibleannotationscount;
+
+ oa = builtin_anewarray(count, class_java_lang_annotation_Annotation);
- for (i = 0; i < s->value->header.size; i++) {
- if (s->value->data[i] == '/')
- s->value->data[i] = '.';
+ if (oa == NULL)
+ return NULL;
+
+ /* fill the annotations */
+
+ for (i = 0; i < count; i++) {
}
- return s;
+ return oa;
}
+#endif
/* native_get_parametertypes ***************************************************