* src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.c,
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Sat, 2 Aug 2008 21:37:01 +0000 (23:37 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Sat, 2 Aug 2008 21:37:01 +0000 (23:37 +0200)
src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.c,
src/native/vm/cldc1.1/com_sun_cldchi_io_ConsoleOutputStream.c,
src/native/vm/cldc1.1/com_sun_cldchi_jvm_JVM.c,
src/native/vm/cldc1.1/java_lang_Class.c,
src/native/vm/cldc1.1/java_lang_Double.c,
src/native/vm/cldc1.1/java_lang_Float.c,
src/native/vm/cldc1.1/java_lang_Math.c,
src/native/vm/cldc1.1/java_lang_Object.c,
src/native/vm/cldc1.1/java_lang_Runtime.c,
src/native/vm/cldc1.1/java_lang_String.c,
src/native/vm/cldc1.1/java_lang_System.c,
src/native/vm/cldc1.1/java_lang_Thread.c,
src/native/vm/cldc1.1/java_lang_Throwable.c: Moved to .cpp.
* src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.cpp,
src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.cpp,
src/native/vm/cldc1.1/com_sun_cldchi_io_ConsoleOutputStream.cpp,
src/native/vm/cldc1.1/com_sun_cldchi_jvm_JVM.cpp,
src/native/vm/cldc1.1/java_lang_Class.cpp,
src/native/vm/cldc1.1/java_lang_Double.cpp,
src/native/vm/cldc1.1/java_lang_Float.cpp,
src/native/vm/cldc1.1/java_lang_Math.cpp,
src/native/vm/cldc1.1/java_lang_Object.cpp,
src/native/vm/cldc1.1/java_lang_Runtime.cpp,
src/native/vm/cldc1.1/java_lang_String.cpp,
src/native/vm/cldc1.1/java_lang_System.cpp,
src/native/vm/cldc1.1/java_lang_Thread.cpp,
src/native/vm/cldc1.1/java_lang_Throwable.cpp: New file.
* src/native/vm/cldc1.1/Makefile.am (libnativevmcore_la_SOURCES):
Updated filenames.

--HG--
rename : src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.c => src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.cpp
rename : src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.c => src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.cpp
rename : src/native/vm/cldc1.1/com_sun_cldchi_io_ConsoleOutputStream.c => src/native/vm/cldc1.1/com_sun_cldchi_io_ConsoleOutputStream.cpp
rename : src/native/vm/cldc1.1/com_sun_cldchi_jvm_JVM.c => src/native/vm/cldc1.1/com_sun_cldchi_jvm_JVM.cpp
rename : src/native/vm/cldc1.1/java_lang_Class.c => src/native/vm/cldc1.1/java_lang_Class.cpp
rename : src/native/vm/cldc1.1/java_lang_Double.c => src/native/vm/cldc1.1/java_lang_Double.cpp
rename : src/native/vm/cldc1.1/java_lang_Float.c => src/native/vm/cldc1.1/java_lang_Float.cpp
rename : src/native/vm/cldc1.1/java_lang_Math.c => src/native/vm/cldc1.1/java_lang_Math.cpp
rename : src/native/vm/cldc1.1/java_lang_Object.c => src/native/vm/cldc1.1/java_lang_Object.cpp
rename : src/native/vm/cldc1.1/java_lang_Runtime.c => src/native/vm/cldc1.1/java_lang_Runtime.cpp
rename : src/native/vm/cldc1.1/java_lang_String.c => src/native/vm/cldc1.1/java_lang_String.cpp
rename : src/native/vm/cldc1.1/java_lang_System.c => src/native/vm/cldc1.1/java_lang_System.cpp
rename : src/native/vm/cldc1.1/java_lang_Thread.c => src/native/vm/cldc1.1/java_lang_Thread.cpp
rename : src/native/vm/cldc1.1/java_lang_Throwable.c => src/native/vm/cldc1.1/java_lang_Throwable.cpp

29 files changed:
src/native/vm/cldc1.1/Makefile.am
src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.c [deleted file]
src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.cpp [new file with mode: 0644]
src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.c [deleted file]
src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.cpp [new file with mode: 0644]
src/native/vm/cldc1.1/com_sun_cldchi_io_ConsoleOutputStream.c [deleted file]
src/native/vm/cldc1.1/com_sun_cldchi_io_ConsoleOutputStream.cpp [new file with mode: 0644]
src/native/vm/cldc1.1/com_sun_cldchi_jvm_JVM.c [deleted file]
src/native/vm/cldc1.1/com_sun_cldchi_jvm_JVM.cpp [new file with mode: 0644]
src/native/vm/cldc1.1/java_lang_Class.c [deleted file]
src/native/vm/cldc1.1/java_lang_Class.cpp [new file with mode: 0644]
src/native/vm/cldc1.1/java_lang_Double.c [deleted file]
src/native/vm/cldc1.1/java_lang_Double.cpp [new file with mode: 0644]
src/native/vm/cldc1.1/java_lang_Float.c [deleted file]
src/native/vm/cldc1.1/java_lang_Float.cpp [new file with mode: 0644]
src/native/vm/cldc1.1/java_lang_Math.c [deleted file]
src/native/vm/cldc1.1/java_lang_Math.cpp [new file with mode: 0644]
src/native/vm/cldc1.1/java_lang_Object.c [deleted file]
src/native/vm/cldc1.1/java_lang_Object.cpp [new file with mode: 0644]
src/native/vm/cldc1.1/java_lang_Runtime.c [deleted file]
src/native/vm/cldc1.1/java_lang_Runtime.cpp [new file with mode: 0644]
src/native/vm/cldc1.1/java_lang_String.c [deleted file]
src/native/vm/cldc1.1/java_lang_String.cpp [new file with mode: 0644]
src/native/vm/cldc1.1/java_lang_System.c [deleted file]
src/native/vm/cldc1.1/java_lang_System.cpp [new file with mode: 0644]
src/native/vm/cldc1.1/java_lang_Thread.c [deleted file]
src/native/vm/cldc1.1/java_lang_Thread.cpp [new file with mode: 0644]
src/native/vm/cldc1.1/java_lang_Throwable.c [deleted file]
src/native/vm/cldc1.1/java_lang_Throwable.cpp [new file with mode: 0644]

index 625d9acec0b804dd5b89bef2910eee810385bdcc..3cc9877172b4150e2d00f3079341279e9e6dc68a 100644 (file)
@@ -1,9 +1,7 @@
 ## src/native/vm/cldc1.1/Makefile.am
 ##
-## 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
+## Copyright (C) 2006, 2007, 2008
+## CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 ##
 ## This file is part of CACAO.
 ##
@@ -31,20 +29,20 @@ 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 \
-       com_sun_cldchi_jvm_JVM.c \
-       java_lang_Class.c \
-       java_lang_Double.c \
-       java_lang_Float.c \
-       java_lang_Math.c \
-       java_lang_Object.c \
-       java_lang_Runtime.c \
-       java_lang_String.c \
-       java_lang_System.c \
-       java_lang_Thread.c \
-       java_lang_Throwable.c
+       com_sun_cldc_io_ResourceInputStream.cpp \
+       com_sun_cldc_io_j2me_socket_Protocol.cpp \
+       com_sun_cldchi_io_ConsoleOutputStream.cpp \
+       com_sun_cldchi_jvm_JVM.cpp \
+       java_lang_Class.cpp \
+       java_lang_Double.cpp \
+       java_lang_Float.cpp \
+       java_lang_Math.cpp \
+       java_lang_Object.cpp \
+       java_lang_Runtime.cpp \
+       java_lang_String.cpp \
+       java_lang_System.cpp \
+       java_lang_Thread.cpp \
+       java_lang_Throwable.cpp
 
 
 ## Local variables:
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
deleted file mode 100644 (file)
index c0370fa..0000000
+++ /dev/null
@@ -1,411 +0,0 @@
-/* src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.c
-
-   Copyright (C) 2007, 2008
-   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
-   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.
-
-*/
-
-
-#include "config.h"
-
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <zlib.h>
-
-#include "mm/memory.h"
-
-#include "native/jni.h"
-#include "native/llni.h"
-#include "native/native.h"
-
-#include "native/include/java_lang_Object.h"
-#include "native/include/java_lang_String.h"
-#include "native/include/com_sun_cldc_io_ResourceInputStream.h"
-#include "native/include/com_sun_cldchi_jvm_FileDescriptor.h"
-
-#include "vm/types.h"
-#include "vm/builtin.h"
-#include "vm/vm.hpp" /* REMOVE ME: temporarily */
-#include "vm/exceptions.hpp"
-#include "vm/string.hpp"
-
-#include "vmcore/zip.h"
-
-#include "threads/lock-common.h"
-
-/* native methods implemented by this file ************************************/
-static JNINativeMethod methods[] = {
-       { "open", "(Ljava/lang/String;)Ljava/lang/Object;", (void *) (ptrint) &Java_com_sun_cldc_io_ResourceInputStream_open },
-       { "bytesRemain", "(Ljava/lang/Object;)I", (void *) (ptrint) &Java_com_sun_cldc_io_ResourceInputStream_bytesRemain },
-       { "readByte", "(Ljava/lang/Object;)I", (void *) (ptrint) &Java_com_sun_cldc_io_ResourceInputStream_readByte },
-       { "readBytes", "(Ljava/lang/Object;[BII)I", (void *) (ptrint) &Java_com_sun_cldc_io_ResourceInputStream_readBytes },
-       { "clone", "(Ljava/lang/Object;)Ljava/lang/Object;", (void *) (ptrint) &Java_com_sun_cldc_io_ResourceInputStream_clone },
-};
-/* _Jv_com_sun_cldc_io_ResourceInputStream_init ********************************
-   Register native functions.
-*******************************************************************************/
-void _Jv_com_sun_cldc_io_ResourceInputStream_init(void)
-{
-       utf *u;
-       u = utf_new_char("com/sun/cldc/io/ResourceInputStream");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
-
-static struct com_sun_cldchi_jvm_FileDescriptor* zip_read_resource(list_classpath_entry *lce, utf *name)
-{
-       hashtable_zipfile_entry *htzfe;
-       lfh                      lfh;
-       u1                      *indata;
-       u1                      *outdata;
-       z_stream                 zs;
-       int                      err;
-       
-       classinfo *ci;
-       com_sun_cldchi_jvm_FileDescriptor *fileDescriptor = NULL;
-
-       /* try to find the class in the current archive */
-
-       htzfe = zip_find(lce, name);
-
-       if (htzfe == NULL)
-               return NULL;
-
-       /* read stuff from local file header */
-
-       lfh.filenamelength   = SUCK_LE_U2(htzfe->data + LFH_FILE_NAME_LENGTH);
-       lfh.extrafieldlength = SUCK_LE_U2(htzfe->data + LFH_EXTRA_FIELD_LENGTH);
-
-       indata = htzfe->data +
-               LFH_HEADER_SIZE +
-               lfh.filenamelength +
-               lfh.extrafieldlength;
-
-       /* allocate buffer for uncompressed data */
-
-       outdata = MNEW(u1, htzfe->uncompressedsize);
-
-       /* how is the file stored? */
-
-       switch (htzfe->compressionmethod) {
-       case Z_DEFLATED:
-               /* fill z_stream structure */
-
-               zs.next_in   = indata;
-               zs.avail_in  = htzfe->compressedsize;
-               zs.next_out  = outdata;
-               zs.avail_out = htzfe->uncompressedsize;
-
-               zs.zalloc = Z_NULL;
-               zs.zfree  = Z_NULL;
-               zs.opaque = Z_NULL;
-
-               /* initialize this inflate run */
-
-               if (inflateInit2(&zs, -MAX_WBITS) != Z_OK)
-                       vm_abort("zip_get: inflateInit2 failed: %s", strerror(errno));
-
-               /* decompress the file into buffer */
-
-               err = inflate(&zs, Z_SYNC_FLUSH);
-
-               if ((err != Z_STREAM_END) && (err != Z_OK))
-                       vm_abort("zip_get: inflate failed: %s", strerror(errno));
-
-               /* finish this inflate run */
-
-               if (inflateEnd(&zs) != Z_OK)
-                       vm_abort("zip_get: inflateEnd failed: %s", strerror(errno));
-               break;
-
-       case 0:
-               /* uncompressed file, just copy the data */
-               MCOPY(outdata, indata, u1, htzfe->compressedsize);
-               break;
-
-       default:
-               vm_abort("zip_get: unknown compression method %d",
-                                htzfe->compressionmethod);
-       }
-               
-       /* Create a file descriptor object */
-       ci = load_class_bootstrap(utf_new_char("com/sun/cldchi/jvm/FileDescriptor"));
-       fileDescriptor = (com_sun_cldchi_jvm_FileDescriptor *) native_new_and_init(ci);
-       LLNI_field_set_val(fileDescriptor, pointer, (int)outdata);
-       LLNI_field_set_val(fileDescriptor, length, htzfe->uncompressedsize);
-       LLNI_field_set_val(fileDescriptor, position, 0);
-       return fileDescriptor;
-       
-}
-
-static struct com_sun_cldchi_jvm_FileDescriptor* file_read_resource(char *path) 
-{
-       int len;
-       struct stat statBuffer;
-       u1 *filep;
-       com_sun_cldchi_jvm_FileDescriptor *fileDescriptor = NULL; 
-       classinfo *ci;
-       int fd;
-       
-       fd = open(path, O_RDONLY);
-       
-       if (fd > 0) {
-               
-               if (fstat(fd, &statBuffer) != -1) {
-                       len = statBuffer.st_size;
-               } else {  
-                       return NULL;
-               }
-               
-               /* Map file into the memory */
-               filep = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0);
-               
-               /* Create a file descriptor object */
-               ci = load_class_bootstrap(utf_new_char("com/sun/cldchi/jvm/FileDescriptor"));
-               fileDescriptor = (com_sun_cldchi_jvm_FileDescriptor *) native_new_and_init(ci);
-               LLNI_field_set_val(fileDescriptor, pointer, (int)filep);
-               LLNI_field_set_val(fileDescriptor, length, len);
-               LLNI_field_set_val(fileDescriptor, position, 0);
-               
-               return fileDescriptor;  
-               
-       } else {
-               return NULL;
-       }
-       
-}
-
-
-/*
- * Class:     com/sun/cldc/io/ResourceInputStream
- * Method:    open
- * Signature: (Ljava/lang/String;)Ljava/lang/Object;
- */
-JNIEXPORT struct java_lang_Object* JNICALL Java_com_sun_cldc_io_ResourceInputStream_open(JNIEnv *env, jclass clazz, java_lang_String *name)
-{
-       
-       list_classpath_entry *lce;
-       char *filename;
-       s4 filenamelen;
-       char *path;
-       utf *uname;
-       com_sun_cldchi_jvm_FileDescriptor* descriptor;
-       
-       /* get the classname as char string (do it here for the warning at
-       the end of the function) */
-
-       uname = javastring_toutf((java_handle_t *)name, false);
-       filenamelen = utf_bytes(uname) + strlen("0");
-       filename = MNEW(char, filenamelen);
-       utf_copy(filename, uname);
-       
-       /* walk through all classpath entries */
-
-       for (lce = list_first(list_classpath_entries); lce != NULL;
-                lce = list_next(list_classpath_entries, lce)) {
-                       
-#if defined(ENABLE_ZLIB)
-               if (lce->type == CLASSPATH_ARCHIVE) {
-
-                       /* enter a monitor on zip/jar archives */
-                       LOCK_MONITOR_ENTER(lce);
-
-                       /* try to get the file in current archive */
-                       descriptor = zip_read_resource(lce, uname);
-
-                       /* leave the monitor */
-                       LOCK_MONITOR_EXIT(lce);
-                       
-                       if (descriptor != NULL) { /* file exists */
-                               break;
-                       }
-
-               } else {
-#endif
-                       
-                       path = MNEW(char, lce->pathlen + filenamelen);
-                       strcpy(path, lce->path);
-                       strcat(path, filename);
-
-                       descriptor = file_read_resource(path);
-                       
-                       MFREE(path, char, lce->pathlen + filenamelen);
-
-                       if (descriptor != NULL) { /* file exists */
-                               break;
-                       }
-                       
-#if defined(ENABLE_ZLIB)
-               }
-#endif 
-                       
-       }
-
-       MFREE(filename, char, filenamelen);
-
-       return (java_lang_Object*) descriptor;
-       
-}
-
-
-/*
- * Class:     com_sun_cldc_io_ResourceInputStream
- * Method:    bytesRemain
- * Signature: (Ljava/lang/Object;)I
- */
-JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_ResourceInputStream_bytesRemain(JNIEnv *env, jclass clazz, struct java_lang_Object* jobj) {
-       
-       com_sun_cldchi_jvm_FileDescriptor *fileDescriptor;
-       int32_t length;
-       int32_t position;
-
-       fileDescriptor = (com_sun_cldchi_jvm_FileDescriptor *) jobj;
-       LLNI_field_get_val(fileDescriptor, position, position);
-       LLNI_field_get_val(fileDescriptor, length, length);
-       
-       return length - position;
-
-}
-
-/*
- * Class:     com_sun_cldc_io_ResourceInputStream
- * Method:    readByte
- * Signature: (Ljava/lang/Object;)I
- */
-JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_ResourceInputStream_readByte(JNIEnv *env, jclass clazz, struct java_lang_Object* jobj) {
-       
-       com_sun_cldchi_jvm_FileDescriptor *fileDescriptor;
-       u1 byte;
-       int32_t length;
-       int32_t position;
-       int64_t filep;
-       
-       fileDescriptor = (com_sun_cldchi_jvm_FileDescriptor *) jobj;
-       LLNI_field_get_val(fileDescriptor, position, position);
-       LLNI_field_get_val(fileDescriptor, length, length);
-       LLNI_field_get_val(fileDescriptor, pointer, filep);
-       
-       if (position < length) {
-               byte = ((u1*)(int)filep)[position];
-               position++;
-       } else {
-               return -1; /* EOF */
-       }
-
-       /* Update access position */
-       LLNI_field_set_val(fileDescriptor, position, position);
-       
-       return (byte & 0xFF);
-
-}
-
-/*
- * Class:     com_sun_cldc_io_ResourceInputStream
- * Method:    readBytes
- * Signature: (Ljava/lang/Object;[BII)I
- */
-JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_ResourceInputStream_readBytes(JNIEnv *env, jclass clazz, struct java_lang_Object* jobj, java_handle_bytearray_t* byteArray, s4 off, s4 len) {
-       
-       com_sun_cldchi_jvm_FileDescriptor *fileDescriptor;
-       s4 readBytes = -1;
-       int32_t fileLength;
-       int32_t position;
-       s4 available;
-       int64_t filep;
-       void *buf;
-
-       /* get pointer to the buffer */
-       buf = &(LLNI_array_direct(byteArray, off));
-       
-       fileDescriptor = (com_sun_cldchi_jvm_FileDescriptor *) jobj;
-       LLNI_field_get_val(fileDescriptor, position, position);
-       LLNI_field_get_val(fileDescriptor, length, fileLength);
-       LLNI_field_get_val(fileDescriptor, pointer, filep);
-       
-       if (position < fileLength) {
-               available = fileLength - position;
-               if (available < len) {
-                       readBytes = available;
-               } else {
-                       readBytes = len;
-               }
-               memcpy(buf, ((u1*)(int)filep) + position, readBytes * sizeof(u1));
-               position += readBytes;
-       } else {
-               return -1; /* EOF */
-       }
-
-       /* Update access position */
-       LLNI_field_set_val(fileDescriptor, position, position);
-       
-       return readBytes;
-}
-
-/*
- * Class:     com_sun_cldc_io_ResourceInputStream
- * Method:    clone
- * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
- */
-JNIEXPORT struct java_lang_Object* JNICALL Java_com_sun_cldc_io_ResourceInputStream_clone(JNIEnv *env, jclass clazz, struct java_lang_Object* jobj) {
-       
-       classinfo *ci;
-       com_sun_cldchi_jvm_FileDescriptor *srcFileDescriptor;
-       com_sun_cldchi_jvm_FileDescriptor *dstFileDescriptor;
-       int32_t srcLength;
-       int32_t srcPosition;
-       int64_t srcFilePointer;
-       
-       srcFileDescriptor = (com_sun_cldchi_jvm_FileDescriptor *) jobj;
-       LLNI_field_get_val(srcFileDescriptor, position, srcPosition);
-       LLNI_field_get_val(srcFileDescriptor, length, srcLength);
-       LLNI_field_get_val(srcFileDescriptor, pointer, srcFilePointer);
-       
-       ci = load_class_bootstrap(utf_new_char("com/sun/cldchi/jvm/FileDescriptor"));
-       dstFileDescriptor = (com_sun_cldchi_jvm_FileDescriptor *) native_new_and_init(ci);
-       LLNI_field_set_val(dstFileDescriptor, position, srcPosition);
-       LLNI_field_set_val(dstFileDescriptor, length, srcLength);
-       LLNI_field_set_val(dstFileDescriptor, pointer, srcFilePointer);
-       
-       return (java_lang_Object*) dstFileDescriptor;
-
-}
-
-
-/*
- * 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_ResourceInputStream.cpp b/src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.cpp
new file mode 100644 (file)
index 0000000..60bd063
--- /dev/null
@@ -0,0 +1,425 @@
+/* src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.cpp
+
+   Copyright (C) 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+*/
+
+
+#include "config.h"
+
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <zlib.h>
+
+#include "mm/memory.h"
+
+#include "native/jni.h"
+#include "native/llni.h"
+#include "native/native.h"
+
+#include "native/include/java_lang_Object.h"
+#include "native/include/java_lang_String.h"
+#include "native/include/com_sun_cldchi_jvm_FileDescriptor.h"
+
+// FIXME
+extern "C" {
+#include "native/include/com_sun_cldc_io_ResourceInputStream.h"
+}
+
+#include "vm/types.h"
+#include "vm/builtin.h"
+#include "vm/vm.hpp" /* REMOVE ME: temporarily */
+#include "vm/exceptions.hpp"
+#include "vm/string.hpp"
+
+#include "vmcore/zip.h"
+
+#include "threads/lock-common.h"
+
+
+/* native methods implemented by this file ************************************/
+static JNINativeMethod methods[] = {
+       { (char*) "open",        (char*) "(Ljava/lang/String;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_com_sun_cldc_io_ResourceInputStream_open        },
+       { (char*) "bytesRemain", (char*) "(Ljava/lang/Object;)I",                  (void*) (uintptr_t) &Java_com_sun_cldc_io_ResourceInputStream_bytesRemain },
+       { (char*) "readByte",    (char*) "(Ljava/lang/Object;)I",                  (void*) (uintptr_t) &Java_com_sun_cldc_io_ResourceInputStream_readByte    },
+       { (char*) "readBytes",   (char*) "(Ljava/lang/Object;[BII)I",              (void*) (uintptr_t) &Java_com_sun_cldc_io_ResourceInputStream_readBytes   },
+       { (char*) "clone",       (char*) "(Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_com_sun_cldc_io_ResourceInputStream_clone       },
+};
+
+/* _Jv_com_sun_cldc_io_ResourceInputStream_init ********************************
+   Register native functions.
+*******************************************************************************/
+// FIXME
+extern "C" {
+void _Jv_com_sun_cldc_io_ResourceInputStream_init(void)
+{
+       utf *u;
+       u = utf_new_char("com/sun/cldc/io/ResourceInputStream");
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
+}
+
+static struct com_sun_cldchi_jvm_FileDescriptor* zip_read_resource(list_classpath_entry *lce, utf *name)
+{
+       hashtable_zipfile_entry *htzfe;
+       lfh                      lfh;
+       u1                      *indata;
+       u1                      *outdata;
+       z_stream                 zs;
+       int                      err;
+       
+       classinfo *ci;
+       com_sun_cldchi_jvm_FileDescriptor *fileDescriptor = NULL;
+
+       /* try to find the class in the current archive */
+
+       htzfe = zip_find(lce, name);
+
+       if (htzfe == NULL)
+               return NULL;
+
+       /* read stuff from local file header */
+
+       lfh.filenamelength   = SUCK_LE_U2(htzfe->data + LFH_FILE_NAME_LENGTH);
+       lfh.extrafieldlength = SUCK_LE_U2(htzfe->data + LFH_EXTRA_FIELD_LENGTH);
+
+       indata = htzfe->data +
+               LFH_HEADER_SIZE +
+               lfh.filenamelength +
+               lfh.extrafieldlength;
+
+       /* allocate buffer for uncompressed data */
+
+       outdata = MNEW(u1, htzfe->uncompressedsize);
+
+       /* how is the file stored? */
+
+       switch (htzfe->compressionmethod) {
+       case Z_DEFLATED:
+               /* fill z_stream structure */
+
+               zs.next_in   = indata;
+               zs.avail_in  = htzfe->compressedsize;
+               zs.next_out  = outdata;
+               zs.avail_out = htzfe->uncompressedsize;
+
+               zs.zalloc = Z_NULL;
+               zs.zfree  = Z_NULL;
+               zs.opaque = Z_NULL;
+
+               /* initialize this inflate run */
+
+               if (inflateInit2(&zs, -MAX_WBITS) != Z_OK)
+                       vm_abort("zip_get: inflateInit2 failed: %s", strerror(errno));
+
+               /* decompress the file into buffer */
+
+               err = inflate(&zs, Z_SYNC_FLUSH);
+
+               if ((err != Z_STREAM_END) && (err != Z_OK))
+                       vm_abort("zip_get: inflate failed: %s", strerror(errno));
+
+               /* finish this inflate run */
+
+               if (inflateEnd(&zs) != Z_OK)
+                       vm_abort("zip_get: inflateEnd failed: %s", strerror(errno));
+               break;
+
+       case 0:
+               /* uncompressed file, just copy the data */
+               MCOPY(outdata, indata, u1, htzfe->compressedsize);
+               break;
+
+       default:
+               vm_abort("zip_get: unknown compression method %d",
+                                htzfe->compressionmethod);
+       }
+               
+       /* Create a file descriptor object */
+       ci = load_class_bootstrap(utf_new_char("com/sun/cldchi/jvm/FileDescriptor"));
+       fileDescriptor = (com_sun_cldchi_jvm_FileDescriptor *) native_new_and_init(ci);
+       LLNI_field_set_val(fileDescriptor, pointer, (int)outdata);
+       LLNI_field_set_val(fileDescriptor, length, htzfe->uncompressedsize);
+       LLNI_field_set_val(fileDescriptor, position, 0);
+       return fileDescriptor;
+       
+}
+
+static struct com_sun_cldchi_jvm_FileDescriptor* file_read_resource(char *path) 
+{
+       int len;
+       struct stat statBuffer;
+       u1 *filep;
+       com_sun_cldchi_jvm_FileDescriptor *fileDescriptor = NULL; 
+       classinfo *ci;
+       int fd;
+       
+       fd = open(path, O_RDONLY);
+       
+       if (fd > 0) {
+               
+               if (fstat(fd, &statBuffer) != -1) {
+                       len = statBuffer.st_size;
+               } else {  
+                       return NULL;
+               }
+               
+               /* Map file into the memory */
+               filep = (u1*) mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0);
+               
+               /* Create a file descriptor object */
+               ci = load_class_bootstrap(utf_new_char("com/sun/cldchi/jvm/FileDescriptor"));
+               fileDescriptor = (com_sun_cldchi_jvm_FileDescriptor *) native_new_and_init(ci);
+               LLNI_field_set_val(fileDescriptor, pointer, (int)filep);
+               LLNI_field_set_val(fileDescriptor, length, len);
+               LLNI_field_set_val(fileDescriptor, position, 0);
+               
+               return fileDescriptor;  
+               
+       } else {
+               return NULL;
+       }
+       
+}
+
+
+// Native functions are exported as C functions.
+extern "C" {
+
+/*
+ * Class:     com/sun/cldc/io/ResourceInputStream
+ * Method:    open
+ * Signature: (Ljava/lang/String;)Ljava/lang/Object;
+ */
+JNIEXPORT struct java_lang_Object* JNICALL Java_com_sun_cldc_io_ResourceInputStream_open(JNIEnv *env, jclass clazz, java_lang_String *name)
+{
+       
+       list_classpath_entry *lce;
+       char *filename;
+       s4 filenamelen;
+       char *path;
+       utf *uname;
+       com_sun_cldchi_jvm_FileDescriptor* descriptor;
+       
+       /* get the classname as char string (do it here for the warning at
+       the end of the function) */
+
+       uname = javastring_toutf((java_handle_t *)name, false);
+       filenamelen = utf_bytes(uname) + strlen("0");
+       filename = MNEW(char, filenamelen);
+       utf_copy(filename, uname);
+       
+       /* walk through all classpath entries */
+
+       for (lce = (list_classpath_entry*) list_first(list_classpath_entries); lce != NULL;
+                lce = (list_classpath_entry*) list_next(list_classpath_entries, lce)) {
+                       
+#if defined(ENABLE_ZLIB)
+               if (lce->type == CLASSPATH_ARCHIVE) {
+
+                       /* enter a monitor on zip/jar archives */
+                       LOCK_MONITOR_ENTER(lce);
+
+                       /* try to get the file in current archive */
+                       descriptor = zip_read_resource(lce, uname);
+
+                       /* leave the monitor */
+                       LOCK_MONITOR_EXIT(lce);
+                       
+                       if (descriptor != NULL) { /* file exists */
+                               break;
+                       }
+
+               } else {
+#endif
+                       
+                       path = MNEW(char, lce->pathlen + filenamelen);
+                       strcpy(path, lce->path);
+                       strcat(path, filename);
+
+                       descriptor = file_read_resource(path);
+                       
+                       MFREE(path, char, lce->pathlen + filenamelen);
+
+                       if (descriptor != NULL) { /* file exists */
+                               break;
+                       }
+                       
+#if defined(ENABLE_ZLIB)
+               }
+#endif 
+                       
+       }
+
+       MFREE(filename, char, filenamelen);
+
+       return (java_lang_Object*) descriptor;
+       
+}
+
+
+/*
+ * Class:     com_sun_cldc_io_ResourceInputStream
+ * Method:    bytesRemain
+ * Signature: (Ljava/lang/Object;)I
+ */
+JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_ResourceInputStream_bytesRemain(JNIEnv *env, jclass clazz, struct java_lang_Object* jobj) {
+       
+       com_sun_cldchi_jvm_FileDescriptor *fileDescriptor;
+       int32_t length;
+       int32_t position;
+
+       fileDescriptor = (com_sun_cldchi_jvm_FileDescriptor *) jobj;
+       LLNI_field_get_val(fileDescriptor, position, position);
+       LLNI_field_get_val(fileDescriptor, length, length);
+       
+       return length - position;
+
+}
+
+/*
+ * Class:     com_sun_cldc_io_ResourceInputStream
+ * Method:    readByte
+ * Signature: (Ljava/lang/Object;)I
+ */
+JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_ResourceInputStream_readByte(JNIEnv *env, jclass clazz, struct java_lang_Object* jobj) {
+       
+       com_sun_cldchi_jvm_FileDescriptor *fileDescriptor;
+       u1 byte;
+       int32_t length;
+       int32_t position;
+       int64_t filep;
+       
+       fileDescriptor = (com_sun_cldchi_jvm_FileDescriptor *) jobj;
+       LLNI_field_get_val(fileDescriptor, position, position);
+       LLNI_field_get_val(fileDescriptor, length, length);
+       LLNI_field_get_val(fileDescriptor, pointer, filep);
+       
+       if (position < length) {
+               byte = ((u1*)(int)filep)[position];
+               position++;
+       } else {
+               return -1; /* EOF */
+       }
+
+       /* Update access position */
+       LLNI_field_set_val(fileDescriptor, position, position);
+       
+       return (byte & 0xFF);
+
+}
+
+/*
+ * Class:     com_sun_cldc_io_ResourceInputStream
+ * Method:    readBytes
+ * Signature: (Ljava/lang/Object;[BII)I
+ */
+JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_ResourceInputStream_readBytes(JNIEnv *env, jclass clazz, struct java_lang_Object* jobj, java_handle_bytearray_t* byteArray, s4 off, s4 len) {
+       
+       com_sun_cldchi_jvm_FileDescriptor *fileDescriptor;
+       s4 readBytes = -1;
+       int32_t fileLength;
+       int32_t position;
+       s4 available;
+       int64_t filep;
+       void *buf;
+
+       /* get pointer to the buffer */
+       buf = &(LLNI_array_direct(byteArray, off));
+       
+       fileDescriptor = (com_sun_cldchi_jvm_FileDescriptor *) jobj;
+       LLNI_field_get_val(fileDescriptor, position, position);
+       LLNI_field_get_val(fileDescriptor, length, fileLength);
+       LLNI_field_get_val(fileDescriptor, pointer, filep);
+       
+       if (position < fileLength) {
+               available = fileLength - position;
+               if (available < len) {
+                       readBytes = available;
+               } else {
+                       readBytes = len;
+               }
+               memcpy(buf, ((u1*)(int)filep) + position, readBytes * sizeof(u1));
+               position += readBytes;
+       } else {
+               return -1; /* EOF */
+       }
+
+       /* Update access position */
+       LLNI_field_set_val(fileDescriptor, position, position);
+       
+       return readBytes;
+}
+
+/*
+ * Class:     com_sun_cldc_io_ResourceInputStream
+ * Method:    clone
+ * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
+ */
+JNIEXPORT struct java_lang_Object* JNICALL Java_com_sun_cldc_io_ResourceInputStream_clone(JNIEnv *env, jclass clazz, struct java_lang_Object* jobj) {
+       
+       classinfo *ci;
+       com_sun_cldchi_jvm_FileDescriptor *srcFileDescriptor;
+       com_sun_cldchi_jvm_FileDescriptor *dstFileDescriptor;
+       int32_t srcLength;
+       int32_t srcPosition;
+       int64_t srcFilePointer;
+       
+       srcFileDescriptor = (com_sun_cldchi_jvm_FileDescriptor *) jobj;
+       LLNI_field_get_val(srcFileDescriptor, position, srcPosition);
+       LLNI_field_get_val(srcFileDescriptor, length, srcLength);
+       LLNI_field_get_val(srcFileDescriptor, pointer, srcFilePointer);
+       
+       ci = load_class_bootstrap(utf_new_char("com/sun/cldchi/jvm/FileDescriptor"));
+       dstFileDescriptor = (com_sun_cldchi_jvm_FileDescriptor *) native_new_and_init(ci);
+       LLNI_field_set_val(dstFileDescriptor, position, srcPosition);
+       LLNI_field_set_val(dstFileDescriptor, length, srcLength);
+       LLNI_field_set_val(dstFileDescriptor, pointer, srcFilePointer);
+       
+       return (java_lang_Object*) dstFileDescriptor;
+
+}
+
+} // extern "C"
+
+
+/*
+ * 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
deleted file mode 100644 (file)
index 81d7bda..0000000
+++ /dev/null
@@ -1,282 +0,0 @@
-/* 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.
-
-*/
-
-
-#include "config.h"
-
-#include <errno.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include "vm/types.h"
-
-#include "mm/memory.h"
-
-#include "native/jni.h"
-#include "native/llni.h"
-#include "native/native.h"
-
-#include "native/include/com_sun_cldc_io_j2me_socket_Protocol.h"
-
-#include "vm/global.h"
-#include "vm/vm.hpp" /* REMOVE ME: temporarily */
-
-
-/* native methods implemented by this file ************************************/
-static JNINativeMethod methods[] = {
-       { "open0",      "([BII)I",  (void *) (ptrint) &Java_com_sun_cldc_io_j2me_socket_Protocol_open0      },
-       { "readBuf",    "(I[BII)I", (void *) (ptrint) &Java_com_sun_cldc_io_j2me_socket_Protocol_readBuf    },
-       { "readByte",   "(I)I",     (void *) (ptrint) &Java_com_sun_cldc_io_j2me_socket_Protocol_readByte   },
-       { "writeBuf",   "(I[BII)I", (void *) (ptrint) &Java_com_sun_cldc_io_j2me_socket_Protocol_writeBuf   },
-       { "writeByte",  "(II)I",    (void *) (ptrint) &Java_com_sun_cldc_io_j2me_socket_Protocol_writeByte  },
-       { "available0", "(I)I",     (void *) (ptrint) &Java_com_sun_cldc_io_j2me_socket_Protocol_available0 },
-       { "close0",     "(I)V",     (void *) (ptrint) &Java_com_sun_cldc_io_j2me_socket_Protocol_close0     },
-};
-
-/* _Jv_com_sun_cldc_io_j2me_socket_Protocol_init *******************************
-   Register native functions.
-*******************************************************************************/
-void _Jv_com_sun_cldc_io_j2me_socket_Protocol_init(void)
-{
-       utf *u;
-       u = utf_new_char("com/sun/cldc/io/j2me/socket/Protocol");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
-
-
-/*
- * 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_handle_bytearray_t *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 *) &(LLNI_array_data(hostname));
-
-       /* 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_handle_bytearray_t *b, s4 off, s4 len)
-{
-       void    *buf;
-       ssize_t  result;
-
-       /* get pointer to the buffer */
-
-       buf = &(LLNI_array_direct(b, 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:    readByte
- * Signature: (I)I
- */
-JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_readByte(JNIEnv *env, jclass clazz, s4 handle) {
-       
-       char    byte;
-       ssize_t result;
-       
-       /* receive from the socket */
-
-       result = recv(handle, &byte, 1, 0);
-
-       if (result == 0) {
-               /* the peer has performed an orderly shutdown */
-
-               return -1;
-       }
-       else if (result < 0) {
-               /* should throw an IOException */
-
-               vm_abort("Java_com_sun_cldc_io_j2me_socket_Protocol_readByte: recv failed: %s", strerror(errno));
-       }
-
-       return byte;
-}
-
-
-/*
- * Class:     com/sun/cldc/io/j2me/socket/Protocol
- * Method:    writeBuf
- * Signature: (I[BII)I
- */
-JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_writeBuf(JNIEnv *env, jclass clazz, s4 handle, java_handle_bytearray_t * b, s4 off, s4 len) {
-
-       void    *buf;
-       ssize_t  result;
-
-       /* get pointer to the buffer */
-
-       buf = &(LLNI_array_direct(b, off));
-       
-       /* send the given byte to the socket */
-
-       result = send(handle, buf, len, 0);
-
-       if (result < 0)
-               /* should throw an IOException */
-
-               vm_abort("Java_com_sun_cldc_io_j2me_socket_Protocol_writeBuf: send 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;
-}
-
-
-/*
- * Class:     com/sun/cldc/io/j2me/socket/Protocol
- * Method:    available0
- * Signature: (I)I
- */
-JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_available0(JNIEnv *env, jclass clazz, s4 handle)
-{
-       /* NOTE: Sun doesn't have an implementation too */
-
-       return 0;
-}
-
-
-/*
- * Class:     com/sun/cldc/io/j2me/socket/Protocol
- * Method:    close0
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_close0(JNIEnv *env, jclass clazz, s4 handle)
-{
-       int result;
-
-       /* close the file descriptor */
-
-       result = close(handle);
-
-       if (result < 0)
-               vm_abort("Java_com_sun_cldc_io_j2me_socket_Protocol_close0: close failed: %s", strerror(errno));
-}
-
-
-/*
- * 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.cpp b/src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.cpp
new file mode 100644 (file)
index 0000000..6c24bac
--- /dev/null
@@ -0,0 +1,292 @@
+/* src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.cpp
+
+   Copyright (C) 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+#include <errno.h>
+#include <netdb.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include "vm/types.h"
+
+#include "mm/memory.h"
+
+#include "native/jni.h"
+#include "native/llni.h"
+#include "native/native.h"
+
+// FIXME
+extern "C" {
+#include "native/include/com_sun_cldc_io_j2me_socket_Protocol.h"
+}
+
+#include "vm/global.h"
+#include "vm/vm.hpp" /* REMOVE ME: temporarily */
+
+
+/* native methods implemented by this file ************************************/
+static JNINativeMethod methods[] = {
+       { (char*) "open0",      (char*) "([BII)I",  (void*) (uintptr_t) &Java_com_sun_cldc_io_j2me_socket_Protocol_open0      },
+       { (char*) "readBuf",    (char*) "(I[BII)I", (void*) (uintptr_t) &Java_com_sun_cldc_io_j2me_socket_Protocol_readBuf    },
+       { (char*) "readByte",   (char*) "(I)I",     (void*) (uintptr_t) &Java_com_sun_cldc_io_j2me_socket_Protocol_readByte   },
+       { (char*) "writeBuf",   (char*) "(I[BII)I", (void*) (uintptr_t) &Java_com_sun_cldc_io_j2me_socket_Protocol_writeBuf   },
+       { (char*) "writeByte",  (char*) "(II)I",    (void*) (uintptr_t) &Java_com_sun_cldc_io_j2me_socket_Protocol_writeByte  },
+       { (char*) "available0", (char*) "(I)I",     (void*) (uintptr_t) &Java_com_sun_cldc_io_j2me_socket_Protocol_available0 },
+       { (char*) "close0",     (char*) "(I)V",     (void*) (uintptr_t) &Java_com_sun_cldc_io_j2me_socket_Protocol_close0     },
+};
+
+/* _Jv_com_sun_cldc_io_j2me_socket_Protocol_init *******************************
+   Register native functions.
+*******************************************************************************/
+// FIXME
+extern "C" {
+void _Jv_com_sun_cldc_io_j2me_socket_Protocol_init(void)
+{
+       utf *u;
+       u = utf_new_char("com/sun/cldc/io/j2me/socket/Protocol");
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
+}
+
+
+// Native functions are exported as C functions.
+extern "C" {
+
+/*
+ * 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_handle_bytearray_t *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 *) &(LLNI_array_data(hostname));
+
+       /* 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_handle_bytearray_t *b, s4 off, s4 len)
+{
+       void    *buf;
+       ssize_t  result;
+
+       /* get pointer to the buffer */
+
+       buf = &(LLNI_array_direct(b, 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_errno("Java_com_sun_cldc_io_j2me_socket_Protocol_readBuf: recv failed");
+       }
+
+       return result;
+}
+
+
+/*
+ * Class:     com/sun/cldc/io/j2me/socket/Protocol
+ * Method:    readByte
+ * Signature: (I)I
+ */
+JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_readByte(JNIEnv *env, jclass clazz, s4 handle) {
+       
+       char    byte;
+       ssize_t result;
+       
+       /* receive from the socket */
+
+       result = recv(handle, &byte, 1, 0);
+
+       if (result == 0) {
+               /* the peer has performed an orderly shutdown */
+
+               return -1;
+       }
+       else if (result < 0) {
+               /* should throw an IOException */
+
+               vm_abort_errno("Java_com_sun_cldc_io_j2me_socket_Protocol_readByte: recv failed");
+       }
+
+       return byte;
+}
+
+
+/*
+ * Class:     com/sun/cldc/io/j2me/socket/Protocol
+ * Method:    writeBuf
+ * Signature: (I[BII)I
+ */
+JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_writeBuf(JNIEnv *env, jclass clazz, s4 handle, java_handle_bytearray_t * b, s4 off, s4 len) {
+
+       void    *buf;
+       ssize_t  result;
+
+       /* get pointer to the buffer */
+
+       buf = &(LLNI_array_direct(b, off));
+       
+       /* send the given byte to the socket */
+
+       result = send(handle, buf, len, 0);
+
+       if (result < 0)
+               /* should throw an IOException */
+
+               vm_abort_errno("Java_com_sun_cldc_io_j2me_socket_Protocol_writeBuf: send failed");
+
+       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_errno("Java_com_sun_cldc_io_j2me_socket_Protocol_writeByte: send failed");
+
+       return result;
+}
+
+
+/*
+ * Class:     com/sun/cldc/io/j2me/socket/Protocol
+ * Method:    available0
+ * Signature: (I)I
+ */
+JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_available0(JNIEnv *env, jclass clazz, s4 handle)
+{
+       /* NOTE: Sun doesn't have an implementation too */
+
+       return 0;
+}
+
+
+/*
+ * Class:     com/sun/cldc/io/j2me/socket/Protocol
+ * Method:    close0
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_close0(JNIEnv *env, jclass clazz, s4 handle)
+{
+       int result;
+
+       /* close the file descriptor */
+
+       result = close(handle);
+
+       if (result < 0)
+               vm_abort_errno("Java_com_sun_cldc_io_j2me_socket_Protocol_close0: close failed");
+}
+
+} // extern "C"
+
+
+/*
+ * 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_cldchi_io_ConsoleOutputStream.c b/src/native/vm/cldc1.1/com_sun_cldchi_io_ConsoleOutputStream.c
deleted file mode 100644 (file)
index fc642a1..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/* src/native/vm/cldc1.1/com_sun_cldchi_io_ConsoleOutputStream.c
-
-   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
-
-   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.
-
-*/
-
-
-#include "config.h"
-
-#include <stdio.h>
-
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/native.h"
-
-#include "native/include/com_sun_cldchi_io_ConsoleOutputStream.h"
-
-
-/* native methods implemented by this file ************************************/
-static JNINativeMethod methods[] = {
-       { "write", "(I)V", (void *) (ptrint) &Java_com_sun_cldchi_io_ConsoleOutputStream_write },
-};
-
-/* _Jv_com_sun_cldchi_io_ConsoleOutputStream_init ******************************
-   Register native functions.
-*******************************************************************************/
-void _Jv_com_sun_cldchi_io_ConsoleOutputStream_init(void)
-{
-       utf *u;
-       u = utf_new_char("com/sun/cldchi/io/ConsoleOutputStream");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
-
-
-/*
- * Class:     com/sun/cldchi/io/ConsoleOutputStream
- * Method:    write
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL Java_com_sun_cldchi_io_ConsoleOutputStream_write(JNIEnv *env, com_sun_cldchi_io_ConsoleOutputStream *this, s4 c)
-{
-       (void) fputc(c, stdout);
-}
-
-
-/*
- * 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_cldchi_io_ConsoleOutputStream.cpp b/src/native/vm/cldc1.1/com_sun_cldchi_io_ConsoleOutputStream.cpp
new file mode 100644 (file)
index 0000000..d0caeb1
--- /dev/null
@@ -0,0 +1,96 @@
+/* src/native/vm/cldc1.1/com_sun_cldchi_io_ConsoleOutputStream.cpp
+
+   Copyright (C) 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+#include <stdio.h>
+
+#include "vm/types.h"
+
+#include "native/jni.h"
+#include "native/native.h"
+
+// FIXME
+extern "C" { 
+#include "native/include/com_sun_cldchi_io_ConsoleOutputStream.h"
+}
+
+
+/* native methods implemented by this file ************************************/
+static JNINativeMethod methods[] = {
+       { (char*) "write", (char*) "(I)V", (void*) (uintptr_t) &Java_com_sun_cldchi_io_ConsoleOutputStream_write },
+};
+
+/* _Jv_com_sun_cldchi_io_ConsoleOutputStream_init ******************************
+   Register native functions.
+*******************************************************************************/
+// FIXME
+extern "C" { 
+void _Jv_com_sun_cldchi_io_ConsoleOutputStream_init(void)
+{
+       utf *u;
+       u = utf_new_char("com/sun/cldchi/io/ConsoleOutputStream");
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
+}
+
+
+// Native functions are exported as C functions.
+extern "C" {
+
+/*
+ * Class:     com/sun/cldchi/io/ConsoleOutputStream
+ * Method:    write
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_com_sun_cldchi_io_ConsoleOutputStream_write(JNIEnv *env, com_sun_cldchi_io_ConsoleOutputStream *_this, int32_t c)
+{
+       (void) fputc(c, stdout);
+}
+
+} // extern "C"
+
+
+/*
+ * 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_cldchi_jvm_JVM.c b/src/native/vm/cldc1.1/com_sun_cldchi_jvm_JVM.c
deleted file mode 100644 (file)
index c8f7187..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/* src/native/vm/cldc1.1/com_sun_cldchi_jvm_JVM.c
-
-   Copyright (C) 2007, 2008
-   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
-   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.
-
-*/
-
-
-#include "config.h"
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/native.h"
-
-#include "native/include/java_lang_String.h"
-
-#include "native/include/com_sun_cldchi_jvm_JVM.h"
-
-#include "vm/exceptions.hpp"
-#include "vm/string.hpp"
-
-
-/* native methods implemented by this file ************************************/
-static JNINativeMethod methods[] = {
-       { "loadLibrary", "(Ljava/lang/String;)V", (void *) (ptrint) &Java_com_sun_cldchi_jvm_JVM_loadLibrary },
-};
-
-
-/* _Jv_com_sun_cldchi_jvm_JVM_init *********************************************
-   Register native functions.
-*******************************************************************************/
-void _Jv_com_sun_cldchi_jvm_JVM_init(void)
-{
-       utf *u;
-       u = utf_new_char("com/sun/cldchi/jvm/JVM");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
-
-
-/*
- * Class:     com/sun/cldchi/jvm/JVM
- * Method:    loadLibrary
- * Signature: (Ljava/lang/String;)V
- */
-JNIEXPORT void JNICALL Java_com_sun_cldchi_jvm_JVM_loadLibrary(JNIEnv *env, jclass clazz, java_lang_String *libName)
-{
-       int  result;
-       utf *name;
-
-       /* REMOVEME When we use Java-strings internally. */
-
-       if (libName == NULL) {
-               exceptions_throw_nullpointerexception();
-               return;
-       }
-
-       name = javastring_toutf((java_handle_t *) libName, false);
-
-       result = native_library_load(env, name, NULL);
-
-       /* Check for error and throw an exception in case. */
-
-       if (result == 0) {
-               exceptions_throw_unsatisfiedlinkerror(name);
-       }
-}
-
-
-/*
- * 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_cldchi_jvm_JVM.cpp b/src/native/vm/cldc1.1/com_sun_cldchi_jvm_JVM.cpp
new file mode 100644 (file)
index 0000000..5078faf
--- /dev/null
@@ -0,0 +1,116 @@
+/* src/native/vm/cldc1.1/com_sun_cldchi_jvm_JVM.cpp
+
+   Copyright (C) 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+
+#include "native/jni.h"
+#include "native/native.h"
+
+#include "native/include/java_lang_String.h"
+
+// FIXME
+extern "C" { 
+#include "native/include/com_sun_cldchi_jvm_JVM.h"
+}
+
+#include "vm/exceptions.hpp"
+#include "vm/string.hpp"
+
+
+/* native methods implemented by this file ************************************/
+static JNINativeMethod methods[] = {
+       { (char*) "loadLibrary", (char*) "(Ljava/lang/String;)V", (void*) (uintptr_t) &Java_com_sun_cldchi_jvm_JVM_loadLibrary },
+};
+
+
+/* _Jv_com_sun_cldchi_jvm_JVM_init *********************************************
+   Register native functions.
+*******************************************************************************/
+// FIXME
+extern "C" { 
+void _Jv_com_sun_cldchi_jvm_JVM_init(void)
+{
+       utf *u;
+       u = utf_new_char("com/sun/cldchi/jvm/JVM");
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
+}
+
+
+// Native functions are exported as C functions.
+extern "C" {
+
+/*
+ * Class:     com/sun/cldchi/jvm/JVM
+ * Method:    loadLibrary
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_com_sun_cldchi_jvm_JVM_loadLibrary(JNIEnv *env, jclass clazz, java_lang_String *libName)
+{
+       int  result;
+       utf *name;
+
+       /* REMOVEME When we use Java-strings internally. */
+
+       if (libName == NULL) {
+               exceptions_throw_nullpointerexception();
+               return;
+       }
+
+       name = javastring_toutf((java_handle_t *) libName, false);
+
+       result = native_library_load(env, name, NULL);
+
+       /* Check for error and throw an exception in case. */
+
+       if (result == 0) {
+               exceptions_throw_unsatisfiedlinkerror(name);
+       }
+}
+
+} // extern "C"
+
+
+/*
+ * 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
deleted file mode 100644 (file)
index 7713afd..0000000
+++ /dev/null
@@ -1,239 +0,0 @@
-/* src/native/vm/cldc1.1/java_lang_Class.c
-
-   Copyright (C) 2006, 2007, 2008
-   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
-   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.
-
-*/
-
-
-#include "config.h"
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/llni.h"
-#include "native/native.h"
-
-#include "native/include/java_lang_String.h"             /* required by j.l.C */
-#include "native/include/java_lang_Object.h"
-
-#include "native/include/java_lang_Class.h"
-
-#include "vm/exceptions.hpp"
-#include "vm/initialize.h"
-
-
-/* native methods implemented by this file ************************************/
-static JNINativeMethod methods[] = {
-       { "forName",          "(Ljava/lang/String;)Ljava/lang/Class;",(void *) (ptrint) &Java_java_lang_Class_forName          },
-       { "newInstance",      "()Ljava/lang/Object;",                 (void *) (ptrint) &Java_java_lang_Class_newInstance      },
-       { "isInstance",       "(Ljava/lang/Object;)Z",                (void *) (ptrint) &Java_java_lang_Class_isInstance       },
-       { "isAssignableFrom", "(Ljava/lang/Class;)Z",                 (void *) (ptrint) &Java_java_lang_Class_isAssignableFrom },
-       { "isInterface",      "()Z",                                  (void *) (ptrint) &Java_java_lang_Class_isInterface      },
-       { "isArray",          "()Z",                                  (void *) (ptrint) &Java_java_lang_Class_isArray          },
-       { "getName",          "()Ljava/lang/String;",                 (void *) (ptrint) &Java_java_lang_Class_getName          },
-};
-
-/* _Jv_java_lang_Class_init ****************************************************
-   Register native functions.
-*******************************************************************************/
-void _Jv_java_lang_Class_init(void)
-{
-       utf *u;
-       u = utf_new_char("java/lang/Class");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
-
-
-/*
- * Class:     java/lang/Class
- * Method:    forName
- * Signature: (Ljava/lang/String;)Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_java_lang_Class_forName(JNIEnv *env, jclass clazz, java_lang_String *name)
-{
-       utf       *ufile;
-       utf       *uname;
-       classinfo *c;
-       u2        *pos;
-       s4         i;
-
-       /* illegal argument */
-
-       if (name == NULL) {
-               exceptions_throw_nullpointerexception();
-               return NULL;
-       }
-
-       /* create utf string in which '.' is replaced by '/' */
-
-       ufile = javastring_toutf((java_handle_t *) name, true);
-       uname = javastring_toutf((java_handle_t *) name, false);
-
-       /* name must not contain '/' (mauve test) */
-
-       for (i = 0, pos = LLNI_field_direct(name, value)->data + LLNI_field_direct(name, offset); i < LLNI_field_direct(name, count); i++, pos++) {
-               if (*pos == '/') {
-                       exceptions_throw_classnotfoundexception(uname);
-                       return NULL;
-               }
-       }
-
-       /* try to load, ... */
-
-       c = load_class_bootstrap(ufile);
-
-       if (c == NULL)
-           return NULL;
-
-       /* link, ... */
-
-       if (!link_class(c))
-               return NULL;
-       
-       /* ...and initialize it. */
-
-       if (!initialize_class(c))
-               return NULL;
-
-       return LLNI_classinfo_wrap(c);
-}
-
-
-/*
- * Class:     java/lang/Class
- * Method:    newInstance
- * Signature: ()Ljava/lang/Object;
- */
-JNIEXPORT java_lang_Object* JNICALL Java_java_lang_Class_newInstance(JNIEnv *env, java_lang_Class* this)
-{
-       classinfo     *c;
-       java_handle_t *o;
-
-       c = LLNI_classinfo_unwrap(this);
-
-       o = native_new_and_init(c);
-
-       return (java_lang_Object *) o;
-}
-
-
-/*
- * Class:     java/lang/Class
- * Method:    isInstance
- * Signature: (Ljava/lang/Object;)Z
- */
-JNIEXPORT int32_t JNICALL Java_java_lang_Class_isInstance(JNIEnv *env, java_lang_Class *this, java_lang_Object *obj)
-{
-       classinfo     *c;
-       java_handle_t *h;
-
-       c = LLNI_classinfo_unwrap(this);
-       h = (java_handle_t *) obj;
-
-       return class_is_instance(c, h);
-}
-
-
-/*
- * Class:     java/lang/Class
- * Method:    isAssignableFrom
- * Signature: (Ljava/lang/Class;)Z
- */
-JNIEXPORT int32_t JNICALL Java_java_lang_Class_isAssignableFrom(JNIEnv *env, java_lang_Class *this, java_lang_Class *cls)
-{
-       classinfo *to;
-       classinfo *from;
-
-       to   = LLNI_classinfo_unwrap(this);
-       from = LLNI_classinfo_unwrap(cls);
-
-       if (from == NULL) {
-               exceptions_throw_nullpointerexception();
-               return 0;
-       }
-
-       return class_is_assignable_from(to, from);
-}
-
-
-/*
- * Class:     java/lang/Class
- * Method:    isInterface
- * Signature: ()Z
- */
-JNIEXPORT int32_t JNICALL Java_java_lang_Class_isInterface(JNIEnv *env, java_lang_Class *this)
-{
-       classinfo *c;
-
-       c = LLNI_classinfo_unwrap(this);
-
-       return class_is_interface(c);
-}
-
-
-/*
- * Class:     java/lang/Class
- * Method:    isArray
- * Signature: ()Z
- */
-JNIEXPORT int32_t JNICALL Java_java_lang_Class_isArray(JNIEnv *env, java_lang_Class *this)
-{
-       classinfo *c;
-
-       c = LLNI_classinfo_unwrap(this);
-
-       return class_is_array(c);
-}
-
-
-/*
- * Class:     java/lang/Class
- * Method:    getName
- * Signature: ()Ljava/lang/String;
- */
-JNIEXPORT java_lang_String* JNICALL Java_java_lang_Class_getName(JNIEnv *env, java_lang_Class *this)
-{
-       classinfo *c;
-
-       c = LLNI_classinfo_unwrap(this);
-
-       return (java_lang_String*) class_get_classname(c);
-}
-
-
-/*
- * 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.cpp b/src/native/vm/cldc1.1/java_lang_Class.cpp
new file mode 100644 (file)
index 0000000..9e86764
--- /dev/null
@@ -0,0 +1,251 @@
+/* src/native/vm/cldc1.1/java_lang_Class.cpp
+
+   Copyright (C) 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+
+#include "native/jni.h"
+#include "native/llni.h"
+#include "native/native.h"
+
+#include "native/include/java_lang_String.h"             /* required by j.l.C */
+#include "native/include/java_lang_Object.h"
+
+// FIXME
+extern "C" { 
+#include "native/include/java_lang_Class.h"
+}
+
+#include "vm/exceptions.hpp"
+#include "vm/initialize.h"
+
+
+/* native methods implemented by this file ************************************/
+static JNINativeMethod methods[] = {
+       { (char*) "forName",          (char*) "(Ljava/lang/String;)Ljava/lang/Class;",(void*) (uintptr_t) &Java_java_lang_Class_forName          },
+       { (char*) "newInstance",      (char*) "()Ljava/lang/Object;",                 (void*) (uintptr_t) &Java_java_lang_Class_newInstance      },
+       { (char*) "isInstance",       (char*) "(Ljava/lang/Object;)Z",                (void*) (uintptr_t) &Java_java_lang_Class_isInstance       },
+       { (char*) "isAssignableFrom", (char*) "(Ljava/lang/Class;)Z",                 (void*) (uintptr_t) &Java_java_lang_Class_isAssignableFrom },
+       { (char*) "isInterface",      (char*) "()Z",                                  (void*) (uintptr_t) &Java_java_lang_Class_isInterface      },
+       { (char*) "isArray",          (char*) "()Z",                                  (void*) (uintptr_t) &Java_java_lang_Class_isArray          },
+       { (char*) "getName",          (char*) "()Ljava/lang/String;",                 (void*) (uintptr_t) &Java_java_lang_Class_getName          },
+};
+
+/* _Jv_java_lang_Class_init ****************************************************
+   Register native functions.
+*******************************************************************************/
+
+// FIXME
+extern "C" { 
+void _Jv_java_lang_Class_init(void)
+{
+       utf *u;
+       u = utf_new_char("java/lang/Class");
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
+}
+
+
+// Native functions are exported as C functions.
+extern "C" {
+
+/*
+ * Class:     java/lang/Class
+ * Method:    forName
+ * Signature: (Ljava/lang/String;)Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_java_lang_Class_forName(JNIEnv *env, jclass clazz, java_lang_String *name)
+{
+       utf       *ufile;
+       utf       *uname;
+       classinfo *c;
+       u2        *pos;
+       s4         i;
+
+       /* illegal argument */
+
+       if (name == NULL) {
+               exceptions_throw_nullpointerexception();
+               return NULL;
+       }
+
+       /* create utf string in which '.' is replaced by '/' */
+
+       ufile = javastring_toutf((java_handle_t *) name, true);
+       uname = javastring_toutf((java_handle_t *) name, false);
+
+       /* name must not contain '/' (mauve test) */
+
+       for (i = 0, pos = LLNI_field_direct(name, value)->data + LLNI_field_direct(name, offset); i < LLNI_field_direct(name, count); i++, pos++) {
+               if (*pos == '/') {
+                       exceptions_throw_classnotfoundexception(uname);
+                       return NULL;
+               }
+       }
+
+       /* try to load, ... */
+
+       c = load_class_bootstrap(ufile);
+
+       if (c == NULL)
+           return NULL;
+
+       /* link, ... */
+
+       if (!link_class(c))
+               return NULL;
+       
+       /* ...and initialize it. */
+
+       if (!initialize_class(c))
+               return NULL;
+
+       return LLNI_classinfo_wrap(c);
+}
+
+
+/*
+ * Class:     java/lang/Class
+ * Method:    newInstance
+ * Signature: ()Ljava/lang/Object;
+ */
+JNIEXPORT java_lang_Object* JNICALL Java_java_lang_Class_newInstance(JNIEnv *env, java_lang_Class* _this)
+{
+       classinfo     *c;
+       java_handle_t *o;
+
+       c = LLNI_classinfo_unwrap(_this);
+
+       o = native_new_and_init(c);
+
+       return (java_lang_Object *) o;
+}
+
+
+/*
+ * Class:     java/lang/Class
+ * Method:    isInstance
+ * Signature: (Ljava/lang/Object;)Z
+ */
+JNIEXPORT int32_t JNICALL Java_java_lang_Class_isInstance(JNIEnv *env, java_lang_Class *_this, java_lang_Object *obj)
+{
+       classinfo     *c;
+       java_handle_t *h;
+
+       c = LLNI_classinfo_unwrap(_this);
+       h = (java_handle_t *) obj;
+
+       return class_is_instance(c, h);
+}
+
+
+/*
+ * Class:     java/lang/Class
+ * Method:    isAssignableFrom
+ * Signature: (Ljava/lang/Class;)Z
+ */
+JNIEXPORT int32_t JNICALL Java_java_lang_Class_isAssignableFrom(JNIEnv *env, java_lang_Class *_this, java_lang_Class *cls)
+{
+       classinfo *to;
+       classinfo *from;
+
+       to   = LLNI_classinfo_unwrap(_this);
+       from = LLNI_classinfo_unwrap(cls);
+
+       if (from == NULL) {
+               exceptions_throw_nullpointerexception();
+               return 0;
+       }
+
+       return class_is_assignable_from(to, from);
+}
+
+
+/*
+ * Class:     java/lang/Class
+ * Method:    isInterface
+ * Signature: ()Z
+ */
+JNIEXPORT int32_t JNICALL Java_java_lang_Class_isInterface(JNIEnv *env, java_lang_Class *_this)
+{
+       classinfo *c;
+
+       c = LLNI_classinfo_unwrap(_this);
+
+       return class_is_interface(c);
+}
+
+
+/*
+ * Class:     java/lang/Class
+ * Method:    isArray
+ * Signature: ()Z
+ */
+JNIEXPORT int32_t JNICALL Java_java_lang_Class_isArray(JNIEnv *env, java_lang_Class *_this)
+{
+       classinfo *c;
+
+       c = LLNI_classinfo_unwrap(_this);
+
+       return class_is_array(c);
+}
+
+
+/*
+ * Class:     java/lang/Class
+ * Method:    getName
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT java_lang_String* JNICALL Java_java_lang_Class_getName(JNIEnv *env, java_lang_Class *_this)
+{
+       classinfo *c;
+
+       c = LLNI_classinfo_unwrap(_this);
+
+       return (java_lang_String*) class_get_classname(c);
+}
+
+} // extern "C"
+
+
+/*
+ * 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_Double.c b/src/native/vm/cldc1.1/java_lang_Double.c
deleted file mode 100644 (file)
index 99f3195..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/* src/native/vm/cldc1.1/java_lang_Double.c
-
-   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
-
-   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.
-
-*/
-
-
-#include "config.h"
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/native.h"
-
-#include "native/include/java_lang_Double.h"
-
-#include "vm/builtin.h"
-
-
-/* native methods implemented by this file ************************************/
-static JNINativeMethod methods[] = {
-       { "doubleToLongBits", "(D)J", (void *) (ptrint) &Java_java_lang_Double_doubleToLongBits },
-       { "longBitsToDouble", "(J)D", (void *) (ptrint) &Java_java_lang_Double_longBitsToDouble },
-};
-/* _Jv_java_lang_Double_init ***************************************************
-   Register native functions.
-*******************************************************************************/
-void _Jv_java_lang_Double_init(void)
-{
-       utf *u;
-       u = utf_new_char("java/lang/Double");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
-
-
-/*
- * Class:     java/lang/Double
- * Method:    doubleToLongBits
- * Signature: (D)J
- */
-JNIEXPORT s8 JNICALL Java_java_lang_Double_doubleToLongBits(JNIEnv *env, jclass clazz, double doubleValue)
-{
-       jvalue val;
-       s8  e, f;
-       val.d = doubleValue;
-
-#if defined(__IEEE_BYTES_LITTLE_ENDIAN)
-       /* On little endian ARM processors when using FPA, word order of
-          doubles is still big endian. So take that into account here. When
-          using VFP, word order of doubles follows byte order. */
-
-#define SWAP_DOUBLE(a)    (((a) << 32) | (((a) >> 32) & 0x00000000ffffffff))
-
-       val.j = SWAP_DOUBLE(val.j);
-#endif
-
-       e = val.j & 0x7ff0000000000000LL;
-       f = val.j & 0x000fffffffffffffLL;
-
-       if (e == DBL_POSINF && f != 0L)
-               val.j = DBL_NAN;
-
-       return val.j;
-}
-
-
-/*
- * Class:     java/lang/Double
- * Method:    longBitsToDouble
- * Signature: (J)D
- */
-JNIEXPORT double JNICALL Java_java_lang_Double_longBitsToDouble(JNIEnv *env, jclass clazz, s8 longValue)
-{
-       jvalue val;
-       val.j = longValue;
-
-#if defined(__IEEE_BYTES_LITTLE_ENDIAN)
-       val.j = SWAP_DOUBLE(val.j);
-#endif
-
-       return val.d;
-}
-
-
-/*
- * 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:
- */
diff --git a/src/native/vm/cldc1.1/java_lang_Double.cpp b/src/native/vm/cldc1.1/java_lang_Double.cpp
new file mode 100644 (file)
index 0000000..3c48cdf
--- /dev/null
@@ -0,0 +1,133 @@
+/* src/native/vm/cldc1.1/java_lang_Double.c
+
+   Copyright (C) 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+
+#include "native/jni.h"
+#include "native/native.h"
+
+// FIXME
+extern "C" {
+#include "native/include/java_lang_Double.h"
+}
+
+#include "vm/builtin.h"
+
+
+/* native methods implemented by this file ************************************/
+static JNINativeMethod methods[] = {
+       { (char*) "doubleToLongBits", (char*) "(D)J", (void*) (uintptr_t) &Java_java_lang_Double_doubleToLongBits },
+       { (char*) "longBitsToDouble", (char*) "(J)D", (void*) (uintptr_t) &Java_java_lang_Double_longBitsToDouble },
+};
+/* _Jv_java_lang_Double_init ***************************************************
+   Register native functions.
+*******************************************************************************/
+
+// FIXME
+extern "C" { 
+void _Jv_java_lang_Double_init(void)
+{
+       utf *u;
+       u = utf_new_char("java/lang/Double");
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
+}
+
+
+// Native functions are exported as C functions.
+extern "C" {
+
+/*
+ * Class:     java/lang/Double
+ * Method:    doubleToLongBits
+ * Signature: (D)J
+ */
+JNIEXPORT int64_t JNICALL Java_java_lang_Double_doubleToLongBits(JNIEnv *env, jclass clazz, double doubleValue)
+{
+       jvalue val;
+       s8  e, f;
+       val.d = doubleValue;
+
+#if defined(__IEEE_BYTES_LITTLE_ENDIAN)
+       /* On little endian ARM processors when using FPA, word order of
+          doubles is still big endian. So take that into account here. When
+          using VFP, word order of doubles follows byte order. */
+
+#define SWAP_DOUBLE(a)    (((a) << 32) | (((a) >> 32) & 0x00000000ffffffff))
+
+       val.j = SWAP_DOUBLE(val.j);
+#endif
+
+       e = val.j & 0x7ff0000000000000LL;
+       f = val.j & 0x000fffffffffffffLL;
+
+       if (e == DBL_POSINF && f != 0L)
+               val.j = DBL_NAN;
+
+       return val.j;
+}
+
+
+/*
+ * Class:     java/lang/Double
+ * Method:    longBitsToDouble
+ * Signature: (J)D
+ */
+JNIEXPORT double JNICALL Java_java_lang_Double_longBitsToDouble(JNIEnv *env, jclass clazz, int64_t longValue)
+{
+       jvalue val;
+       val.j = longValue;
+
+#if defined(__IEEE_BYTES_LITTLE_ENDIAN)
+       val.j = SWAP_DOUBLE(val.j);
+#endif
+
+       return val.d;
+}
+
+} // extern "C"
+
+
+/*
+ * 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:
+ */
diff --git a/src/native/vm/cldc1.1/java_lang_Float.c b/src/native/vm/cldc1.1/java_lang_Float.c
deleted file mode 100644 (file)
index 67cb004..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/* src/native/vm/cldc1.1/java_lang_Float.c
-
-   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
-
-   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.
-
-*/
-
-
-#include "config.h"
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/native.h"
-
-#include "native/include/java_lang_Float.h"
-
-#include "vm/builtin.h"
-
-
-/* native methods implemented by this file ************************************/
-static JNINativeMethod methods[] = {
-       { "floatToIntBits", "(F)I",     (void *) (ptrint) &Java_java_lang_Float_floatToIntBits },
-};
-/* _Jv_java_lang_Float_init ****************************************************
-   Register native functions.
-*******************************************************************************/
-void _Jv_java_lang_Float_init(void)
-{
-       utf *u;
-       u = utf_new_char("java/lang/Float");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
-
-/*
- * Class:     java/lang/Float
- * Method:    floatToIntBits
- * Signature: (F)I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_Float_floatToIntBits(JNIEnv *env, jclass clazz, float value)
-{
-       imm_union val;
-       int e, f;
-
-       val.f = value;
-
-       e = val.i & 0x7f800000;
-       f = val.i & 0x007fffff;
-
-       if (e == FLT_POSINF && f != 0)
-               return FLT_NAN;
-
-       return val.i;
-}
-
-
-/*
- * 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:
- */
diff --git a/src/native/vm/cldc1.1/java_lang_Float.cpp b/src/native/vm/cldc1.1/java_lang_Float.cpp
new file mode 100644 (file)
index 0000000..0018381
--- /dev/null
@@ -0,0 +1,105 @@
+/* src/native/vm/cldc1.1/java_lang_Float.cpp
+
+   Copyright (C) 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+
+#include "native/jni.h"
+#include "native/native.h"
+
+// FIXME
+extern "C" {
+#include "native/include/java_lang_Float.h"
+}
+
+#include "vm/builtin.h"
+
+
+/* native methods implemented by this file ************************************/
+static JNINativeMethod methods[] = {
+       { (char*) "floatToIntBits", (char*) "(F)I", (void*) (uintptr_t) &Java_java_lang_Float_floatToIntBits },
+};
+/* _Jv_java_lang_Float_init ****************************************************
+   Register native functions.
+*******************************************************************************/
+
+// FIXME
+extern "C" { 
+void _Jv_java_lang_Float_init(void)
+{
+       utf *u;
+       u = utf_new_char("java/lang/Float");
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
+}
+
+
+// Native functions are exported as C functions.
+extern "C" {
+
+/*
+ * Class:     java/lang/Float
+ * Method:    floatToIntBits
+ * Signature: (F)I
+ */
+JNIEXPORT int32_t JNICALL Java_java_lang_Float_floatToIntBits(JNIEnv *env, jclass clazz, float value)
+{
+       imm_union val;
+       int e, f;
+
+       val.f = value;
+
+       e = val.i & 0x7f800000;
+       f = val.i & 0x007fffff;
+
+       if (e == FLT_POSINF && f != 0)
+               return FLT_NAN;
+
+       return val.i;
+}
+
+} // extern "C"
+
+
+/*
+ * 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:
+ */
diff --git a/src/native/vm/cldc1.1/java_lang_Math.c b/src/native/vm/cldc1.1/java_lang_Math.c
deleted file mode 100644 (file)
index 9d542b7..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-/* src/native/vm/cldc1.1/java_lang_Math.c
-
-   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
-
-   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.
-
-*/
-
-
-#include "config.h"
-#include "vm/types.h"
-
-#include "fdlibm/fdlibm.h"
-
-#include "native/jni.h"
-#include "native/native.h"
-
-#include "native/include/java_lang_Math.h"
-
-
-/* native methods implemented by this file ************************************/
-static JNINativeMethod methods[] = {
-       { "ceil",  "(D)D", (void *) (ptrint) &Java_java_lang_Math_ceil  },
-       { "cos",   "(D)D", (void *) (ptrint) &Java_java_lang_Math_cos   },
-       { "floor", "(D)D", (void *) (ptrint) &Java_java_lang_Math_floor },
-       { "sin",   "(D)D", (void *) (ptrint) &Java_java_lang_Math_sin   },
-       { "sqrt",  "(D)D", (void *) (ptrint) &Java_java_lang_Math_sqrt  },
-       { "tan",   "(D)D", (void *) (ptrint) &Java_java_lang_Math_tan   },
-};
-/* _Jv_java_lang_Math_init *****************************************************
-   Register native functions.
-*******************************************************************************/
-void _Jv_java_lang_Math_init(void)
-{
-       utf *u;
-       u = utf_new_char("java/lang/Math");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
-
-
-/*
- * Class:     java/lang/Math
- * Method:    ceil
- * Signature: (D)D
- */
-JNIEXPORT double JNICALL Java_java_lang_Math_ceil(JNIEnv *env, jclass clazz, double a)
-{
-       return ceil(a);
-}
-
-
-/*
- * Class:     java/lang/Math
- * Method:    cos
- * Signature: (D)D
- */
-JNIEXPORT double JNICALL Java_java_lang_Math_cos(JNIEnv *env, jclass clazz, double a)
-{
-       return cos(a);
-}
-
-
-/*
- * Class:     java/lang/Math
- * Method:    floor
- * Signature: (D)D
- */
-JNIEXPORT double JNICALL Java_java_lang_Math_floor(JNIEnv *env, jclass clazz, double a)
-{
-       return floor(a);
-}
-
-
-/*
- * Class:     java/lang/Math
- * Method:    sin
- * Signature: (D)D
- */
-JNIEXPORT double JNICALL Java_java_lang_Math_sin(JNIEnv *env, jclass clazz, double a)
-{
-       return sin(a);
-}
-
-
-/*
- * Class:     java/lang/Math
- * Method:    sqrt
- * Signature: (D)D
- */
-JNIEXPORT double JNICALL Java_java_lang_Math_sqrt(JNIEnv *env, jclass clazz, double a)
-{
-       return sqrt(a);
-}
-
-
-/*
- * Class:     java/lang/Math
- * Method:    tan
- * Signature: (D)D
- */
-JNIEXPORT double JNICALL Java_java_lang_Math_tan(JNIEnv *env, jclass clazz, double a)
-{
-       return tan(a);
-}
-
-
-/*
- * 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_Math.cpp b/src/native/vm/cldc1.1/java_lang_Math.cpp
new file mode 100644 (file)
index 0000000..55331e6
--- /dev/null
@@ -0,0 +1,155 @@
+/* src/native/vm/cldc1.1/java_lang_Math.c
+
+   Copyright (C) 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+
+#include "fdlibm/fdlibm.h"
+
+#include "native/jni.h"
+#include "native/native.h"
+
+// FIXME
+extern "C" {
+#include "native/include/java_lang_Math.h"
+}
+
+
+/* native methods implemented by this file ************************************/
+static JNINativeMethod methods[] = {
+       { (char*) "ceil",  (char*) "(D)D", (void*) (uintptr_t) &Java_java_lang_Math_ceil  },
+       { (char*) "cos",   (char*) "(D)D", (void*) (uintptr_t) &Java_java_lang_Math_cos   },
+       { (char*) "floor", (char*) "(D)D", (void*) (uintptr_t) &Java_java_lang_Math_floor },
+       { (char*) "sin",   (char*) "(D)D", (void*) (uintptr_t) &Java_java_lang_Math_sin   },
+       { (char*) "sqrt",  (char*) "(D)D", (void*) (uintptr_t) &Java_java_lang_Math_sqrt  },
+       { (char*) "tan",   (char*) "(D)D", (void*) (uintptr_t) &Java_java_lang_Math_tan   },
+};
+/* _Jv_java_lang_Math_init *****************************************************
+   Register native functions.
+*******************************************************************************/
+
+// FIXME
+extern "C" { 
+void _Jv_java_lang_Math_init(void)
+{
+       utf *u;
+       u = utf_new_char("java/lang/Math");
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
+}
+
+
+// Native functions are exported as C functions.
+extern "C" {
+
+/*
+ * Class:     java/lang/Math
+ * Method:    ceil
+ * Signature: (D)D
+ */
+JNIEXPORT double JNICALL Java_java_lang_Math_ceil(JNIEnv *env, jclass clazz, double a)
+{
+       return ceil(a);
+}
+
+
+/*
+ * Class:     java/lang/Math
+ * Method:    cos
+ * Signature: (D)D
+ */
+JNIEXPORT double JNICALL Java_java_lang_Math_cos(JNIEnv *env, jclass clazz, double a)
+{
+       return cos(a);
+}
+
+
+/*
+ * Class:     java/lang/Math
+ * Method:    floor
+ * Signature: (D)D
+ */
+JNIEXPORT double JNICALL Java_java_lang_Math_floor(JNIEnv *env, jclass clazz, double a)
+{
+       return floor(a);
+}
+
+
+/*
+ * Class:     java/lang/Math
+ * Method:    sin
+ * Signature: (D)D
+ */
+JNIEXPORT double JNICALL Java_java_lang_Math_sin(JNIEnv *env, jclass clazz, double a)
+{
+       return sin(a);
+}
+
+
+/*
+ * Class:     java/lang/Math
+ * Method:    sqrt
+ * Signature: (D)D
+ */
+JNIEXPORT double JNICALL Java_java_lang_Math_sqrt(JNIEnv *env, jclass clazz, double a)
+{
+       return sqrt(a);
+}
+
+
+/*
+ * Class:     java/lang/Math
+ * Method:    tan
+ * Signature: (D)D
+ */
+JNIEXPORT double JNICALL Java_java_lang_Math_tan(JNIEnv *env, jclass clazz, double a)
+{
+       return tan(a);
+}
+
+} // extern "C"
+
+
+/*
+ * 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_Object.c b/src/native/vm/cldc1.1/java_lang_Object.c
deleted file mode 100644 (file)
index 702da84..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-/* src/native/vm/cldc1.1/java_lang_Object.c
-
-   Copyright (C) 2006, 2007, 2008
-   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
-   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.
-
-*/
-
-
-#include "config.h"
-
-#include <stdlib.h>
-
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/llni.h"
-#include "native/native.h"
-
-#include "native/include/java_lang_String.h"             /* required by j.l.C */
-#include "native/include/java_lang_Class.h"
-
-#include "native/include/java_lang_Object.h"
-
-#include "threads/lock-common.h"
-
-#include "vm/exceptions.hpp"
-
-
-/* native methods implemented by this file ************************************/
-static JNINativeMethod methods[] = {
-       { "getClass",  "()Ljava/lang/Class;",                   (void *) (ptrint) &Java_java_lang_Object_getClass  },
-       { "hashCode",  "()I",                                   (void *) (ptrint) &Java_java_lang_Object_hashCode  },
-       { "notify",    "()V",                                   (void *) (ptrint) &Java_java_lang_Object_notify    },
-       { "notifyAll", "()V",                                   (void *) (ptrint) &Java_java_lang_Object_notifyAll },
-       { "wait",      "(J)V",                                  (void *) (ptrint) &Java_java_lang_Object_wait      },
-};
-/* _Jv_java_lang_Object_init ***************************************************
-   Register native functions.
-*******************************************************************************/
-void _Jv_java_lang_Object_init(void)
-{
-       utf *u;
-       u = utf_new_char("java/lang/Object");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
-
-
-/*
- * Class:     java/lang/Object
- * Method:    getClass
- * Signature: ()Ljava/lang/Class;
- */
-JNIEXPORT java_lang_Class* JNICALL Java_java_lang_Object_getClass(JNIEnv *env, java_lang_Object *obj)
-{
-       classinfo *c;
-
-       if (obj == NULL) {
-               exceptions_throw_nullpointerexception();
-               return NULL;
-       }
-
-       LLNI_class_get(obj, c);
-
-       return LLNI_classinfo_wrap(c);
-}
-
-
-/*
- * Class:     java/lang/Object
- * Method:    hashCode
- * Signature: ()I
- */
-JNIEXPORT int32_t JNICALL Java_java_lang_Object_hashCode(JNIEnv *env, java_lang_Object *this)
-{
-#if defined(ENABLE_GC_CACAO)
-       assert(0);
-#else
-       return (int32_t) ((intptr_t) this);
-#endif
-}
-
-
-/*
- * Class:     java/lang/Object
- * Method:    notify
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_Object_notify(JNIEnv *env, java_lang_Object *this)
-{
-#if defined(ENABLE_THREADS)
-       lock_notify_object((java_handle_t *) this);
-#endif
-}
-
-
-/*
- * Class:     java/lang/Object
- * Method:    notifyAll
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_Object_notifyAll(JNIEnv *env, java_lang_Object *this)
-{
-#if defined(ENABLE_THREADS)
-       lock_notify_all_object((java_handle_t *) this);
-#endif
-}
-
-
-/*
- * Class:     java/lang/Object
- * Method:    wait
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_java_lang_Object_wait(JNIEnv *env, java_lang_Object *this, s8 timeout)
-{
-#if defined(ENABLE_JVMTI)
-       /* Monitor Wait */
-       if (jvmti) jvmti_MonitorWaiting(true, this, timeout);
-#endif
-
-#if defined(ENABLE_THREADS)
-       lock_wait_for_object((java_handle_t *) this, timeout, 0);
-#endif
-
-#if defined(ENABLE_JVMTI)
-       /* Monitor Waited */
-       /* XXX: How do you know if wait timed out ?*/
-       if (jvmti) jvmti_MonitorWaiting(false, this, 0);
-#endif
-}
-
-
-/*
- * 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_Object.cpp b/src/native/vm/cldc1.1/java_lang_Object.cpp
new file mode 100644 (file)
index 0000000..a275a43
--- /dev/null
@@ -0,0 +1,180 @@
+/* src/native/vm/cldc1.1/java_lang_Object.c
+
+   Copyright (C) 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "native/jni.h"
+#include "native/llni.h"
+#include "native/native.h"
+
+#include "native/include/java_lang_String.h"             /* required by j.l.C */
+#include "native/include/java_lang_Class.h"
+
+// FIXME
+extern "C" {
+#include "native/include/java_lang_Object.h"
+}
+
+#include "threads/lock-common.h"
+
+#include "vm/exceptions.hpp"
+
+
+/* native methods implemented by this file ************************************/
+static JNINativeMethod methods[] = {
+       { (char*) "getClass",  (char*) "()Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_Object_getClass  },
+       { (char*) "hashCode",  (char*) "()I",                 (void*) (uintptr_t) &Java_java_lang_Object_hashCode  },
+       { (char*) "notify",    (char*) "()V",                 (void*) (uintptr_t) &Java_java_lang_Object_notify    },
+       { (char*) "notifyAll", (char*) "()V",                 (void*) (uintptr_t) &Java_java_lang_Object_notifyAll },
+       { (char*) "wait",      (char*) "(J)V",                (void*) (uintptr_t) &Java_java_lang_Object_wait      },
+};
+/* _Jv_java_lang_Object_init ***************************************************
+   Register native functions.
+*******************************************************************************/
+// FIXME
+extern "C" {
+void _Jv_java_lang_Object_init(void)
+{
+       utf *u;
+       u = utf_new_char("java/lang/Object");
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
+}
+
+
+// Native functions are exported as C functions.
+extern "C" {
+
+/*
+ * Class:     java/lang/Object
+ * Method:    getClass
+ * Signature: ()Ljava/lang/Class;
+ */
+JNIEXPORT java_lang_Class* JNICALL Java_java_lang_Object_getClass(JNIEnv *env, java_lang_Object *obj)
+{
+       classinfo *c;
+
+       if (obj == NULL) {
+               exceptions_throw_nullpointerexception();
+               return NULL;
+       }
+
+       LLNI_class_get(obj, c);
+
+       return LLNI_classinfo_wrap(c);
+}
+
+
+/*
+ * Class:     java/lang/Object
+ * Method:    hashCode
+ * Signature: ()I
+ */
+JNIEXPORT int32_t JNICALL Java_java_lang_Object_hashCode(JNIEnv *env, java_lang_Object *_this)
+{
+#if defined(ENABLE_GC_CACAO)
+       assert(0);
+#else
+       return (int32_t) ((intptr_t) _this);
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Object
+ * Method:    notify
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_Object_notify(JNIEnv *env, java_lang_Object *_this)
+{
+#if defined(ENABLE_THREADS)
+       lock_notify_object((java_handle_t *) _this);
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Object
+ * Method:    notifyAll
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_Object_notifyAll(JNIEnv *env, java_lang_Object *_this)
+{
+#if defined(ENABLE_THREADS)
+       lock_notify_all_object((java_handle_t *) _this);
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Object
+ * Method:    wait
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_Object_wait(JNIEnv *env, java_lang_Object *_this, s8 timeout)
+{
+#if defined(ENABLE_JVMTI)
+       /* Monitor Wait */
+       if (jvmti) jvmti_MonitorWaiting(true, _this, timeout);
+#endif
+
+#if defined(ENABLE_THREADS)
+       lock_wait_for_object((java_handle_t *) _this, timeout, 0);
+#endif
+
+#if defined(ENABLE_JVMTI)
+       /* Monitor Waited */
+       /* XXX: How do you know if wait timed out ?*/
+       if (jvmti) jvmti_MonitorWaiting(false, _this, 0);
+#endif
+}
+
+} // extern "C"
+
+
+/*
+ * 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_Runtime.c b/src/native/vm/cldc1.1/java_lang_Runtime.c
deleted file mode 100644 (file)
index 3b330a7..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/* src/native/vm/cldc1.1/java_lang_Runtime.c
-
-   Copyright (C) 2006, 2007, 2008
-   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
-   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.
-
-*/
-
-
-#include "config.h"
-
-#include <stdint.h>
-
-#include "mm/gc.hpp"
-
-#include "native/jni.h"
-#include "native/native.h"
-
-#include "native/include/java_lang_Runtime.h"
-
-#include "vm/vm.hpp"
-
-#include "vmcore/utf8.h"
-
-
-/* native methods implemented by this file ************************************/
-static JNINativeMethod methods[] = {
-       { "exitInternal", "(I)V", (void *) (intptr_t) &Java_java_lang_Runtime_exitInternal },
-       { "freeMemory",   "()J",  (void *) (intptr_t) &Java_java_lang_Runtime_freeMemory   },
-       { "totalMemory",  "()J",  (void *) (intptr_t) &Java_java_lang_Runtime_totalMemory  },
-       { "gc",           "()V",  (void *) (intptr_t) &Java_java_lang_Runtime_gc           },
-};
-/* _Jv_java_lang_Runtime_init **************************************************
-   Register native functions.
-*******************************************************************************/
-void _Jv_java_lang_Runtime_init(void)
-{
-       utf *u;
-       u = utf_new_char("java/lang/Runtime");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
-
-
-/*
- * Class:     java/lang/Runtime
- * Method:    exitInternal
- * Signature: (I)V
- */
-JNIEXPORT void JNICALL Java_java_lang_Runtime_exitInternal(JNIEnv *env, java_lang_Runtime *this, int32_t status)
-{
-       vm_shutdown(status);
-}
-
-
-/*
- * Class:     java/lang/Runtime
- * Method:    freeMemory
- * Signature: ()J
- */
-JNIEXPORT int64_t JNICALL Java_java_lang_Runtime_freeMemory(JNIEnv *env, java_lang_Runtime *this)
-{
-       return gc_get_free_bytes();
-}
-
-
-/*
- * Class:     java/lang/Runtime
- * Method:    totalMemory
- * Signature: ()J
- */
-JNIEXPORT int64_t JNICALL Java_java_lang_Runtime_totalMemory(JNIEnv *env, java_lang_Runtime *this)
-{
-       return gc_get_heap_size();
-}
-
-
-/*
- * Class:     java/lang/Runtime
- * Method:    gc
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_Runtime_gc(JNIEnv *env, java_lang_Runtime *this)
-{
-       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/cldc1.1/java_lang_Runtime.cpp b/src/native/vm/cldc1.1/java_lang_Runtime.cpp
new file mode 100644 (file)
index 0000000..d37eb9d
--- /dev/null
@@ -0,0 +1,135 @@
+/* src/native/vm/cldc1.1/java_lang_Runtime.cpp
+
+   Copyright (C) 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+
+#include "mm/gc.hpp"
+
+#include "native/jni.h"
+#include "native/native.h"
+
+// FIXME
+extern "C" {
+#include "native/include/java_lang_Runtime.h"
+}
+
+#include "vm/vm.hpp"
+
+#include "vmcore/utf8.h"
+
+
+/* native methods implemented by this file ************************************/
+static JNINativeMethod methods[] = {
+       { (char*) "exitInternal", (char*) "(I)V", (void*) (uintptr_t) &Java_java_lang_Runtime_exitInternal },
+       { (char*) "freeMemory",   (char*) "()J",  (void*) (uintptr_t) &Java_java_lang_Runtime_freeMemory   },
+       { (char*) "totalMemory",  (char*) "()J",  (void*) (uintptr_t) &Java_java_lang_Runtime_totalMemory  },
+       { (char*) "gc",           (char*) "()V",  (void*) (uintptr_t) &Java_java_lang_Runtime_gc           },
+};
+/* _Jv_java_lang_Runtime_init **************************************************
+   Register native functions.
+*******************************************************************************/
+// FIXME
+extern "C" {
+void _Jv_java_lang_Runtime_init(void)
+{
+       utf *u;
+       u = utf_new_char("java/lang/Runtime");
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
+}
+
+
+// Native functions are exported as C functions.
+extern "C" {
+
+/*
+ * Class:     java/lang/Runtime
+ * Method:    exitInternal
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_Runtime_exitInternal(JNIEnv *env, java_lang_Runtime *_this, int32_t status)
+{
+       vm_shutdown(status);
+}
+
+
+/*
+ * Class:     java/lang/Runtime
+ * Method:    freeMemory
+ * Signature: ()J
+ */
+JNIEXPORT int64_t JNICALL Java_java_lang_Runtime_freeMemory(JNIEnv *env, java_lang_Runtime *_this)
+{
+       return gc_get_free_bytes();
+}
+
+
+/*
+ * Class:     java/lang/Runtime
+ * Method:    totalMemory
+ * Signature: ()J
+ */
+JNIEXPORT int64_t JNICALL Java_java_lang_Runtime_totalMemory(JNIEnv *env, java_lang_Runtime *_this)
+{
+       return gc_get_heap_size();
+}
+
+
+/*
+ * Class:     java/lang/Runtime
+ * Method:    gc
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_Runtime_gc(JNIEnv *env, java_lang_Runtime *_this)
+{
+       gc_call();
+}
+
+} // extern "C"
+
+
+/*
+ * 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_String.c b/src/native/vm/cldc1.1/java_lang_String.c
deleted file mode 100644 (file)
index 0e65859..0000000
+++ /dev/null
@@ -1,284 +0,0 @@
-/* src/native/vm/cldc1.1/java_lang_String.c
-
-   Copyright (C) 2006, 2007, 2008
-   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
-   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.
-
-*/
-
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/llni.h"
-#include "native/native.h"
-
-#include "native/include/java_lang_Object.h"
-
-#include "native/include/java_lang_String.h"
-
-#include "vm/string.hpp"
-
-
-/* native methods implemented by this file ************************************/
-static JNINativeMethod methods[] = {
-       { "hashCode",    "()I",                    (void *) (ptrint) &Java_java_lang_String_hashCode        },
-       { "indexOf",     "(I)I",                   (void *) (ptrint) &Java_java_lang_String_indexOf__I      },
-       { "indexOf",     "(II)I",                  (void *) (ptrint) &Java_java_lang_String_indexOf__II     },
-       { "lastIndexOf", "(I)I",                   (void *) (ptrint) &Java_java_lang_String_lastIndexOf__I  },
-       { "lastIndexOf", "(II)I",                  (void *) (ptrint) &Java_java_lang_String_lastIndexOf__II },
-#if 0
-       { "equals",      "(Ljava/lang/Object;)Z;", (void *) (ptrint) &Java_java_lang_String_equals          },
-#endif
-       { "intern",      "()Ljava/lang/String;",   (void *) (ptrint) &Java_java_lang_String_intern          },
-};
-
-
-/* _Jv_java_lang_String_init ***************************************************
-   Register native functions.
-*******************************************************************************/
-void _Jv_java_lang_String_init(void)
-{
-       utf *u;
-       u = utf_new_char("java/lang/String");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
-
-
-/*
- * Class:     java/lang/String
- * Method:    hashCode
- * Signature: ()I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_String_hashCode(JNIEnv *env, java_lang_String *this)
-{
-       java_handle_chararray_t *value;
-       int32_t                 offset;
-       int32_t                 count;
-       s4                              hash;
-       s4                              i;
-
-       /* get values from Java object */
-       
-       LLNI_field_get_val(this, offset, offset);
-       LLNI_field_get_val(this, count, count);
-       LLNI_field_get_ref(this, value, value);
-
-       hash = 0;
-
-       for (i = 0; i < count; i++) {
-               hash = (31 * hash) + LLNI_array_direct(value, 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_handle_chararray_t *value;
-       int32_t                 offset;
-       int32_t                 count;
-       s4                              i;
-
-       /* get values from Java object */
-
-       LLNI_field_get_val(this, offset, offset);
-       LLNI_field_get_val(this, count, count);
-       LLNI_field_get_ref(this, value, value);
-
-       for (i = 0; i < count; i++) {
-               if (LLNI_array_direct(value, offset + i) == ch) {
-                       return i;
-               }
-       }
-
-       return -1;
-}
-
-
-/*
- * Class:     java/lang/String
- * Method:    indexOf
- * Signature: (II)I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_String_indexOf__II(JNIEnv *env, java_lang_String *this, s4 ch, s4 fromIndex)
-{
-       java_handle_chararray_t *value;
-       int32_t                 offset;
-       int32_t                 count;
-       s4                              i;
-
-       /* get values from Java object */
-
-       LLNI_field_get_val(this, offset, offset);
-       LLNI_field_get_val(this, count, count);
-       LLNI_field_get_ref(this, value, value);
-
-       if (fromIndex < 0) {
-               fromIndex = 0;
-       }
-       else if (fromIndex >= count) {
-               /* Note: fromIndex might be near -1>>>1. */
-               return -1;
-       }
-
-       for (i = fromIndex ; i < count ; i++) {
-               if (LLNI_array_direct(value, offset + i) == ch) {
-                       return i;
-               }
-       }
-
-       return -1;
-}
-
-
-/*
- * Class:     java/lang/String
- * Method:    lastIndexOf
- * Signature: (I)I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_String_lastIndexOf__I(JNIEnv *env, java_lang_String *this, s4 ch)
-{
-       int32_t count;
-       
-       LLNI_field_get_val(this, count, count);
-       
-       return Java_java_lang_String_lastIndexOf__II(env, this, ch, count - 1);
-}
-
-
-/*
- * Class:     java/lang/String
- * Method:    lastIndexOf
- * Signature: (II)I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_String_lastIndexOf__II(JNIEnv *env, java_lang_String *this, s4 ch, s4 fromIndex)
-{
-       java_handle_chararray_t *value;
-       int32_t                 offset;
-       int32_t                 count;
-       s4                              start;
-       s4                              i;
-
-       /* get values from Java object */
-
-       LLNI_field_get_val(this, offset, offset);
-       LLNI_field_get_val(this, count, count);
-       LLNI_field_get_ref(this, value, value);
-
-       start = ((fromIndex >= count) ? count - 1 : fromIndex);
-
-       for (i = start; i >= 0; i--) {
-               if (LLNI_array_direct(value, offset + i) == ch) {
-                       return i;
-               }
-       }
-
-       return -1;
-}
-
-
-#if 0
-/*
- * Class:     java/lang/String
- * Method:    equals
- * Signature: (Ljava/lang/Object;)Z;
- */
-JNIEXPORT s4 JNICALL Java_java_lang_String_equals(JNIEnv *env, java_lang_String* this, java_lang_Object *o)
-{
-       java_lang_String*               s;
-       java_handle_chararray_t *value;
-       int32_t                 offset;
-       int32_t                 count;
-       java_handle_chararray_t *dvalue;
-       int32_t                 doffset;
-       int32_t                 dcount;
-       classinfo                       *c;
-       
-       LLNI_field_get_val(this, offset, offset);
-       LLNI_field_get_val(this, count, count);
-       LLNI_field_get_ref(this, value, value);
-       LLNI_class_get(o, c);
-
-       /* TODO: is this the correct implementation for short-circuiting on object identity? */
-       if ((java_lang_Object*)this == o)
-               return 1;
-       
-       if (c != class_java_lang_String) 
-               return 0;
-
-       s = (java_lang_String *) o;
-       LLNI_field_get_val(this, offset, doffset);
-       LLNI_field_get_val(this, count, dcount);
-       LLNI_field_get_ref(this, value, dvalue);
-
-       if (count != dcount)
-               return 0;
-
-       return ( 0 == memcmp((void*)(LLNI_array_direct(value, offset)),
-                                                (void*)(LLNI_array_direct(dvalue, doffset),
-                                                count) );
-
-}
-#endif
-
-
-/*
- * Class:     java/lang/String
- * Method:    intern
- * Signature: ()Ljava/lang/String;
- */
-JNIEXPORT java_lang_String* JNICALL Java_java_lang_String_intern(JNIEnv *env, java_lang_String *this)
-{
-       if (this == NULL)
-               return NULL;
-
-       return (java_lang_String *) javastring_intern((java_handle_t *) this);
-}
-
-
-/*
- * 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:
- */
diff --git a/src/native/vm/cldc1.1/java_lang_String.cpp b/src/native/vm/cldc1.1/java_lang_String.cpp
new file mode 100644 (file)
index 0000000..94ee1a4
--- /dev/null
@@ -0,0 +1,294 @@
+/* src/native/vm/cldc1.1/java_lang_String.cpp
+
+   Copyright (C) 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "native/jni.h"
+#include "native/llni.h"
+#include "native/native.h"
+
+#include "native/include/java_lang_Object.h"
+
+// FIXME
+extern "C" {
+#include "native/include/java_lang_String.h"
+}
+
+#include "vm/string.hpp"
+
+
+/* native methods implemented by this file ************************************/
+static JNINativeMethod methods[] = {
+       { (char*) "hashCode",    (char*) "()I",                    (void*) (uintptr_t) &Java_java_lang_String_hashCode        },
+       { (char*) "indexOf",     (char*) "(I)I",                   (void*) (uintptr_t) &Java_java_lang_String_indexOf__I      },
+       { (char*) "indexOf",     (char*) "(II)I",                  (void*) (uintptr_t) &Java_java_lang_String_indexOf__II     },
+       { (char*) "lastIndexOf", (char*) "(I)I",                   (void*) (uintptr_t) &Java_java_lang_String_lastIndexOf__I  },
+       { (char*) "lastIndexOf", (char*) "(II)I",                  (void*) (uintptr_t) &Java_java_lang_String_lastIndexOf__II },
+#if 0
+       { (char*) "equals",      (char*) "(Ljava/lang/Object;)Z;", (void*) (uintptr_t) &Java_java_lang_String_equals          },
+#endif
+       { (char*) "intern",      (char*) "()Ljava/lang/String;",   (void*) (uintptr_t) &Java_java_lang_String_intern          },
+};
+
+
+/* _Jv_java_lang_String_init ***************************************************
+   Register native functions.
+*******************************************************************************/
+// FIXME
+extern "C" {
+void _Jv_java_lang_String_init(void)
+{
+       utf *u;
+       u = utf_new_char("java/lang/String");
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
+}
+
+
+// Native functions are exported as C functions.
+extern "C" {
+
+/*
+ * Class:     java/lang/String
+ * Method:    hashCode
+ * Signature: ()I
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_String_hashCode(JNIEnv *env, java_lang_String *_this)
+{
+       java_handle_chararray_t *value;
+       int32_t                 offset;
+       int32_t                 count;
+       s4                              hash;
+       s4                              i;
+
+       /* get values from Java object */
+       
+       LLNI_field_get_val(_this, offset, offset);
+       LLNI_field_get_val(_this, count, count);
+       LLNI_field_get_ref(_this, value, value);
+
+       hash = 0;
+
+       for (i = 0; i < count; i++) {
+               hash = (31 * hash) + LLNI_array_direct(value, 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_handle_chararray_t *value;
+       int32_t                 offset;
+       int32_t                 count;
+       s4                              i;
+
+       /* get values from Java object */
+
+       LLNI_field_get_val(_this, offset, offset);
+       LLNI_field_get_val(_this, count, count);
+       LLNI_field_get_ref(_this, value, value);
+
+       for (i = 0; i < count; i++) {
+               if (LLNI_array_direct(value, offset + i) == ch) {
+                       return i;
+               }
+       }
+
+       return -1;
+}
+
+
+/*
+ * Class:     java/lang/String
+ * Method:    indexOf
+ * Signature: (II)I
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_String_indexOf__II(JNIEnv *env, java_lang_String *_this, s4 ch, s4 fromIndex)
+{
+       java_handle_chararray_t *value;
+       int32_t                 offset;
+       int32_t                 count;
+       s4                              i;
+
+       /* get values from Java object */
+
+       LLNI_field_get_val(_this, offset, offset);
+       LLNI_field_get_val(_this, count, count);
+       LLNI_field_get_ref(_this, value, value);
+
+       if (fromIndex < 0) {
+               fromIndex = 0;
+       }
+       else if (fromIndex >= count) {
+               /* Note: fromIndex might be near -1>>>1. */
+               return -1;
+       }
+
+       for (i = fromIndex ; i < count ; i++) {
+               if (LLNI_array_direct(value, offset + i) == ch) {
+                       return i;
+               }
+       }
+
+       return -1;
+}
+
+
+/*
+ * Class:     java/lang/String
+ * Method:    lastIndexOf
+ * Signature: (I)I
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_String_lastIndexOf__I(JNIEnv *env, java_lang_String *_this, s4 ch)
+{
+       int32_t count;
+       
+       LLNI_field_get_val(_this, count, count);
+       
+       return Java_java_lang_String_lastIndexOf__II(env, _this, ch, count - 1);
+}
+
+
+/*
+ * Class:     java/lang/String
+ * Method:    lastIndexOf
+ * Signature: (II)I
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_String_lastIndexOf__II(JNIEnv *env, java_lang_String *_this, s4 ch, s4 fromIndex)
+{
+       java_handle_chararray_t *value;
+       int32_t                 offset;
+       int32_t                 count;
+       s4                              start;
+       s4                              i;
+
+       /* get values from Java object */
+
+       LLNI_field_get_val(_this, offset, offset);
+       LLNI_field_get_val(_this, count, count);
+       LLNI_field_get_ref(_this, value, value);
+
+       start = ((fromIndex >= count) ? count - 1 : fromIndex);
+
+       for (i = start; i >= 0; i--) {
+               if (LLNI_array_direct(value, offset + i) == ch) {
+                       return i;
+               }
+       }
+
+       return -1;
+}
+
+
+#if 0
+/*
+ * Class:     java/lang/String
+ * Method:    equals
+ * Signature: (Ljava/lang/Object;)Z;
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_String_equals(JNIEnv *env, java_lang_String* _this, java_lang_Object *o)
+{
+       java_lang_String*               s;
+       java_handle_chararray_t *value;
+       int32_t                 offset;
+       int32_t                 count;
+       java_handle_chararray_t *dvalue;
+       int32_t                 doffset;
+       int32_t                 dcount;
+       classinfo                       *c;
+       
+       LLNI_field_get_val(_this, offset, offset);
+       LLNI_field_get_val(_this, count, count);
+       LLNI_field_get_ref(_this, value, value);
+       LLNI_class_get(o, c);
+
+       /* TODO: is this the correct implementation for short-circuiting on object identity? */
+       if ((java_lang_Object*)_this == o)
+               return 1;
+       
+       if (c != class_java_lang_String) 
+               return 0;
+
+       s = (java_lang_String *) o;
+       LLNI_field_get_val(_this, offset, doffset);
+       LLNI_field_get_val(_this, count, dcount);
+       LLNI_field_get_ref(_this, value, dvalue);
+
+       if (count != dcount)
+               return 0;
+
+       return ( 0 == memcmp((void*)(LLNI_array_direct(value, offset)),
+                                                (void*)(LLNI_array_direct(dvalue, doffset),
+                                                count) );
+
+}
+#endif
+
+
+/*
+ * Class:     java/lang/String
+ * Method:    intern
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT java_lang_String* JNICALL Java_java_lang_String_intern(JNIEnv *env, java_lang_String *_this)
+{
+       if (_this == NULL)
+               return NULL;
+
+       return (java_lang_String *) javastring_intern((java_handle_t *) _this);
+}
+
+} // extern "C"
+
+
+/*
+ * 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:
+ */
diff --git a/src/native/vm/cldc1.1/java_lang_System.c b/src/native/vm/cldc1.1/java_lang_System.c
deleted file mode 100644 (file)
index 1e00f9b..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/* src/native/vm/cldc1.1/java_lang_System.c
-
-   Copyright (C) 2006, 2007, 2008
-   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
-   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.
-
-*/
-
-
-#include "config.h"
-
-#include <stdlib.h>
-
-#include "vm/types.h"
-
-#include "mm/memory.h"
-
-#include "native/jni.h"
-#include "native/native.h"
-
-#include "native/include/java_lang_Object.h"
-#include "native/include/java_lang_String.h"
-
-#include "native/include/java_lang_System.h"
-
-#include "vm/builtin.h"
-#include "vm/properties.h"
-#include "vm/string.hpp"
-
-
-/* native methods implemented by this file ************************************/
-static JNINativeMethod methods[] = {
-       { "arraycopy",    "(Ljava/lang/Object;ILjava/lang/Object;II)V", (void *) (ptrint) &Java_java_lang_System_arraycopy    },
-       { "getProperty0", "(Ljava/lang/String;)Ljava/lang/String;",     (void *) (ptrint) &Java_java_lang_System_getProperty0 },
-};
-
-
-/* _Jv_java_lang_System_init ***************************************************
-   Register native functions.
-*******************************************************************************/
-void _Jv_java_lang_System_init(void)
-{
-       utf *u;
-       u = utf_new_char("java/lang/System");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
-
-
-/*
- * Class:     java/lang/System
- * Method:    arraycopy
- * Signature: (Ljava/lang/Object;ILjava/lang/Object;II)V
- */
-JNIEXPORT void JNICALL Java_java_lang_System_arraycopy(JNIEnv *env, jclass clazz, java_lang_Object *src, s4 srcStart, java_lang_Object *dest, s4 destStart, s4 len)
-{
-       builtin_arraycopy((java_handle_t *) src, srcStart,
-                                         (java_handle_t *) dest, destStart, len);
-}
-
-
-/*
- * Class:     java/lang/System
- * Method:    getProperty0
- * Signature: (Ljava/lang/String;)Ljava/lang/String;
- */
-
-JNIEXPORT java_lang_String* JNICALL Java_java_lang_System_getProperty0(JNIEnv *env, jclass clazz, java_lang_String *s)
-{
-       java_handle_t *so;
-       char*          key;
-       char*          value;
-       java_handle_t *result;
-
-       so = (java_handle_t *) s;
-
-       /* build an ASCII string out of the java/lang/String passed */
-
-       key = javastring_tochar(so);
-
-       /* get the property from the internal table */
-
-       value = properties_get(key);
-
-       /* release the memory allocated in javastring_tochar */
-
-       MFREE(key, char, 0);
-
-       if (value == NULL)
-               return NULL;
-
-       result = javastring_new_from_ascii(value);
-
-       return (java_lang_String *) 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:
- */
diff --git a/src/native/vm/cldc1.1/java_lang_System.cpp b/src/native/vm/cldc1.1/java_lang_System.cpp
new file mode 100644 (file)
index 0000000..cb17b72
--- /dev/null
@@ -0,0 +1,140 @@
+/* src/native/vm/cldc1.1/java_lang_System.cpp
+
+   Copyright (C) 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "mm/memory.h"
+
+#include "native/jni.h"
+#include "native/native.h"
+
+#include "native/include/java_lang_Object.h"
+#include "native/include/java_lang_String.h"
+
+// FIXME
+extern "C" {
+#include "native/include/java_lang_System.h"
+}
+
+#include "vm/builtin.h"
+#include "vm/properties.h"
+#include "vm/string.hpp"
+
+
+/* native methods implemented by this file ************************************/
+static JNINativeMethod methods[] = {
+       { (char*) "arraycopy",    (char*) "(Ljava/lang/Object;ILjava/lang/Object;II)V", (void*) (uintptr_t) &Java_java_lang_System_arraycopy    },
+       { (char*) "getProperty0", (char*) "(Ljava/lang/String;)Ljava/lang/String;",     (void*) (uintptr_t) &Java_java_lang_System_getProperty0 },
+};
+
+
+/* _Jv_java_lang_System_init ***************************************************
+   Register native functions.
+*******************************************************************************/
+// FIXME
+extern "C" {
+void _Jv_java_lang_System_init(void)
+{
+       utf *u;
+       u = utf_new_char("java/lang/System");
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
+}
+
+
+// Native functions are exported as C functions.
+extern "C" {
+
+/*
+ * Class:     java/lang/System
+ * Method:    arraycopy
+ * Signature: (Ljava/lang/Object;ILjava/lang/Object;II)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_System_arraycopy(JNIEnv *env, jclass clazz, java_lang_Object *src, s4 srcStart, java_lang_Object *dest, s4 destStart, s4 len)
+{
+       builtin_arraycopy((java_handle_t *) src, srcStart,
+                                         (java_handle_t *) dest, destStart, len);
+}
+
+
+/*
+ * Class:     java/lang/System
+ * Method:    getProperty0
+ * Signature: (Ljava/lang/String;)Ljava/lang/String;
+ */
+
+JNIEXPORT java_lang_String* JNICALL Java_java_lang_System_getProperty0(JNIEnv *env, jclass clazz, java_lang_String *s)
+{
+       java_handle_t *so;
+       char*          key;
+       const char*    value;
+       java_handle_t *result;
+
+       so = (java_handle_t *) s;
+
+       /* build an ASCII string out of the java/lang/String passed */
+
+       key = javastring_tochar(so);
+
+       /* get the property from the internal table */
+
+       value = properties_get(key);
+
+       /* release the memory allocated in javastring_tochar */
+
+       MFREE(key, char, 0);
+
+       if (value == NULL)
+               return NULL;
+
+       result = javastring_new_from_ascii(value);
+
+       return (java_lang_String *) result;
+}
+
+} // extern "C"
+
+
+/*
+ * 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:
+ */
diff --git a/src/native/vm/cldc1.1/java_lang_Thread.c b/src/native/vm/cldc1.1/java_lang_Thread.c
deleted file mode 100644 (file)
index 4743b8b..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-/* src/native/vm/cldc1.1/java_lang_Thread.c
-
-   Copyright (C) 2006, 2007, 2008
-   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
-   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.
-
-*/
-
-
-#include "config.h"
-
-#include <stdint.h>
-
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/native.h"
-
-#include "native/include/java_lang_Thread.h"
-
-#include "threads/thread.hpp"
-
-#include "toolbox/logging.h"
-
-#include "vm/builtin.h"
-
-
-/* native methods implemented by this file ************************************/
-static JNINativeMethod methods[] = {
-       { "currentThread", "()Ljava/lang/Thread;", (void *) (ptrint) &Java_java_lang_Thread_currentThread },
-       { "setPriority0",  "(II)V",                (void *) (ptrint) &Java_java_lang_Thread_setPriority0  },
-       { "sleep",         "(J)V",                 (void *) (ptrint) &Java_java_lang_Thread_sleep         },
-       { "start0",        "()V",                  (void *) (ptrint) &Java_java_lang_Thread_start0        },
-       { "isAlive",       "()Z",                  (void *) (ptrint) &Java_java_lang_Thread_isAlive       },
-#if 0
-       { "activeCount",   "()I",                  (void *) (ptrint) &Java_java_lang_Thread_activeCount   },
-       { "setPriority0",  "(II)V",                (void *) (ptrint) &Java_java_lang_Thread_setPriority0  },
-       { "interrupt0",    "()V",                  (void *) (ptrint) &Java_java_lang_Thread_interrupt0    },
-       { "internalExit",  "()V",                  (void *) (ptrint) &Java_java_lang_Thread_internalExit  },
-#endif
-       { "yield",         "()V",                  (void *) (ptrint) &Java_java_lang_Thread_yield         },
-};
-
-
-/* _Jv_java_lang_Thread_init ***************************************************
-   Register native functions.
-*******************************************************************************/
-void _Jv_java_lang_Thread_init(void)
-{
-       utf *u;
-       u = utf_new_char("java/lang/Thread");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
-
-
-/*
- * Class:     java/lang/Thread
- * Method:    currentThread
- * Signature: ()Ljava/lang/Thread;
- */
-JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_Thread_currentThread(JNIEnv *env, jclass clazz)
-{
-       java_lang_Thread *to;
-
-       to = (java_lang_Thread *) thread_get_current_object();
-
-       return to;
-}
-
-
-/*
- * Class:     java/lang/Thread
- * Method:    setPriority0
- * Signature: (II)V
- */
-JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, java_lang_Thread *this, s4 oldPriority, s4 newPriority)
-{
-#if defined(ENABLE_THREADS)
-       threadobject *t;
-
-       t = (threadobject *) this->vm_thread;
-
-       /* The threadobject is null when a thread is created in Java. The
-          priority is set later during startup. */
-
-       if (t == NULL)
-               return;
-
-       threads_set_thread_priority(t->tid, newPriority);
-#endif
-}
-
-
-/*
- * Class:     java/lang/Thread
- * Method:    sleep
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_java_lang_Thread_sleep(JNIEnv *env, jclass clazz, s8 millis)
-{
-#if defined(ENABLE_THREADS)
-       threads_sleep(millis, 0);
-#endif
-}
-
-
-/*
- * Class:     java/lang/Thread
- * Method:    start0
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_Thread_start0(JNIEnv *env, java_lang_Thread *this)
-{
-#if defined(ENABLE_THREADS)
-       threads_thread_start((java_handle_t *) this);
-#endif
-}
-
-
-/*
- * Class:     java/lang/Thread
- * Method:    isAlive
- * Signature: ()Z
- */
-JNIEXPORT int32_t JNICALL Java_java_lang_Thread_isAlive(JNIEnv *env, java_lang_Thread *this)
-{
-#if defined(ENABLE_THREADS)
-       threadobject *t;
-       bool          result;
-
-       t = (threadobject *) this->vm_thread;
-
-       if (t == NULL)
-               return 0;
-
-       result = threads_thread_is_alive(t);
-
-       return result;
-#else
-       /* If threads are disabled, the only thread running is alive. */
-
-       return 1;
-#endif
-}
-
-
-#if 0
-/*
- * Class:     java/lang/Thread
- * Method:    activeCount
- * Signature: ()I
- */
-JNIEXPORT s4 JNICALL Java_java_lang_Thread_activeCount(JNIEnv *env, jclass clazz)
-{
-}
-
-
-/*
- * Class:     java/lang/Thread
- * Method:    setPriority0
- * Signature: (II)V
- */
-JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, struct java_lang_Thread* this, s4 par1, s4 par2)
-{
-}
-
-
-/*
- * Class:     java/lang/Thread
- * Method:    interrupt0
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_Thread_interrupt0(JNIEnv *env, struct java_lang_Thread* this)
-{
-}
-
-
-/*
- * Class:     java/lang/Thread
- * Method:    internalExit
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_Thread_internalExit(JNIEnv *env, struct java_lang_Thread* this)
-{
-}
-#endif
-
-
-/*
- * Class:     java/lang/Thread
- * Method:    yield
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_Thread_yield(JNIEnv *env, jclass clazz)
-{
-#if defined(ENABLE_THREADS)
-       threads_yield();
-#endif
-}
-
-
-/*
- * 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_Thread.cpp b/src/native/vm/cldc1.1/java_lang_Thread.cpp
new file mode 100644 (file)
index 0000000..4c64b18
--- /dev/null
@@ -0,0 +1,245 @@
+/* src/native/vm/cldc1.1/java_lang_Thread.cpp
+
+   Copyright (C) 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+
+#include "native/jni.h"
+#include "native/native.h"
+
+// FIXME
+extern "C" {
+#include "native/include/java_lang_Thread.h"
+}
+
+#include "threads/thread.hpp"
+
+#include "toolbox/logging.h"
+
+#include "vm/builtin.h"
+
+
+/* native methods implemented by this file ************************************/
+static JNINativeMethod methods[] = {
+       { (char*) "currentThread", (char*) "()Ljava/lang/Thread;", (void*) (uintptr_t) &Java_java_lang_Thread_currentThread },
+       { (char*) "setPriority0",  (char*) "(II)V",                (void*) (uintptr_t) &Java_java_lang_Thread_setPriority0  },
+       { (char*) "sleep",         (char*) "(J)V",                 (void*) (uintptr_t) &Java_java_lang_Thread_sleep         },
+       { (char*) "start0",        (char*) "()V",                  (void*) (uintptr_t) &Java_java_lang_Thread_start0        },
+       { (char*) "isAlive",       (char*) "()Z",                  (void*) (uintptr_t) &Java_java_lang_Thread_isAlive       },
+#if 0
+       { (char*) "activeCount",   (char*) "()I",                  (void*) (uintptr_t) &Java_java_lang_Thread_activeCount   },
+       { (char*) "setPriority0",  (char*) "(II)V",                (void*) (uintptr_t) &Java_java_lang_Thread_setPriority0  },
+       { (char*) "interrupt0",    (char*) "()V",                  (void*) (uintptr_t) &Java_java_lang_Thread_interrupt0    },
+       { (char*) "internalExit",  (char*) "()V",                  (void*) (uintptr_t) &Java_java_lang_Thread_internalExit  },
+#endif
+       { (char*) "yield",         (char*) "()V",                  (void*) (uintptr_t) &Java_java_lang_Thread_yield         },
+};
+
+
+/* _Jv_java_lang_Thread_init ***************************************************
+   Register native functions.
+*******************************************************************************/
+// FIXME
+extern "C" {
+void _Jv_java_lang_Thread_init(void)
+{
+       utf *u;
+       u = utf_new_char("java/lang/Thread");
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
+}
+
+
+// Native functions are exported as C functions.
+extern "C" {
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    currentThread
+ * Signature: ()Ljava/lang/Thread;
+ */
+JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_Thread_currentThread(JNIEnv *env, jclass clazz)
+{
+       java_lang_Thread *to;
+
+       to = (java_lang_Thread *) thread_get_current_object();
+
+       return to;
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    setPriority0
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, java_lang_Thread *_this, s4 oldPriority, s4 newPriority)
+{
+#if defined(ENABLE_THREADS)
+       threadobject *t;
+
+       t = (threadobject *) _this->vm_thread;
+
+       /* The threadobject is null when a thread is created in Java. The
+          priority is set later during startup. */
+
+       if (t == NULL)
+               return;
+
+       threads_set_thread_priority(t->tid, newPriority);
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    sleep
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_Thread_sleep(JNIEnv *env, jclass clazz, s8 millis)
+{
+#if defined(ENABLE_THREADS)
+       threads_sleep(millis, 0);
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    start0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_Thread_start0(JNIEnv *env, java_lang_Thread *_this)
+{
+#if defined(ENABLE_THREADS)
+       threads_thread_start((java_handle_t *) _this);
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    isAlive
+ * Signature: ()Z
+ */
+JNIEXPORT int32_t JNICALL Java_java_lang_Thread_isAlive(JNIEnv *env, java_lang_Thread *_this)
+{
+#if defined(ENABLE_THREADS)
+       threadobject *t;
+       bool          result;
+
+       t = (threadobject *) _this->vm_thread;
+
+       if (t == NULL)
+               return 0;
+
+       result = threads_thread_is_alive(t);
+
+       return result;
+#else
+       /* If threads are disabled, the only thread running is alive. */
+
+       return 1;
+#endif
+}
+
+
+#if 0
+/*
+ * Class:     java/lang/Thread
+ * Method:    activeCount
+ * Signature: ()I
+ */
+JNIEXPORT s4 JNICALL Java_java_lang_Thread_activeCount(JNIEnv *env, jclass clazz)
+{
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    setPriority0
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, struct java_lang_Thread* _this, s4 par1, s4 par2)
+{
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    interrupt0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_Thread_interrupt0(JNIEnv *env, struct java_lang_Thread* _this)
+{
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    internalExit
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_Thread_internalExit(JNIEnv *env, struct java_lang_Thread* _this)
+{
+}
+#endif
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    yield
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_Thread_yield(JNIEnv *env, jclass clazz)
+{
+#if defined(ENABLE_THREADS)
+       threads_yield();
+#endif
+}
+
+} // extern "C"
+
+
+/*
+ * 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_Throwable.c b/src/native/vm/cldc1.1/java_lang_Throwable.c
deleted file mode 100644 (file)
index a689d86..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/* src/native/vm/cldc1.1/java_lang_Throwable.c - java/lang/Throwable
-
-   Copyright (C) 2006, 2007, 2008
-   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
-   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.
-
-*/
-
-
-#include "config.h"
-
-#include <assert.h>
-#include <stdint.h>
-
-#include "native/jni.h"
-#include "native/llni.h"
-#include "native/native.h"
-
-#include "native/include/java_lang_Object.h"
-#include "native/include/java_lang_Throwable.h"
-
-#include "vm/exceptions.hpp"
-#include "vm/jit/stacktrace.hpp"
-
-
-/* native methods implemented by this file ************************************/
-static JNINativeMethod methods[] = {
-       { "printStackTrace",  "()V", (void *) (uintptr_t) &Java_java_lang_Throwable_printStackTrace  },
-       { "fillInStackTrace", "()V", (void *) (uintptr_t) &Java_java_lang_Throwable_fillInStackTrace },
-};
-
-
-/* _Jv_java_lang_Throwable_init ************************************************
-   Register native functions.
-*******************************************************************************/
-void _Jv_java_lang_Throwable_init(void)
-{
-       utf *u;
-       u = utf_new_char("java/lang/Throwable");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
-
-
-/*
- * Class:     java/lang/Throwable
- * Method:    printStackTrace
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_Throwable_printStackTrace(JNIEnv *env, java_lang_Throwable *this)
-{
-       java_handle_t *o;
-
-       o = (java_handle_t *) this;
-
-       exceptions_print_exception(o);
-       stacktrace_print_exception(o);
-}
-
-
-/*
- * Class:     java/lang/Throwable
- * Method:    fillInStackTrace
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_java_lang_Throwable_fillInStackTrace(JNIEnv *env, java_lang_Throwable *this)
-{
-       java_handle_bytearray_t *ba;
-
-       ba = stacktrace_get_current();
-
-       if (ba == NULL)
-               return;
-
-       LLNI_field_set_ref(this, backtrace, (java_lang_Object *) ba);
-}
-
-
-/*
- * 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:
- */
diff --git a/src/native/vm/cldc1.1/java_lang_Throwable.cpp b/src/native/vm/cldc1.1/java_lang_Throwable.cpp
new file mode 100644 (file)
index 0000000..905ff2d
--- /dev/null
@@ -0,0 +1,123 @@
+/* src/native/vm/cldc1.1/java_lang_Throwable.cpp
+
+   Copyright (C) 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+*/
+
+
+#include "config.h"
+
+#include <assert.h>
+#include <stdint.h>
+
+#include "native/jni.h"
+#include "native/llni.h"
+#include "native/native.h"
+
+#include "native/include/java_lang_Object.h"
+
+// FIXME
+extern "C" {
+#include "native/include/java_lang_Throwable.h"
+}
+
+#include "vm/exceptions.hpp"
+#include "vm/jit/stacktrace.hpp"
+
+
+/* native methods implemented by this file ************************************/
+static JNINativeMethod methods[] = {
+       { (char*) "printStackTrace",  (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Throwable_printStackTrace  },
+       { (char*) "fillInStackTrace", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Throwable_fillInStackTrace },
+};
+
+
+/* _Jv_java_lang_Throwable_init ************************************************
+   Register native functions.
+*******************************************************************************/
+// FIXME
+extern "C" {
+void _Jv_java_lang_Throwable_init(void)
+{
+       utf *u;
+       u = utf_new_char("java/lang/Throwable");
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
+}
+
+
+// Native functions are exported as C functions.
+extern "C" {
+
+/*
+ * Class:     java/lang/Throwable
+ * Method:    printStackTrace
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_Throwable_printStackTrace(JNIEnv *env, java_lang_Throwable *_this)
+{
+       java_handle_t *o;
+
+       o = (java_handle_t *) _this;
+
+       exceptions_print_exception(o);
+       stacktrace_print_exception(o);
+}
+
+
+/*
+ * Class:     java/lang/Throwable
+ * Method:    fillInStackTrace
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_java_lang_Throwable_fillInStackTrace(JNIEnv *env, java_lang_Throwable *_this)
+{
+       java_handle_bytearray_t *ba;
+
+       ba = stacktrace_get_current();
+
+       if (ba == NULL)
+               return;
+
+       LLNI_field_set_ref(_this, backtrace, (java_lang_Object *) ba);
+}
+
+} // extern "C"
+
+
+/*
+ * 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:
+ */