From a3194739a44a0ac20fdd805e05e7f769786a9c81 Mon Sep 17 00:00:00 2001 From: twisti Date: Fri, 9 Feb 2007 11:08:14 +0000 Subject: [PATCH] * src/vm/exceptions.c (exceptions_throw_unsatisfiedlinkerror) [!ENABLE_JAVASE]: Generate a java.lang.Error. * src/native/vm/cldc1.1/java_lang_Class.c (isInstance): Added. (isAssignableFrom): Likewise. (isInterface): Likewise. (isArray): Likewise. * src/native/vm/cldc1.1/java_lang_Object.c (hashCode): Likewise. (notify): Likewise. (wait): Likewise. * src/native/vm/cldc1.1/java_lang_String.c (hashCode): Smaller implementation changes. (indexOf__II): Likewise. (lastIndexOf__II): Likewise. (indexOf__I): Added. * src/native/vm/cldc1.1/java_lang_Thread.c: Header updated. * src/native/vm/cldc1.1/java_lang_Runtime.c (exitInternal): Fixed signature. (freeMemory): Added. (totalMemory): Likewise. (gc): Likewise. * src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.c: New file. * src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.c: Likewise. * src/native/vm/cldc1.1/Makefile.am (libnativevmcore_la_SOURCES): Added com_sun_cldc_io_ResourceInputStream.c and com_sun_cldc_io_j2me_socket_Protocol.c. * src/native/vm/java_lang_Runtime.c: New file. * src/native/vm/java_lang_Runtime.h: Likewise. * src/native/vm/Makefile.am (libnativevm_la_SOURCES): Added java_lang_Runtime.c and java_lang_Runtime.h. * src/native/vm/java_lang_Class.c: Un-ifdef some functions for CLDC. * src/native/vm/java_lang_Class.h: Likewise. * src/native/vm/gnu/java_lang_VMRuntime.c (native/vm/java_lang_Runtime.h): Added. (exit): Call _Jv_java_lang_Runtime function. (freeMemory): Likewise. (totalMemory): Likewise. (gc): Likewise. * src/native/vm/java_lang_Object.h [ENABLE_JAVASE] (native/include/java_lang_Cloneable.h): Only available for JavaSE configurations. * src/native/include/Makefile.am (JAVAME_CLDC1_1_HEADER_FILES): Added com_sun_cldc_io_ResourceInputStream.h and com_sun_cldc_io_j2me_socket_Protocol.h. * src/native/native.c (dummynativetable) [ENABLE_JAVAME_CLDC1_1]: Added new functions. --- src/native/include/Makefile.am | 4 +- src/native/native.c | 25 ++- src/native/vm/Makefile.am | 2 + src/native/vm/cldc1.1/Makefile.am | 2 + .../com_sun_cldc_io_ResourceInputStream.c | 64 +++++++ .../com_sun_cldc_io_j2me_socket_Protocol.c | 161 ++++++++++++++++++ src/native/vm/cldc1.1/java_lang_Class.c | 44 +++++ src/native/vm/cldc1.1/java_lang_Object.c | 33 ++-- src/native/vm/cldc1.1/java_lang_Runtime.c | 44 ++++- src/native/vm/cldc1.1/java_lang_String.c | 44 ++++- src/native/vm/cldc1.1/java_lang_Thread.c | 12 +- src/native/vm/gnu/java_lang_VMRuntime.c | 20 +-- src/native/vm/java_lang_Class.c | 8 +- src/native/vm/java_lang_Class.h | 22 +-- src/native/vm/java_lang_Object.h | 15 +- src/native/vm/java_lang_Runtime.c | 101 +++++++++++ src/native/vm/java_lang_Runtime.h | 59 +++++++ src/vm/exceptions.c | 6 +- 18 files changed, 594 insertions(+), 72 deletions(-) create mode 100644 src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.c create mode 100644 src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.c create mode 100644 src/native/vm/java_lang_Runtime.c create mode 100644 src/native/vm/java_lang_Runtime.h diff --git a/src/native/include/Makefile.am b/src/native/include/Makefile.am index 4da573e9a..7e75f6516 100644 --- a/src/native/include/Makefile.am +++ b/src/native/include/Makefile.am @@ -22,7 +22,7 @@ ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ## 02110-1301, USA. ## -## $Id: Makefile.am 7246 2007-01-29 18:49:05Z twisti $ +## $Id: Makefile.am 7305 2007-02-09 11:08:14Z twisti $ ## Process this file with automake to produce Makefile.in @@ -70,6 +70,8 @@ JAVASE_HEADER_FILES = \ sun_misc_Unsafe.h JAVAME_CLDC1_1_HEADER_FILES = \ + com_sun_cldc_io_ResourceInputStream.h \ + com_sun_cldc_io_j2me_socket_Protocol.h \ com_sun_cldchi_io_ConsoleOutputStream.h \ java_lang_Math.h \ java_lang_Runtime.h \ diff --git a/src/native/native.c b/src/native/native.c index 179609eab..a71c7383d 100644 --- a/src/native/native.c +++ b/src/native/native.c @@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - $Id: native.c 7246 2007-01-29 18:49:05Z twisti $ + $Id: native.c 7305 2007-02-09 11:08:14Z twisti $ */ @@ -317,10 +317,20 @@ functionptr dummynativetable[] = { #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, @@ -334,7 +344,20 @@ functionptr dummynativetable[] = { (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, diff --git a/src/native/vm/Makefile.am b/src/native/vm/Makefile.am index 4db361ad9..a00b0e564 100644 --- a/src/native/vm/Makefile.am +++ b/src/native/vm/Makefile.am @@ -58,6 +58,8 @@ libnativevm_la_SOURCES = \ java_lang_Class.h \ java_lang_Object.c \ java_lang_Object.h \ + java_lang_Runtime.c \ + java_lang_Runtime.h \ java_lang_Thread.c \ java_lang_Thread.h diff --git a/src/native/vm/cldc1.1/Makefile.am b/src/native/vm/cldc1.1/Makefile.am index 813af5795..aab33bf68 100644 --- a/src/native/vm/cldc1.1/Makefile.am +++ b/src/native/vm/cldc1.1/Makefile.am @@ -34,6 +34,8 @@ noinst_LTLIBRARIES = \ libnativevmcore.la libnativevmcore_la_SOURCES = \ + com_sun_cldc_io_ResourceInputStream.c \ + com_sun_cldc_io_j2me_socket_Protocol.c \ com_sun_cldchi_io_ConsoleOutputStream.c \ java_lang_Class.c \ java_lang_Double.c \ diff --git a/src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.c b/src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.c new file mode 100644 index 000000000..566551be8 --- /dev/null +++ b/src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.c @@ -0,0 +1,64 @@ +/* src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.c + + Copyright (C) 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 + + This file is part of CACAO. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + $Id: java_lang_VMRuntime.c 5900 2006-11-04 17:30:44Z michi $ + +*/ + + +#include "config.h" +#include "vm/types.h" + +#include "native/jni.h" + +#include "native/include/java_lang_Object.h" +#include "native/include/java_lang_String.h" + + +/* + * Class: com/sun/cldc/io/ResourceInputStream + * Method: open + * Signature: (Ljava/lang/String;)Ljava/lang/Object; + */ +JNIEXPORT java_lang_Object* JNICALL Java_com_sun_cldc_io_ResourceInputStream_open(JNIEnv *env, jclass clazz, java_lang_String *name) +{ + exceptions_throw_outofmemoryerror(); + + return NULL; +} + + +/* + * These are local overrides for various environment variables in Emacs. + * Please do not remove this and leave it at the end of the file, where + * Emacs will automagically detect them. + * --------------------------------------------------------------------- + * Local variables: + * mode: c + * indent-tabs-mode: t + * c-basic-offset: 4 + * tab-width: 4 + * End: + * vim:noexpandtab:sw=4:ts=4: + */ diff --git a/src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.c b/src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.c new file mode 100644 index 000000000..b59754194 --- /dev/null +++ b/src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.c @@ -0,0 +1,161 @@ +/* src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.c + + Copyright (C) 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 + + This file is part of CACAO. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + $Id: java_lang_VMRuntime.c 5900 2006-11-04 17:30:44Z michi $ + +*/ + + +#include "config.h" + +#include +#include +#include +#include + +#include "vm/types.h" + +#include "mm/memory.h" + +#include "native/jni.h" + +#include "vm/global.h" + + +/* + * Class: com/sun/cldc/io/j2me/socket/Protocol + * Method: open0 + * Signature: ([BII)I + */ +JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_open0(JNIEnv *env, jclass clazz, java_bytearray *hostname, s4 port, s4 mode) +{ + struct hostent *phostent; + struct sockaddr_in serv_addr; + char *name; + s4 sockfd; + s4 result; + + /* The hostname byte-array is a NULL terminated C-string. */ + + name = (char *) &(hostname->data); + + /* get the host */ + + phostent = gethostbyname(name); + + if (phostent == NULL) + return -1; + + /* fill the sockaddr structure */ + + serv_addr.sin_family = AF_INET; + serv_addr.sin_port = htons(port); + + MCOPY(&serv_addr.sin_addr, phostent->h_addr, u1, phostent->h_length); + + /* create the socket */ + + sockfd = socket(AF_INET, SOCK_STREAM, 0); + + if (sockfd < 0) + return -1; + + /* connect the socket */ + + result = connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)); + + if (result < 0) + return -1; + + return sockfd; +} + + +/* + * Class: com/sun/cldc/io/j2me/socket/Protocol + * Method: readBuf + * Signature: (I[BII)I + */ +JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_readBuf(JNIEnv *env, jclass clazz, s4 handle, java_bytearray *b, s4 off, s4 len) +{ + void *buf; + ssize_t result; + + /* get pointer to the buffer */ + + buf = &(b->data[off]); + + /* receive from the socket */ + + result = recv(handle, buf, len, 0); + + if (result == 0) { + /* the peer has performed an orderly shutdown */ + + return -1; + } + else if (result < 0) { + vm_abort("Java_com_sun_cldc_io_j2me_socket_Protocol_readBuf: recv failed: %s", strerror(errno)); + } + + return result; +} + + +/* + * Class: com/sun/cldc/io/j2me/socket/Protocol + * Method: writeByte + * Signature: (II)I + */ +JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_writeByte(JNIEnv *env, jclass clazz, s4 handle, s4 b) +{ + char byte; + ssize_t result; + + byte = (char) b; + + /* send the given byte to the socket */ + + result = send(handle, &byte, 1, 0); + + if (result < 0) + vm_abort("Java_com_sun_cldc_io_j2me_socket_Protocol_writeByte: send failed: %s", strerror(errno)); + + return result; +} + + +/* + * These are local overrides for various environment variables in Emacs. + * Please do not remove this and leave it at the end of the file, where + * Emacs will automagically detect them. + * --------------------------------------------------------------------- + * Local variables: + * mode: c + * indent-tabs-mode: t + * c-basic-offset: 4 + * tab-width: 4 + * End: + * vim:noexpandtab:sw=4:ts=4: + */ diff --git a/src/native/vm/cldc1.1/java_lang_Class.c b/src/native/vm/cldc1.1/java_lang_Class.c index 492fbd24f..dfb484e5a 100644 --- a/src/native/vm/cldc1.1/java_lang_Class.c +++ b/src/native/vm/cldc1.1/java_lang_Class.c @@ -69,6 +69,50 @@ JNIEXPORT java_lang_Object* JNICALL Java_java_lang_Class_newInstance(JNIEnv *env } +/* + * Class: java/lang/Class + * Method: isInstance + * Signature: (Ljava/lang/Object;)Z + */ +JNIEXPORT s4 JNICALL Java_java_lang_Class_isInstance(JNIEnv *env, java_lang_Class *this, java_lang_Object *obj) +{ + return _Jv_java_lang_Class_isInstance(this, obj); +} + + +/* + * Class: java/lang/Class + * Method: isAssignableFrom + * Signature: (Ljava/lang/Class;)Z + */ +JNIEXPORT s4 JNICALL Java_java_lang_Class_isAssignableFrom(JNIEnv *env, java_lang_Class *this, java_lang_Class *cls) +{ + return _Jv_java_lang_Class_isAssignableFrom(this, cls); +} + + +/* + * Class: java/lang/Class + * Method: isInterface + * Signature: ()Z + */ +JNIEXPORT s4 JNICALL Java_java_lang_Class_isInterface(JNIEnv *env, java_lang_Class *this) +{ + return _Jv_java_lang_Class_isInterface(this); +} + + +/* + * Class: java/lang/Class + * Method: isArray + * Signature: ()Z + */ +JNIEXPORT s4 JNICALL Java_java_lang_Class_isArray(JNIEnv *env, java_lang_Class *this) +{ + return _Jv_java_lang_Class_isArray(this); +} + + /* * Class: java/lang/Class * Method: getName diff --git a/src/native/vm/cldc1.1/java_lang_Object.c b/src/native/vm/cldc1.1/java_lang_Object.c index 61ec9ec40..509c7f454 100644 --- a/src/native/vm/cldc1.1/java_lang_Object.c +++ b/src/native/vm/cldc1.1/java_lang_Object.c @@ -1,6 +1,6 @@ -/* src/native/vm/java_lang_Object.c +/* src/native/vm/cldc1.1/java_lang_Object.c - Copyright (C) 2006 R. Grafl, A. Krall, C. Kruegel, C. Oates, + Copyright (C) 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 @@ -22,11 +22,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - Contact: cacao@cacaojvm.org - - Authors: Phil Tomsich - Christian Thalinger - $Id: java_lang_VMRuntime.c 5900 2006-11-04 17:30:44Z michi $ */ @@ -39,10 +34,13 @@ #include "vm/types.h" #include "native/jni.h" -#include "native/native.h" + +#include "native/include/java_lang_String.h" /* required by java_lang_Class.h */ #include "native/include/java_lang_Class.h" #include "native/include/java_lang_Object.h" +#include "native/vm/java_lang_Object.h" + /* * Class: java/lang/VMObject @@ -65,13 +63,15 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_Object_getClass(JNIEnv *env, j } -#if 0 /* * Class: java/lang/Object * Method: hashCode * Signature: ()I */ -JNIEXPORT s4 JNICALL Java_java_lang_Object_hashCode(JNIEnv *env, struct java_lang_Object* this); +JNIEXPORT s4 JNICALL Java_java_lang_Object_hashCode(JNIEnv *env, java_lang_Object *this) +{ + return (s4) ((ptrint) this); +} /* @@ -79,15 +79,20 @@ JNIEXPORT s4 JNICALL Java_java_lang_Object_hashCode(JNIEnv *env, struct java_lan * Method: notify * Signature: ()V */ -JNIEXPORT void JNICALL Java_java_lang_Object_notify(JNIEnv *env, struct java_lang_Object* this); +JNIEXPORT void JNICALL Java_java_lang_Object_notify(JNIEnv *env, java_lang_Object *this) +{ + _Jv_java_lang_Object_notify(this); +} +#if 0 /* * Class: java/lang/Object * Method: notifyAll * Signature: ()V */ JNIEXPORT void JNICALL Java_java_lang_Object_notifyAll(JNIEnv *env, struct java_lang_Object* this); +#endif /* @@ -95,8 +100,10 @@ JNIEXPORT void JNICALL Java_java_lang_Object_notifyAll(JNIEnv *env, struct java_ * Method: wait * Signature: (J)V */ -JNIEXPORT void JNICALL Java_java_lang_Object_wait(JNIEnv *env, struct java_lang_Object* this, s8 par1); -#endif +JNIEXPORT void JNICALL Java_java_lang_Object_wait(JNIEnv *env, java_lang_Object *this, s8 timeout) +{ + _Jv_java_lang_Object_wait(this, timeout, 0); +} /* diff --git a/src/native/vm/cldc1.1/java_lang_Runtime.c b/src/native/vm/cldc1.1/java_lang_Runtime.c index 74300efd4..11fe32e40 100644 --- a/src/native/vm/cldc1.1/java_lang_Runtime.c +++ b/src/native/vm/cldc1.1/java_lang_Runtime.c @@ -32,9 +32,9 @@ #include "native/jni.h" -#include "vm/vm.h" +#include "native/include/java_lang_Runtime.h" -#include "vmcore/options.h" +#include "native/vm/java_lang_Runtime.h" /* @@ -42,16 +42,42 @@ * Method: exitInternal * Signature: (I)V */ -JNIEXPORT void JNICALL Java_java_lang_Runtime_exitInternal(JNIEnv *env, jclass clazz, s4 status) +JNIEXPORT void JNICALL Java_java_lang_Runtime_exitInternal(JNIEnv *env, java_lang_Runtime *this, s4 status) { -#if 0 - /* TODO: what's the correct behaviour for J2ME? */ + _Jv_java_lang_Runtime_exit(status); +} + + +/* + * Class: java/lang/Runtime + * Method: freeMemory + * Signature: ()J + */ +JNIEXPORT s8 JNICALL Java_java_lang_Runtime_freeMemory(JNIEnv *env, java_lang_Runtime *this) +{ + return _Jv_java_lang_Runtime_freeMemory(); +} - if (finalizeOnExit) - gc_finalize_all(); -#endif - vm_shutdown(status); +/* + * Class: java/lang/Runtime + * Method: totalMemory + * Signature: ()J + */ +JNIEXPORT s8 JNICALL Java_java_lang_Runtime_totalMemory(JNIEnv *env, java_lang_Runtime *this) +{ + return _Jv_java_lang_Runtime_totalMemory(); +} + + +/* + * Class: java/lang/Runtime + * Method: gc + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_java_lang_Runtime_gc(JNIEnv *env, java_lang_Runtime *this) +{ + _Jv_java_lang_Runtime_gc(); } diff --git a/src/native/vm/cldc1.1/java_lang_String.c b/src/native/vm/cldc1.1/java_lang_String.c index 8d5e0eca5..6a34bc684 100644 --- a/src/native/vm/cldc1.1/java_lang_String.c +++ b/src/native/vm/cldc1.1/java_lang_String.c @@ -62,14 +62,42 @@ JNIEXPORT s4 JNICALL Java_java_lang_String_hashCode(JNIEnv *env, java_lang_Strin hash = 0; - for (i = offset; i < (offset + count); i++) { - hash = (31 * hash) + value->data[i]; + for (i = 0; i < count; i++) { + hash = (31 * hash) + value->data[offset + i]; } return hash; } +/* + * Class: java/lang/String + * Method: indexOf + * Signature: (I)I + */ +JNIEXPORT s4 JNICALL Java_java_lang_String_indexOf__I(JNIEnv *env, java_lang_String *this, s4 ch) +{ + java_chararray *value; + s4 offset; + s4 count; + s4 i; + + /* get values from Java object */ + + offset = this->offset; + count = this->count; + value = this->value; + + for (i = 0; i < count; i++) { + if (value->data[offset + i] == ch) { + return i; + } + } + + return -1; +} + + /* * Class: java/lang/String * Method: indexOf @@ -96,9 +124,9 @@ JNIEXPORT s4 JNICALL Java_java_lang_String_indexOf__II(JNIEnv *env, java_lang_St return -1; } - for (i = offset + fromIndex ; i < (offset + count) ; i++) { - if (value->data[i] == ch) { - return i - offset; + for (i = fromIndex ; i < count ; i++) { + if (value->data[offset + i] == ch) { + return i; } } @@ -127,9 +155,9 @@ JNIEXPORT s4 JNICALL Java_java_lang_String_lastIndexOf__II(JNIEnv *env, java_lan start = ((fromIndex >= count) ? count - 1 : fromIndex); - for (i = offset + start; i >= offset; i--) { - if (value->data[i] == ch) { - return i - offset; + for (i = start; i >= 0; i--) { + if (value->data[offset + i] == ch) { + return i; } } diff --git a/src/native/vm/cldc1.1/java_lang_Thread.c b/src/native/vm/cldc1.1/java_lang_Thread.c index 1e8e6e7c2..4e16b41a9 100644 --- a/src/native/vm/cldc1.1/java_lang_Thread.c +++ b/src/native/vm/cldc1.1/java_lang_Thread.c @@ -1,6 +1,6 @@ -/* src/native/vm/java_lang_Thread.c +/* src/native/vm/cldc1.1/java_lang_Thread.c - Copyright (C) 2006 R. Grafl, A. Krall, C. Kruegel, C. Oates, + Copyright (C) 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 @@ -22,11 +22,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - Contact: cacao@cacaojvm.org - - Authors: Phil Tomsich - Christian Thalinger - $Id: java_lang_VMRuntime.c 5900 2006-11-04 17:30:44Z michi $ */ @@ -36,7 +31,9 @@ #include "vm/types.h" #include "native/jni.h" + #include "native/include/java_lang_Thread.h" + #include "native/vm/java_lang_Thread.h" #if defined(ENABLE_THREADS) @@ -44,6 +41,7 @@ #endif #include "toolbox/logging.h" + #include "vm/builtin.h" diff --git a/src/native/vm/gnu/java_lang_VMRuntime.c b/src/native/vm/gnu/java_lang_VMRuntime.c index e5975ec46..74c4a9770 100644 --- a/src/native/vm/gnu/java_lang_VMRuntime.c +++ b/src/native/vm/gnu/java_lang_VMRuntime.c @@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - $Id: java_lang_VMRuntime.c 7246 2007-01-29 18:49:05Z twisti $ + $Id: java_lang_VMRuntime.c 7305 2007-02-09 11:08:14Z twisti $ */ @@ -50,11 +50,14 @@ #include "native/jni.h" #include "native/native.h" + #include "native/include/java_io_File.h" #include "native/include/java_lang_ClassLoader.h" #include "native/include/java_lang_String.h" #include "native/include/java_lang_Process.h" +#include "native/vm/java_lang_Runtime.h" + #include "toolbox/logging.h" #include "vm/builtin.h" @@ -73,10 +76,6 @@ */ -/* should we run all finalizers on exit? */ -static bool finalizeOnExit = false; - - /* * Class: java/lang/VMRuntime * Method: exitInternal @@ -84,10 +83,7 @@ static bool finalizeOnExit = false; */ JNIEXPORT void JNICALL Java_java_lang_VMRuntime_exit(JNIEnv *env, jclass clazz, s4 par1) { - if (finalizeOnExit) - gc_finalize_all(); - - vm_shutdown(par1); + _Jv_java_lang_Runtime_exit(status); } @@ -98,7 +94,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMRuntime_exit(JNIEnv *env, jclass clazz, */ JNIEXPORT s8 JNICALL Java_java_lang_VMRuntime_freeMemory(JNIEnv *env, jclass clazz) { - return gc_get_free_bytes(); + return _Jv_java_lang_Runtime_freeMemory(); } @@ -109,7 +105,7 @@ JNIEXPORT s8 JNICALL Java_java_lang_VMRuntime_freeMemory(JNIEnv *env, jclass cla */ JNIEXPORT s8 JNICALL Java_java_lang_VMRuntime_totalMemory(JNIEnv *env, jclass clazz) { - return gc_get_heap_size(); + return _Jv_java_lang_Runtime_totalMemory(); } @@ -131,7 +127,7 @@ JNIEXPORT s8 JNICALL Java_java_lang_VMRuntime_maxMemory(JNIEnv *env, jclass claz */ JNIEXPORT void JNICALL Java_java_lang_VMRuntime_gc(JNIEnv *env, jclass clazz) { - gc_call(); + _Jv_java_lang_Runtime_gc(); } diff --git a/src/native/vm/java_lang_Class.c b/src/native/vm/java_lang_Class.c index 943404c32..0ef7d8c95 100644 --- a/src/native/vm/java_lang_Class.c +++ b/src/native/vm/java_lang_Class.c @@ -190,8 +190,6 @@ java_lang_Class *_Jv_java_lang_Class_forName(java_lang_String *name) } -#if defined(ENABLE_JAVASE) - /* * Class: java/lang/Class * Method: isInstance @@ -263,6 +261,8 @@ s4 _Jv_java_lang_Class_isInterface(java_lang_Class *klass) } +#if defined(ENABLE_JAVASE) + /* * Class: java/lang/Class * Method: isPrimitive @@ -778,6 +778,8 @@ java_lang_ClassLoader *_Jv_java_lang_Class_getClassLoader(java_lang_Class *klass return (java_lang_ClassLoader *) c->classloader; } +#endif /* defined(ENABLE_JAVASE) */ + /* * Class: java/lang/Class @@ -798,6 +800,8 @@ s4 _Jv_java_lang_Class_isArray(java_lang_Class *klass) } +#if defined(ENABLE_JAVASE) + /* * Class: java/lang/Class * Method: throwException diff --git a/src/native/vm/java_lang_Class.h b/src/native/vm/java_lang_Class.h index d8e0735db..04f36d24e 100644 --- a/src/native/vm/java_lang_Class.h +++ b/src/native/vm/java_lang_Class.h @@ -1,6 +1,6 @@ /* src/native/vm/java_lang_Class.h - java/lang/Class functions - Copyright (C) 2006 R. Grafl, A. Krall, C. Kruegel, C. Oates, + Copyright (C) 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 @@ -22,10 +22,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - Contact: cacao@cacaojvm.org - - Authors: Christian Thalinger - $Id: java_lang_VMClass.c 6131 2006-12-06 22:15:57Z twisti $ */ @@ -57,9 +53,15 @@ java_lang_String *_Jv_java_lang_Class_getName(java_lang_Class *klas #if defined(ENABLE_JAVASE) java_lang_Class *_Jv_java_lang_Class_forName(java_lang_String *name, s4 initialize, java_lang_ClassLoader *loader); +#elif defined(ENABLE_JAVAME_CLDC1_1) +java_lang_Class *_Jv_java_lang_Class_forName(java_lang_String *name); +#endif + s4 _Jv_java_lang_Class_isInstance(java_lang_Class *klass, java_lang_Object *o); s4 _Jv_java_lang_Class_isAssignableFrom(java_lang_Class *klass, java_lang_Class *c); s4 _Jv_java_lang_Class_isInterface(java_lang_Class *klass); + +#if defined(ENABLE_JAVASE) s4 _Jv_java_lang_Class_isPrimitive(java_lang_Class *klass); java_lang_Class *_Jv_java_lang_Class_getSuperclass(java_lang_Class *klass); java_objectarray *_Jv_java_lang_Class_getInterfaces(java_lang_Class *klass); @@ -71,7 +73,11 @@ java_objectarray *_Jv_java_lang_Class_getDeclaredFields(java_lang_C java_objectarray *_Jv_java_lang_Class_getDeclaredMethods(java_lang_Class *klass, s4 publicOnly); java_objectarray *_Jv_java_lang_Class_getDeclaredConstructors(java_lang_Class *klass, s4 publicOnly); java_lang_ClassLoader *_Jv_java_lang_Class_getClassLoader(java_lang_Class *klass); +#endif + s4 _Jv_java_lang_Class_isArray(java_lang_Class *klass); + +#if defined(ENABLE_JAVASE) void _Jv_java_lang_Class_throwException(java_lang_Throwable *t); #if 0 @@ -83,17 +89,13 @@ java_lang_reflect_Constructor *_Jv_java_lang_Class_getEnclosingConstructor(java_ java_lang_reflect_Method *_Jv_java_lang_Class_getEnclosingMethod(java_lang_Class *klass); java_lang_String *_Jv_java_lang_Class_getClassSignature(java_lang_Class* klass); +#endif #if 0 s4 _Jv_java_lang_Class_isAnonymousClass(JNIEnv *env, jclass clazz, struct java_lang_Class* par1); JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isLocalClass(JNIEnv *env, jclass clazz, struct java_lang_Class* par1); JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isMemberClass(JNIEnv *env, jclass clazz, struct java_lang_Class* par1); #endif -#endif /* ENABLE_JAVASE */ - -#if defined(ENABLE_JAVAME_CLDC1_1) -java_lang_Class *_Jv_java_lang_Class_forName(java_lang_String *name); -#endif #endif /* _JV_JAVA_LANG_CLASS_H */ diff --git a/src/native/vm/java_lang_Object.h b/src/native/vm/java_lang_Object.h index 0fdb6d29f..9d7146513 100644 --- a/src/native/vm/java_lang_Object.h +++ b/src/native/vm/java_lang_Object.h @@ -1,6 +1,6 @@ /* src/native/vm/java_lang_Object.h - java/lang/Object functions - Copyright (C) 2006 R. Grafl, A. Krall, C. Kruegel, C. Oates, + Copyright (C) 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 @@ -22,10 +22,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - Contact: cacao@cacaojvm.org - - Authors: Christian Thalinger - $Id: java_lang_VMObject.c 6213 2006-12-18 17:36:06Z twisti $ */ @@ -38,8 +34,13 @@ #include "vm/types.h" #include "native/jni.h" + #include "native/include/java_lang_Class.h" -#include "native/include/java_lang_Cloneable.h" + +#if defined(ENABLE_JAVASE) +# include "native/include/java_lang_Cloneable.h" +#endif + #include "native/include/java_lang_Object.h" @@ -51,9 +52,7 @@ void _Jv_java_lang_Object_notifyAll(java_lang_Object *this); void _Jv_java_lang_Object_wait(java_lang_Object *o, s8 ms, s4 ns); #if defined(ENABLE_JAVASE) - java_lang_Object *_Jv_java_lang_Object_clone(java_lang_Cloneable *this); - #endif #endif /* _JV_JAVA_LANG_OBJECT_H */ diff --git a/src/native/vm/java_lang_Runtime.c b/src/native/vm/java_lang_Runtime.c new file mode 100644 index 000000000..8ef1d3c5e --- /dev/null +++ b/src/native/vm/java_lang_Runtime.c @@ -0,0 +1,101 @@ +/* src/native/vm/java_lang_VMRuntime.c + + 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 + + This file is part of CACAO. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + $Id: java_lang_VMRuntime.c 7246 2007-01-29 18:49:05Z twisti $ + +*/ + + +#include "config.h" +#include "vm/types.h" + +#include "mm/gc-common.h" + +#include "vm/vm.h" + + +/* should we run all finalizers on exit? */ +static bool finalizeOnExit = false; + + +/* + * Class: java/lang/VMRuntime + * Method: exitInternal + * Signature: (I)V + */ +void _Jv_java_lang_Runtime_exit(s4 status) +{ + if (finalizeOnExit) + gc_finalize_all(); + + vm_shutdown(status); +} + + +/* + * Class: java/lang/VMRuntime + * Method: freeMemory + * Signature: ()J + */ +s8 _Jv_java_lang_Runtime_freeMemory(void) +{ + return gc_get_free_bytes(); +} + + +/* + * Class: java/lang/VMRuntime + * Method: totalMemory + * Signature: ()J + */ +s8 _Jv_java_lang_Runtime_totalMemory(void) +{ + return gc_get_heap_size(); +} + + +/* + * Class: java/lang/Runtime + * Method: gc + * Signature: ()V + */ +void _Jv_java_lang_Runtime_gc(void) +{ + gc_call(); +} + + +/* + * These are local overrides for various environment variables in Emacs. + * Please do not remove this and leave it at the end of the file, where + * Emacs will automagically detect them. + * --------------------------------------------------------------------- + * Local variables: + * mode: c + * indent-tabs-mode: t + * c-basic-offset: 4 + * tab-width: 4 + * End: + * vim:noexpandtab:sw=4:ts=4: + */ diff --git a/src/native/vm/java_lang_Runtime.h b/src/native/vm/java_lang_Runtime.h new file mode 100644 index 000000000..64da31e99 --- /dev/null +++ b/src/native/vm/java_lang_Runtime.h @@ -0,0 +1,59 @@ +/* src/native/vm/java_lang_Runtime.h + + Copyright (C) 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 + + This file is part of CACAO. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + $Id: java_lang_VMRuntime.c 7246 2007-01-29 18:49:05Z twisti $ + +*/ + + +#ifndef _JV_JAVA_LANG_RUNTIME_H +#define _JV_JAVA_LANG_RUNTIME_H + +#include "config.h" +#include "vm/types.h" + + +/* function prototypes *******************************************************/ + +void _Jv_java_lang_Runtime_exit(s4 status); +s8 _Jv_java_lang_Runtime_freeMemory(void); +s8 _Jv_java_lang_Runtime_totalMemory(void); +void _Jv_java_lang_Runtime_gc(void); + +#endif /* _JV_JAVA_LANG_RUNTIME_H */ + + +/* + * These are local overrides for various environment variables in Emacs. + * Please do not remove this and leave it at the end of the file, where + * Emacs will automagically detect them. + * --------------------------------------------------------------------- + * Local variables: + * mode: c + * indent-tabs-mode: t + * c-basic-offset: 4 + * tab-width: 4 + * End: + * vim:noexpandtab:sw=4:ts=4: + */ diff --git a/src/vm/exceptions.c b/src/vm/exceptions.c index b04d94dcb..599de01ff 100644 --- a/src/vm/exceptions.c +++ b/src/vm/exceptions.c @@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - $Id: exceptions.c 7270 2007-02-01 12:58:51Z twisti $ + $Id: exceptions.c 7305 2007-02-09 11:08:14Z twisti $ */ @@ -1160,7 +1160,11 @@ void exceptions_throw_outofmemoryerror(void) void exceptions_throw_unsatisfiedlinkerror(utf *name) { +#if defined(ENABLE_JAVASE) exceptions_throw_utf_utf(utf_java_lang_UnsatisfiedLinkError, name); +#else + exceptions_throw_class_utf(class_java_lang_Error, name); +#endif } -- 2.25.1