* src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.c
authortwisti <none@none>
Sat, 18 Aug 2007 13:04:59 +0000 (13:04 +0000)
committertwisti <none@none>
Sat, 18 Aug 2007 13:04:59 +0000 (13:04 +0000)
(zip_read_resource, file_read_resource,
Java_com_sun_cldc_io_ResourceInputStream_open,
Java_com_sun_cldc_io_ResourceInputStream_bytesRemain,
Java_com_sun_cldc_io_ResourceInputStream_readByte,
Java_com_sun_cldc_io_ResourceInputStream_readBytes,
Java_com_sun_cldc_io_ResourceInputStream_clone): Used LLNI macros,
implemented missing methods

* src/native/vm/cldc1.1/java_lang_Object.c (native/llni.h): Added
* src/native/vm/cldc1.1/java_lang_Class.c: Likewise

* src/native/vm/cldc1.1/java_lang_String.c
(Java_java_lang_String_hashCode,
Java_java_lang_String_indexOf__I,
Java_java_lang_String_indexOf__II,
Java_java_lang_String_lastIndexOf__I
Java_java_lang_String_lastIndexOf__II,
Java_java_lang_String_equals,
Java_java_lang_String_intern): Used LLNI macros
* src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.c
(Java_com_sun_cldc_io_j2me_socket_Protocol_open0,
Java_com_sun_cldc_io_j2me_socket_Protocol_readBuf,
Java_com_sun_cldc_io_j2me_socket_Protocol_writeBuf): Likewise

* src/native/vm/cldc1.1/java_lang_System.c
(Java_java_lang_System_arraycopy): Replaced java_arrayheader by
java_handle_t.

* src/vmcore/zip.c: Moved LFH struct to zip.h.
* src/vmcore/zip.h: Likewise.

* src/lib/cldc1.1/com/sun/cldchi/jvm/FileDescriptor.java: New file.

* src/lib/Makefile.am: Changed to build vm.zip for cldc1.1.
* src/native/include/Makefile.am: Likewise.
* src/Makefile.am: Likewise.

12 files changed:
src/Makefile.am
src/lib/Makefile.am
src/lib/cldc1.1/com/sun/cldchi/jvm/FileDescriptor.java [new file with mode: 0644]
src/native/include/Makefile.am
src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.c
src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.c
src/native/vm/cldc1.1/java_lang_Class.c
src/native/vm/cldc1.1/java_lang_Object.c
src/native/vm/cldc1.1/java_lang_String.c
src/native/vm/cldc1.1/java_lang_System.c
src/vmcore/zip.c
src/vmcore/zip.h

index 1681eddf5b875405bdb6538e11391e928c126c52..4d625f0887756c826d6f746706d4020e1e1d5d81 100644 (file)
@@ -22,7 +22,7 @@
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 ## 02110-1301, USA.
 ##
-## $Id: Makefile.am 7596 2007-03-28 21:05:53Z twisti $
+## $Id: Makefile.am 8347 2007-08-18 13:04:59Z twisti $
 
 ## Process this file with automake to produce Makefile.in
 
@@ -39,11 +39,6 @@ DIST_SUBDIRS = \
        vm \
        vmcore
 
-if WITH_CLASSPATH_GNU
-VM_DIR = \
-       lib
-endif
-
 if ENABLE_THREADS
 THREADS_DIR = \
        threads
@@ -60,7 +55,7 @@ SUBDIRS = \
        toolbox \
        vmcore \
        $(CACAOH_DIR) \
-       $(VM_DIR) \
+       lib \
        native \
        fdlibm \
        mm \
index af5834f9849140db0b0b9e489c48dcbc5ee51637..7d88c3c976b715fa63f7b254994ef6df4ff2a918 100644 (file)
@@ -22,7 +22,7 @@
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 ## 02110-1301, USA.
 ##
-## $Id: Makefile.am 8262 2007-08-06 12:44:01Z panzi $
+## $Id: Makefile.am 8347 2007-08-18 13:04:59Z twisti $
 
 ## Process this file with automake to produce Makefile.in
 
@@ -31,6 +31,7 @@ EXTRA_DIST = \
 
 CLEANFILES = vm.zip
 
+if WITH_CLASSPATH_GNU
 VM_JAVA_FILES = \
        $(top_srcdir)/src/lib/gnu/gnu/classpath/VMStackWalker.java \
        $(top_srcdir)/src/lib/gnu/gnu/classpath/VMSystemProperties.java \
@@ -61,7 +62,6 @@ VM_CLASS_FILES = \
        classes/java/security/VMAccessController.class \
        classes/sun/misc/Unsafe.class
 
-if WITH_CLASSPATH_GNU
 if ENABLE_ANNOTATIONS
 VM_JAVA_FILES += \
        $(top_srcdir)/src/lib/gnu/sun/reflect/annotation/TypeNotPresentExceptionProxy.java \
@@ -77,12 +77,29 @@ VM_CLASS_FILES += \
        classes/sun/reflect/annotation/AnnotationType.class \
        classes/sun/reflect/annotation/AnnotationParser.class
 endif
+
+if ENABLE_ZLIB
+pkgdata_DATA = vm.zip
+else
+pkgdata_DATA = nozip
+endif
 endif
 
+if WITH_CLASSPATH_CLDC1_1
+VM_JAVA_FILES = \
+       $(top_srcdir)/src/lib/cldc1.1/com/sun/cldchi/jvm/FileDescriptor.java
+
+VM_CLASS_FILES = \
+       classes/com/sun/cldchi/jvm/FileDescriptor.class
 
 if ENABLE_ZLIB
 pkgdata_DATA = vm.zip
+else
+pkgdata_DATA = nozip
+endif
+endif
 
+if ENABLE_ZLIB
 VM_ZIP = ../vm.zip
 
 vm.zip: $(VM_JAVA_FILES)
@@ -94,11 +111,9 @@ vm.zip: $(VM_JAVA_FILES)
            cd classes && $(JAR) cvf $(VM_ZIP) .; \
        fi
 else
-pkgdata_DATA = nozip
-
 nozip: $(VM_JAVA_FILES)
        $(mkdir_p) classes
-       $(JAVAC) -d classes $(VM_JAVA_FILES)
+       $(JAVAC) -source 1.5 -target 1.5 -d classes $(VM_JAVA_FILES)
 endif
 
 clean-local:
diff --git a/src/lib/cldc1.1/com/sun/cldchi/jvm/FileDescriptor.java b/src/lib/cldc1.1/com/sun/cldchi/jvm/FileDescriptor.java
new file mode 100644 (file)
index 0000000..42aeb40
--- /dev/null
@@ -0,0 +1,33 @@
+/* src/lib/com/sun/cldchi/jvm/FileDescriptor.java
+
+   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.
+
+*/
+
+package com.sun.cldchi.jvm;
+
+class FileDescriptor {
+    long pointer;
+    int position;
+    int length;
+}
index ab712873cb983a204aea636ee9a08236fdc146f6..a3f492268ceb48a9d9a6fce359a77a81bfba969f 100644 (file)
@@ -22,7 +22,7 @@
 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 ## 02110-1301, USA.
 ##
-## $Id: Makefile.am 8249 2007-07-31 12:59:03Z panzi $
+## $Id: Makefile.am 8347 2007-08-18 13:04:59Z twisti $
 
 ## Process this file with automake to produce Makefile.in
 
@@ -91,6 +91,7 @@ JAVAME_CLDC1_1_HEADER_FILES = \
        com_sun_cldc_io_ResourceInputStream.h \
        com_sun_cldc_io_j2me_socket_Protocol.h \
        com_sun_cldchi_io_ConsoleOutputStream.h \
+       com_sun_cldchi_jvm_FileDescriptor.h \
        com_sun_cldchi_jvm_JVM.h \
        java_lang_Math.h \
        java_lang_Runtime.h \
@@ -168,10 +169,17 @@ endif
 if WITH_CLASSPATH_GNU
 CLASSPATH = $(top_builddir)/src/lib/classes/:$(CLASSPATH_CLASSES)
 VM_ZIP = $(top_builddir)/src/lib/vm.zip
-else
+endif
+
+if WITH_CLASSPATH_SUN
 CLASSPATH = $(CLASSPATH_CLASSES)
 endif
 
+if WITH_CLASSPATH_CLDC1_1
+CLASSPATH = $(top_builddir)/src/lib/classes/:$(CLASSPATH_CLASSES)
+VM_ZIP = $(top_builddir)/src/lib/vm.zip
+endif
+
 noinst_DATA = $(DO_HEADER_FILES)
 
 $(DO_HEADER_FILES): $(CACAOH) $(VM_ZIP) $(CLASSPATH_CLASSES)
index 1bd4ae55d3f90473095ac3ec253104fb9efba08b..d38331aba46565e60b1a98fe49e134a91eb6a2d8 100644 (file)
 
 */
 
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <zlib.h>
 
 #include "config.h"
-#include "vm/types.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.h" /* REMOVE ME: temporarily */
+#include "vm/exceptions.h"
+#include "vm/stringlocal.h"
+
+#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 ********************************
@@ -62,17 +80,322 @@ void _Jv_com_sun_cldc_io_ResourceInputStream_init(void)
        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 java_lang_Object* JNICALL Java_com_sun_cldc_io_ResourceInputStream_open(JNIEnv *env, jclass clazz, java_lang_String *name)
+JNIEXPORT struct java_lang_Object* JNICALL Java_com_sun_cldc_io_ResourceInputStream_open(JNIEnv *env, jclass clazz, java_lang_String *name)
 {
-       vm_abort("Java_com_sun_cldc_io_ResourceInputStream_open: IMPLEMENT ME!");
+       
+       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;
 
-       return NULL;
 }
 
 
index 14fe27f2dd068b81d5634bfdb5e06f9ab0829117..0e6ea1dd15016bf687ff5ad4c26a600b1c2eb510 100644 (file)
@@ -40,6 +40,7 @@
 #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"
@@ -82,7 +83,7 @@ void _Jv_com_sun_cldc_io_j2me_socket_Protocol_init(void)
  * Method:    open0
  * Signature: ([BII)I
  */
-JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_open0(JNIEnv *env, jclass clazz, java_bytearray *hostname, s4 port, s4 mode)
+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;
@@ -92,7 +93,7 @@ JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_open0(JNIEnv *env
 
        /* The hostname byte-array is a NULL terminated C-string. */
 
-       name = (char *) &(hostname->data);
+       name = (char *) &(LLNI_array_data(hostname));
 
        /* get the host */
 
@@ -131,14 +132,14 @@ JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_open0(JNIEnv *env
  * Method:    readBuf
  * Signature: (I[BII)I
  */
-JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_readBuf(JNIEnv *env, jclass clazz, s4 handle, java_bytearray *b, s4 off, s4 len)
+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 = &(b->data[off]);
+       buf = &(LLNI_array_direct(b, off));
 
        /* receive from the socket */
 
@@ -191,14 +192,14 @@ JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_readByte(JNIEnv *
  * 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_bytearray* b, s4 off, s4 len) {
+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 = &(b->data[off]);
+       buf = &(LLNI_array_direct(b, off));
        
        /* send the given byte to the socket */
 
index 84aa99b4b96c4e53999cba3f8771b81247e0c42a..429436751fd8db63930d3d95d4e003c6e965b514 100644 (file)
@@ -31,6 +31,7 @@
 #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 */
index bcc1d8373031b411426fbfd1c7ea4c79989afea5..8e3bd162e179d064897aa27beca75cda08cb1aee 100644 (file)
@@ -34,6 +34,7 @@
 #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 */
index 7d2dc5353746c3a03e8c5542528d8f4d2496406b..feeafcf8b018656d387861dea974e19d84b63d3d 100644 (file)
@@ -35,6 +35,7 @@
 #include "vm/types.h"
 
 #include "native/jni.h"
+#include "native/llni.h"
 #include "native/native.h"
 
 #include "native/include/java_lang_Object.h"
@@ -82,22 +83,22 @@ void _Jv_java_lang_String_init(void)
  */
 JNIEXPORT s4 JNICALL Java_java_lang_String_hashCode(JNIEnv *env, java_lang_String *this)
 {
-       java_chararray *value;
-       s4              offset;
-       s4              count;
-       s4              hash;
-       s4              i;
+       java_handle_chararray_t *value;
+       int32_t                 offset;
+       int32_t                 count;
+       s4                              hash;
+       s4                              i;
 
        /* get values from Java object */
-
-       offset = this->offset;
-       count  = this->count;
-       value  = this->value;
+       
+       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) + value->data[offset + i];
+               hash = (31 * hash) + LLNI_array_direct(value, offset + i);
        }
 
        return hash;
@@ -111,19 +112,19 @@ JNIEXPORT s4 JNICALL Java_java_lang_String_hashCode(JNIEnv *env, java_lang_Strin
  */
 JNIEXPORT s4 JNICALL Java_java_lang_String_indexOf__I(JNIEnv *env, java_lang_String *this, s4 ch)
 {
-       java_chararray *value;
-       s4              offset;
-       s4              count;
-       s4              i;
+       java_handle_chararray_t *value;
+       int32_t                 offset;
+       int32_t                 count;
+       s4                              i;
 
        /* get values from Java object */
 
-       offset = this->offset;
-       count  = this->count;
-       value  = this->value;
+       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 (value->data[offset + i] == ch) {
+               if (LLNI_array_direct(value, offset + i) == ch) {
                        return i;
                }
        }
@@ -139,16 +140,16 @@ JNIEXPORT s4 JNICALL Java_java_lang_String_indexOf__I(JNIEnv *env, java_lang_Str
  */
 JNIEXPORT s4 JNICALL Java_java_lang_String_indexOf__II(JNIEnv *env, java_lang_String *this, s4 ch, s4 fromIndex)
 {
-       java_chararray *value;
-       s4              offset;
-       s4              count;
-       s4              i;
+       java_handle_chararray_t *value;
+       int32_t                 offset;
+       int32_t                 count;
+       s4                              i;
 
        /* get values from Java object */
 
-       offset = this->offset;
-       count  = this->count;
-       value  = this->value;
+       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;
@@ -159,7 +160,7 @@ JNIEXPORT s4 JNICALL Java_java_lang_String_indexOf__II(JNIEnv *env, java_lang_St
        }
 
        for (i = fromIndex ; i < count ; i++) {
-               if (value->data[offset + i] == ch) {
+               if (LLNI_array_direct(value, offset + i) == ch) {
                        return i;
                }
        }
@@ -175,7 +176,11 @@ JNIEXPORT s4 JNICALL Java_java_lang_String_indexOf__II(JNIEnv *env, java_lang_St
  */
 JNIEXPORT s4 JNICALL Java_java_lang_String_lastIndexOf__I(JNIEnv *env, java_lang_String *this, s4 ch)
 {
-       return Java_java_lang_String_lastIndexOf__II(env, this, ch, this->count - 1);
+       int32_t count;
+       
+       LLNI_field_get_val(this, count, count);
+       
+       return Java_java_lang_String_lastIndexOf__II(env, this, ch, count - 1);
 }
 
 
@@ -186,22 +191,22 @@ JNIEXPORT s4 JNICALL Java_java_lang_String_lastIndexOf__I(JNIEnv *env, java_lang
  */
 JNIEXPORT s4 JNICALL Java_java_lang_String_lastIndexOf__II(JNIEnv *env, java_lang_String *this, s4 ch, s4 fromIndex)
 {
-       java_chararray *value;
-       s4              offset;
-       s4              count;
-       s4              start;
-       s4              i;
+       java_handle_chararray_t *value;
+       int32_t                 offset;
+       int32_t                 count;
+       s4                              start;
+       s4                              i;
 
        /* get values from Java object */
 
-       offset = this->offset;
-       count  = this->count;
-       value  = this->value;
+       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 (value->data[offset + i] == ch) {
+               if (LLNI_array_direct(value, offset + i) == ch) {
                        return i;
                }
        }
@@ -218,23 +223,39 @@ JNIEXPORT s4 JNICALL Java_java_lang_String_lastIndexOf__II(JNIEnv *env, java_lan
  */
 JNIEXPORT s4 JNICALL Java_java_lang_String_equals(JNIEnv *env, java_lang_String* this, java_lang_Object *o)
 {
-       java_lang_String* s;
+       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 (o->header.vftbl->class != class_java_lang_String) 
+       
+       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 (this->count != s->count)
+       if (count != dcount)
                return 0;
 
-       return ( 0 == memcmp((void*)(this->value->data + this->offset),
-                                                (void*)(s->value->data + s->offset),
-                                                this->count) );
+       return ( 0 == memcmp((void*)(LLNI_array_direct(value, offset)),
+                                                (void*)(LLNI_array_direct(dvalue, doffset),
+                                                count) );
+
 }
 #endif
 
@@ -247,13 +268,20 @@ JNIEXPORT s4 JNICALL Java_java_lang_String_equals(JNIEnv *env, java_lang_String*
 JNIEXPORT java_lang_String* JNICALL Java_java_lang_String_intern(JNIEnv *env, java_lang_String *this)
 {
        java_handle_t *o;
+       java_handle_chararray_t *value;
+       int32_t                 offset;
+       int32_t                 count;
 
        if (this == NULL)
                return NULL;
+               
+       LLNI_field_get_val(this, offset, offset);
+       LLNI_field_get_val(this, count, count);
+       LLNI_field_get_ref(this, value, value);
 
        /* search table so identical strings will get identical pointers */
 
-       o = literalstring_u2(this->value, this->count, this->offset, true);
+       o = literalstring_u2(value, count, offset, true);
 
        return (java_lang_String *) o;
 }
index 25097feecdd495c49fb26339992f329a5c302c55..b88c2cb7e4928ad65f1b1d4c10db3d4309697f5f 100644 (file)
@@ -79,8 +79,8 @@ void _Jv_java_lang_System_init(void)
  */
 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)
 {
-       (void) builtin_arraycopy((java_arrayheader *) src, srcStart,
-                                                        (java_arrayheader *) dest, destStart, len);
+       (void) builtin_arraycopy((java_handle_t *) src, srcStart,
+                                                        (java_handle_t *) dest, destStart, len);
 }
 
 
index 84511522d62a73cbc18bb652f3e02e1d39b130a2..e1270e7137593dd64669d05f0060424b95ccbac5 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: zip.c 7548 2007-03-21 13:19:44Z twisti $
+   $Id: zip.c 8347 2007-08-18 13:04:59Z twisti $
 
 */
 
 
 #define SIGNATURE_LENGTH    4
 
-
-/* Local file header ***********************************************************
-
-   local file header signature     4 bytes  (0x04034b50)
-   version needed to extract       2 bytes
-   general purpose bit flag        2 bytes
-   compression method              2 bytes
-   last mod file time              2 bytes
-   last mod file date              2 bytes
-   crc-32                          4 bytes
-   compressed size                 4 bytes
-   uncompressed size               4 bytes
-   file name length                2 bytes
-   extra field length              2 bytes
-
-   file name (variable size)
-   extra field (variable size)
-
-*******************************************************************************/
-
-#define LFH_HEADER_SIZE              30
-
-#define LFH_SIGNATURE                0x04034b50
-#define LFH_FILE_NAME_LENGTH         26
-#define LFH_EXTRA_FIELD_LENGTH       28
-
-typedef struct lfh lfh;
-
-struct lfh {
-       u2 compressionmethod;
-       u4 compressedsize;
-       u4 uncompressedsize;
-       u2 filenamelength;
-       u2 extrafieldlength;
-};
-
-
 /* Central directory structure *************************************************
 
    [file header 1]
index 97e9e00d67c339349217a5bcd642be6eb98fadb3..8cd50c8816cd3053ee4f4a7cf39af7ef07519bf4 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: zip.h 7246 2007-01-29 18:49:05Z twisti $
+   $Id: zip.h 8347 2007-08-18 13:04:59Z twisti $
 
 */
 
 #include "vmcore/utf8.h"
 
 
+/* Local file header ***********************************************************
+
+   local file header signature     4 bytes  (0x04034b50)
+   version needed to extract       2 bytes
+   general purpose bit flag        2 bytes
+   compression method              2 bytes
+   last mod file time              2 bytes
+   last mod file date              2 bytes
+   crc-32                          4 bytes
+   compressed size                 4 bytes
+   uncompressed size               4 bytes
+   file name length                2 bytes
+   extra field length              2 bytes
+
+   file name (variable size)
+   extra field (variable size)
+
+*******************************************************************************/
+
+#define LFH_HEADER_SIZE              30
+
+#define LFH_SIGNATURE                0x04034b50
+#define LFH_FILE_NAME_LENGTH         26
+#define LFH_EXTRA_FIELD_LENGTH       28
+
+typedef struct lfh lfh;
+
+struct lfh {
+       u2 compressionmethod;
+       u4 compressedsize;
+       u4 uncompressedsize;
+       u2 filenamelength;
+       u2 extrafieldlength;
+};
+
 /* hashtable_zipfile_entry ****************************************************/
 
 typedef struct hashtable_zipfile_entry hashtable_zipfile_entry;