harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r376690 - in /incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio: IFileSystem.h IMemorySystem.h OSFileSystem.c OSFileSystem.h OSFileSystemLinux32.c OSMemory.c OSMemory.h OSMemoryLinux32.c hynio.exp
Date Fri, 10 Feb 2006 13:58:05 GMT
Author: tellison
Date: Fri Feb 10 05:57:38 2006
New Revision: 376690

URL: http://svn.apache.org/viewcvs?rev=376690&view=rev
Log:
Applying patches received as HARMONY-42 (com.ibm.io.nio.FileChannel is not fully implemented)
 - refactoring of some java platform code
 - additional behavior on NIO file channels
 - refactoring of some IO code
 - work in progress on memory mapping

Added:
    incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/IMemorySystem.h
Modified:
    incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/IFileSystem.h
    incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSFileSystem.c
    incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSFileSystem.h
    incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSFileSystemLinux32.c
    incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSMemory.c
    incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSMemory.h
    incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSMemoryLinux32.c
    incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/hynio.exp

Modified: incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/IFileSystem.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/IFileSystem.h?rev=376690&r1=376689&r2=376690&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/IFileSystem.h (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/IFileSystem.h Fri
Feb 10 05:57:38 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,9 +16,9 @@
 #include <jni.h>
 /* Header for class com_ibm_platform_IFileSystem */
 
-#if !defined(_Included_com_ibm_platform_IFileSystem)
+#ifndef _Included_com_ibm_platform_IFileSystem
 #define _Included_com_ibm_platform_IFileSystem
-#if defined(__cplusplus)
+#ifdef __cplusplus
 extern "C"
 {
 #endif
@@ -32,12 +32,6 @@
 #define com_ibm_platform_IFileSystem_SEEK_CUR 2L
 #undef com_ibm_platform_IFileSystem_SEEK_END
 #define com_ibm_platform_IFileSystem_SEEK_END 4L
-#undef com_ibm_platform_IFileSystem_MMAP_READ_ONLY
-#define com_ibm_platform_IFileSystem_MMAP_READ_ONLY 1L
-#undef com_ibm_platform_IFileSystem_MMAP_READ_WRITE
-#define com_ibm_platform_IFileSystem_MMAP_READ_WRITE 2L
-#undef com_ibm_platform_IFileSystem_MMAP_WRITE_COPY
-#define com_ibm_platform_IFileSystem_MMAP_WRITE_COPY 4L
 #undef com_ibm_platform_IFileSystem_O_RDONLY
 #define com_ibm_platform_IFileSystem_O_RDONLY 0L
 #undef com_ibm_platform_IFileSystem_O_WRONLY
@@ -56,7 +50,7 @@
 #define com_ibm_platform_IFileSystem_O_NONBLOCK 16777216L
 #undef com_ibm_platform_IFileSystem_O_TRUNC
 #define com_ibm_platform_IFileSystem_O_TRUNC 268435456L
-#if defined(__cplusplus)
+#ifdef __cplusplus
 }
 #endif
 #endif

Added: incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/IMemorySystem.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/IMemorySystem.h?rev=376690&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/IMemorySystem.h (added)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/IMemorySystem.h Fri
Feb 10 05:57:38 2006
@@ -0,0 +1,34 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class com_ibm_platform_IMemorySystem */
+
+#ifndef _Included_com_ibm_platform_IMemorySystem
+#define _Included_com_ibm_platform_IMemorySystem
+#ifdef __cplusplus
+extern "C" {
+#endif
+#undef com_ibm_platform_IMemorySystem_MMAP_READ_ONLY
+#define com_ibm_platform_IMemorySystem_MMAP_READ_ONLY 1L
+#undef com_ibm_platform_IMemorySystem_MMAP_READ_WRITE
+#define com_ibm_platform_IMemorySystem_MMAP_READ_WRITE 2L
+#undef com_ibm_platform_IMemorySystem_MMAP_WRITE_COPY
+#define com_ibm_platform_IMemorySystem_MMAP_WRITE_COPY 4L
+#ifdef __cplusplus
+}
+#endif
+#endif

Modified: incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSFileSystem.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSFileSystem.c?rev=376690&r1=376689&r2=376690&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSFileSystem.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSFileSystem.c Fri
Feb 10 05:57:38 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
  */
 
 #include <harmony.h>
+#include <string.h>
 
 #include "OSFileSystem.h"
 #include "IFileSystem.h"
@@ -27,10 +28,10 @@
  * Signature: (JJI)J
  */
 JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_readDirectImpl
-  (JNIEnv * env, jobject thiz, jlong fd, jlong buf, jint nbytes)
+  (JNIEnv * env, jobject thiz, jlong fd, jlong buf, jint offset, jint nbytes)
 {
   PORT_ACCESS_FROM_ENV (env);
-  return (jlong) hyfile_read ((IDATA) fd, (void *) ((IDATA) buf), (IDATA) nbytes);
+  return (jlong) hyfile_read ((IDATA) fd, (void *) (buf+offset), (IDATA) nbytes);
 }
 
 /*
@@ -39,10 +40,10 @@
  * Signature: (JJI)J
  */
 JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_writeDirectImpl
-  (JNIEnv * env, jobject thiz, jlong fd, jlong buf, jint nbytes)
+  (JNIEnv * env, jobject thiz, jlong fd, jlong buf, jint offset, jint nbytes)
 {
   PORT_ACCESS_FROM_ENV (env);
-  return (jlong) hyfile_write ((IDATA) fd, (const void *) ((IDATA) buf),
+  return (jlong) hyfile_write ((IDATA) fd, (const void *) (buf+offset),
                                (IDATA) nbytes);
 }
 
@@ -71,6 +72,30 @@
   return result;
 }
 
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    writeImpl
+ * Signature: (J[BII)J
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_writeImpl
+  (JNIEnv * env, jobject thiz, jlong fd, jbyteArray byteArray, jint offset, jint nbytes)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  jboolean isCopy;
+  jbyte *bytes = (*env)->GetByteArrayElements (env, byteArray, &isCopy);
+  jlong result;
+
+  result =
+    (jlong) hyfile_write ((IDATA) fd, (void *) (bytes + offset),
+                         (IDATA) nbytes);
+  if (isCopy == JNI_TRUE)
+    {
+      (*env)->ReleaseByteArrayElements (env, byteArray, bytes, 0);
+    }
+
+  return result;
+}
+
 /**
  * Seeks a file descriptor to a given file position.
  * 
@@ -87,7 +112,7 @@
   (JNIEnv * env, jobject thiz, jlong fd, jlong offset, jint whence)
 {
   PORT_ACCESS_FROM_ENV (env);
-  I_32 hywhence = 0;            // The HY PPL equivalent of our whence arg.
+  I_32 hywhence = 0;            /* The HY PPL equivalent of our whence arg.*/
 
   /* Convert whence argument */
   switch (whence)
@@ -147,4 +172,114 @@
 
   return (jint) hyfile_close ((IDATA) fd);
 }
+
+
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    truncateImpl
+ * Signature: (JJ)I
+ */
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSFileSystem_truncateImpl
+  (JNIEnv * env, jobject thiz, jlong fd, jlong size)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  return (jint)hyfile_set_length((IDATA)fd, (I_64)size);
+
+}
+
+#define jclSeparator DIR_SEPARATOR
+/**
+  * This will convert all separators to the proper platform separator
+  * and remove duplicates on non POSIX platforms.
+  */
+void convertToPlatform (char *path)
+{
+  char *pathIndex;
+  int length = strlen (path);
+
+  /* Convert all separators to the same type */
+  pathIndex = path;
+  while (*pathIndex != '\0')
+    {
+      if ((*pathIndex == '\\' || *pathIndex == '/')
+          && (*pathIndex != jclSeparator))
+        *pathIndex = jclSeparator;
+      pathIndex++;
+    }
+
+  /* Remove duplicate separators */
+  if (jclSeparator == '/')
+    return;                     /* Do not do POSIX platforms */
+
+  /* Remove duplicate initial separators */
+  pathIndex = path;
+  while ((*pathIndex != '\0') && (*pathIndex == jclSeparator))
+    {
+      pathIndex++;
+    }
+  if ((pathIndex > path) && (length > (pathIndex - path))
+      && (*(pathIndex + 1) == ':'))
+    {
+      /* For Example '////c:/*' */
+      int newlen = length - (pathIndex - path);
+      memmove (path, pathIndex, newlen);
+      path[newlen] = '\0';
+    }
+  else
+    {
+      if ((pathIndex - path > 3) && (length > (pathIndex - path)))
+        {
+          /* For Example '////serverName/*' */
+          int newlen = length - (pathIndex - path) + 2;
+          memmove (path, pathIndex - 2, newlen);
+          path[newlen] = '\0';
+        }
+    }
+  /* This will have to handle extra \'s but currently doesn't */
+}
+
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    openImpl
+ * Signature: ([BI)J
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_openImpl
+  (JNIEnv * env, jobject obj, jbyteArray path, jint jflags){
+      PORT_ACCESS_FROM_ENV (env);
+      I_32 flags = 0;
+      I_32 mode = 0; 
+      IDATA portFD;
+      jsize length;
+      char pathCopy[HyMaxPath];
+
+      switch(jflags){
+        case com_ibm_platform_IFileSystem_O_RDONLY:
+                flags = HyOpenRead;
+                mode = 0;
+                break;
+        case com_ibm_platform_IFileSystem_O_WRONLY:
+                flags = HyOpenCreate | HyOpenWrite | HyOpenTruncate;
+                mode = 0666;
+                break;
+        case com_ibm_platform_IFileSystem_O_RDWR:
+                flags = HyOpenRead | HyOpenWrite | HyOpenCreate;
+                mode = 0666;
+                break;
+        case com_ibm_platform_IFileSystem_O_APPEND:
+                flags = HyOpenWrite | HyOpenCreate | HyOpenAppend; 
+                mode = 0666;
+                break;
+      }
+
+      length = (*env)->GetArrayLength (env, path);
+      length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+      ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+      pathCopy[length] = '\0';
+      convertToPlatform (pathCopy);
+
+      portFD = hyfile_open (pathCopy, flags, mode);
+      return (jlong)portFD;
+  }
+
 

Modified: incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSFileSystem.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSFileSystem.h?rev=376690&r1=376689&r2=376690&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSFileSystem.h (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSFileSystem.h Fri
Feb 10 05:57:38 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,9 +16,9 @@
 #include <jni.h>
 /* Header for class com_ibm_platform_OSFileSystem */
 
-#if !defined(_Included_com_ibm_platform_OSFileSystem)
+#ifndef _Included_com_ibm_platform_OSFileSystem
 #define _Included_com_ibm_platform_OSFileSystem
-#if defined(__cplusplus)
+#ifdef __cplusplus
 extern "C"
 {
 #endif
@@ -29,6 +29,15 @@
  */
   JNIEXPORT jint JNICALL Java_com_ibm_platform_OSFileSystem_lockImpl
     (JNIEnv *, jobject, jlong, jlong, jlong, jint, jboolean);
+
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    getPageSize
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSFileSystem_getPageSize
+  (JNIEnv *, jobject);
+
 /*
  * Class:     com_ibm_platform_OSFileSystem
  * Method:    unlockImpl
@@ -53,17 +62,17 @@
 /*
  * Class:     com_ibm_platform_OSFileSystem
  * Method:    readDirectImpl
- * Signature: (JJI)J
+ * Signature: (JJII)J
  */
   JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_readDirectImpl
-    (JNIEnv *, jobject, jlong, jlong, jint);
+    (JNIEnv *, jobject, jlong, jlong, jint, jint);
 /*
  * Class:     com_ibm_platform_OSFileSystem
  * Method:    writeDirectImpl
- * Signature: (JJI)J
+ * Signature: (JJII)J
  */
   JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_writeDirectImpl
-    (JNIEnv *, jobject, jlong, jlong, jint);
+    (JNIEnv *, jobject, jlong, jlong, jint, jint);
 /*
  * Class:     com_ibm_platform_OSFileSystem
  * Method:    readImpl
@@ -73,11 +82,28 @@
     (JNIEnv *, jobject, jlong, jbyteArray, jint, jint);
 /*
  * Class:     com_ibm_platform_OSFileSystem
- * Method:    mmapImpl
- * Signature: (JJJI)J
+ * Method:    writeImpl
+ * Signature: (J[BII)J
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_writeImpl
+  (JNIEnv *, jobject, jlong, jbyteArray, jint, jint);
+
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    readvImpl
+ * Signature: (J[J[I[II)J
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_readvImpl
+  (JNIEnv *, jobject, jlong, jlongArray, jintArray, jintArray, jint);
+
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    writevImpl
+ * Signature: (J[J[I[II)J
  */
-  JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_mmapImpl
-    (JNIEnv *, jobject, jlong, jlong, jlong, jint);
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_writevImpl
+  (JNIEnv *, jobject, jlong, jlongArray, jintArray, jintArray, jint);
+
 /*
  * Class:     com_ibm_platform_OSFileSystem
  * Method:    closeImpl
@@ -85,7 +111,32 @@
  */
   JNIEXPORT jint JNICALL Java_com_ibm_platform_OSFileSystem_closeImpl
     (JNIEnv *, jobject, jlong);
-#if defined(__cplusplus)
+
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    truncateImpl
+ * Signature: (JJ)I
+ */
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSFileSystem_truncateImpl
+  (JNIEnv *, jobject, jlong, jlong);
+
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    openImpl
+ * Signature: ([BI)J
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_openImpl
+  (JNIEnv *, jobject, jbyteArray, jint);
+
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    transferImpl
+ * Signature: (JLjava/io/FileDescriptor;JJ)J
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_transferImpl
+  (JNIEnv *, jobject, jlong, jobject, jlong, jlong);
+
+#ifdef __cplusplus
 }
 #endif
 #endif

Modified: incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSFileSystemLinux32.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSFileSystemLinux32.c?rev=376690&r1=376689&r2=376690&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSFileSystemLinux32.c
(original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSFileSystemLinux32.c
Fri Feb 10 05:57:38 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,26 +17,23 @@
  * Linux32 specific natives supporting the file system interface.
  */
 
+#include <sys/uio.h>
 #include <fcntl.h>
-#include <bits/wordsize.h>
+#include <unistd.h>
 #include <errno.h>
-
+#include <sys/sendfile.h>
 #include <harmony.h>
 
 #include "IFileSystem.h"
 #include "OSFileSystem.h"
 
-/*
- * Class:     com_ibm_platform_OSFileSystem
- * Method:    mmapImpl
- * Signature: (JJJI)J
- */
-JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_mmapImpl
-  (JNIEnv * env, jobject thiz, jlong fd, jlong offset, jlong size, jint mmode)
+typedef int OSSOCKET;   
+typedef struct hysocket_struct
 {
-  // TODO: 
-  return (jlong) - 1L;
-}
+  OSSOCKET sock;
+  U_16 family;
+} hysocket_struct;
+
 
 /**
  * Lock the file identified by the given handle.
@@ -121,3 +118,117 @@
 
   return (rc == -1) ? -1 : 0;
 }
+
+
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSFileSystem_getPageSize
+  (JNIEnv * env, jobject thiz)
+{
+  static int pageSize = 0;
+  if(pageSize == 0){
+    pageSize = getpagesize();
+  }
+  return pageSize;
+}
+
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    readvImpl
+ * Signature: (J[J[I[I)J
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_readvImpl
+  (JNIEnv *env, jobject thiz, jlong fd, jlongArray jbuffers, jintArray joffsets, jintArray
jlengths, jint size){
+  PORT_ACCESS_FROM_ENV (env);
+  jboolean bufsCopied = JNI_FALSE;
+  jboolean offsetsCopied = JNI_FALSE;
+  jboolean lengthsCopied = JNI_FALSE;
+  jlong *bufs; 
+  jint *offsets;
+  jint *lengths;
+  int i = 0;
+  long totalRead = 0;  
+  struct iovec *vectors = (struct iovec *)hymem_allocate_memory(size * sizeof(struct iovec));
+  if(vectors == NULL){
+    return -1;
+  }
+  bufs = (*env)->GetLongArrayElements(env, jbuffers, &bufsCopied);
+  offsets = (*env)->GetIntArrayElements(env, joffsets, &offsetsCopied);
+  lengths = (*env)->GetIntArrayElements(env, jlengths, &lengthsCopied);
+  while(i < size){
+    vectors[i].iov_base = (void *)(bufs[i]+offsets[i]);
+    vectors[i].iov_len = lengths[i];
+    i++;
+  }
+  totalRead = readv(fd, vectors, size);
+  if(bufsCopied){
+    (*env)->ReleaseLongArrayElements(env, jbuffers, bufs, JNI_ABORT);
+  }
+  if(offsetsCopied){
+    (*env)->ReleaseIntArrayElements(env, joffsets, offsets, JNI_ABORT);
+  }
+  if(lengthsCopied){
+    (*env)->ReleaseIntArrayElements(env, jlengths, lengths, JNI_ABORT);
+  }
+  hymem_free_memory(vectors);
+  return totalRead;
+}
+
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    writevImpl
+ * Signature: (J[J[I[I)J
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_writevImpl
+  (JNIEnv *env, jobject thiz, jlong fd, jlongArray jbuffers, jintArray joffsets, jintArray
jlengths, jint size){
+  PORT_ACCESS_FROM_ENV (env);
+  jboolean bufsCopied = JNI_FALSE;
+  jboolean offsetsCopied = JNI_FALSE;
+  jboolean lengthsCopied = JNI_FALSE;
+  jlong *bufs; 
+  jint *offsets;
+  jint *lengths;
+  int i = 0;
+  long totalRead = 0;  
+  struct iovec *vectors = (struct iovec *)hymem_allocate_memory(size * sizeof(struct iovec));
+  if(vectors == NULL){
+    return -1;
+  }
+  bufs = (*env)->GetLongArrayElements(env, jbuffers, &bufsCopied);
+  offsets = (*env)->GetIntArrayElements(env, joffsets, &offsetsCopied);
+  lengths = (*env)->GetIntArrayElements(env, jlengths, &lengthsCopied);
+  while(i < size){
+    vectors[i].iov_base = (void *)(bufs[i]+offsets[i]);
+    vectors[i].iov_len = lengths[i];
+    i++;
+  }
+  totalRead = writev(fd, vectors, size);
+  if(bufsCopied){
+    (*env)->ReleaseLongArrayElements(env, jbuffers, bufs, JNI_ABORT);
+  }
+  if(offsetsCopied){
+    (*env)->ReleaseIntArrayElements(env, joffsets, offsets, JNI_ABORT);
+  }
+  if(lengthsCopied){
+    (*env)->ReleaseIntArrayElements(env, jlengths, lengths, JNI_ABORT);
+  }
+  hymem_free_memory(vectors);
+  return totalRead;
+}
+
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    transferImpl
+ * Signature: (JLjava/io/FileDescriptor;JJ)J
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_transferImpl
+  (JNIEnv *env, jobject thiz, jlong fd, jobject sd, jlong offset, jlong count)
+{
+	PORT_ACCESS_FROM_ENV (env);
+	int socket;
+	//TODO IPV6
+	hysocket_t hysocketP= (hysocket_t)getJavaIoFileDescriptorContentsAsAPointer (env,sd);
+	if(hysocketP == NULL)
+       return -1;
+	socket = hysocketP->sock;
+	return sendfile(socket,(size_t)fd,(off_t *)&offset,(size_t)count);	
+}
+

Modified: incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSMemory.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSMemory.c?rev=376690&r1=376689&r2=376690&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSMemory.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSMemory.c Fri Feb
10 05:57:38 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,9 +17,10 @@
  * Common natives supporting the memory system interface.
  */
 
-#include <string.h>
+#include <sys/mman.h>
 #include <harmony.h>
 #include "OSMemory.h"
+#include "IMemorySystem.h"
 
 JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSMemory_malloc
   (JNIEnv * env, jobject thiz, jlong size)
@@ -159,3 +160,59 @@
 {
   *(jdouble *) ((IDATA) address) = value;
 }
+
+
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    unmapImpl
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_unmapImpl
+  (JNIEnv * env, jobject thiz, jlong fd)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  hymmap_unmap_file((void *)fd);
+}
+
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    mmapImpl
+ * Signature: (JJJI)J
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSMemory_mmapImpl
+  (JNIEnv * env, jobject thiz, jlong fd, jlong alignment, jlong size, jint mmode)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  void *mapAddress = NULL;
+  int prot, flags;
+		  
+  // Convert from Java mapping mode to port library mapping mode.
+  switch (mmode)
+    {
+      case com_ibm_platform_IMemorySystem_MMAP_READ_ONLY:
+	prot = PROT_READ;
+	flags = MAP_SHARED;
+        break;
+      case com_ibm_platform_IMemorySystem_MMAP_READ_WRITE:
+	prot = PROT_READ|PROT_WRITE;
+	flags = MAP_SHARED;
+        break;
+      case com_ibm_platform_IMemorySystem_MMAP_WRITE_COPY:
+	prot = PROT_READ|PROT_WRITE;
+	flags = MAP_PRIVATE;
+        break;
+      default:
+        return -1;
+    }
+
+//TODO: how to unmap
+ // mapAddress = hymmap_map_filehandler(fd, &mapAddress, mapmode, (IDATA)alignment, (IDATA)size);
+
+   mapAddress = mmap(0,size, prot, flags,fd,alignment);
+  if (mapAddress == NULL)
+    {
+      return -1;
+    }
+  return (jlong) mapAddress;
+}
+

Modified: incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSMemory.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSMemory.h?rev=376690&r1=376689&r2=376690&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSMemory.h (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSMemory.h Fri Feb
10 05:57:38 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,9 +16,9 @@
 #include <jni.h>
 /* Header for class com_ibm_platform_OSMemory */
 
-#if !defined(_Included_com_ibm_platform_OSMemory)
+#ifndef _Included_com_ibm_platform_OSMemory
 #define _Included_com_ibm_platform_OSMemory
-#if defined(__cplusplus)
+#ifdef __cplusplus
 extern "C"
 {
 #endif
@@ -81,6 +81,15 @@
  */
   JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setByteArray
     (JNIEnv *, jobject, jlong, jbyteArray, jint, jint);
+
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    setCharArray
+ * Signature: (J[CII)V
+ */
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setCharArray
+  (JNIEnv *, jobject, jlong, jcharArray, jint, jint);
+
 /*
  * Class:     com_ibm_platform_OSMemory
  * Method:    getByte
@@ -179,7 +188,48 @@
  */
   JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setAddress
     (JNIEnv *, jobject, jlong, jlong);
-#if defined(__cplusplus)
+
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    mmapImpl
+ * Signature: (JJJI)J
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSMemory_mmapImpl
+  (JNIEnv *, jobject, jlong, jlong, jlong, jint);
+
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    unmapImpl
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_unmapImpl
+  (JNIEnv *, jobject, jlong);
+
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    loadImpl
+ * Signature: (JJ)I
+ */
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSMemory_loadImpl
+  (JNIEnv *, jobject, jlong, jlong);
+
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    isLoadedImpl
+ * Signature: (JJ)Z
+ */
+JNIEXPORT jboolean JNICALL Java_com_ibm_platform_OSMemory_isLoadedImpl
+  (JNIEnv *, jobject, jlong, jlong);
+
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    flushImpl
+ * Signature: (JJ)I
+ */
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSMemory_flushImpl
+  (JNIEnv *, jobject, jlong, jlong);
+
+#ifdef __cplusplus
 }
 #endif
 #endif

Modified: incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSMemoryLinux32.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSMemoryLinux32.c?rev=376690&r1=376689&r2=376690&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSMemoryLinux32.c
(original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/OSMemoryLinux32.c
Fri Feb 10 05:57:38 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,29 +18,86 @@
  */
 
 #include <string.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <unistd.h>
 #include <harmony.h>
 #include "OSMemory.h"
 
 #define	OS_JNI(func) JNICALL Java_com_ibm_platform_OSMemory_##func
 
-JNIEXPORT jboolean OS_JNI (isLittleEndianImpl) (JNIEnv * env, jclass clazz)
+JNIEXPORT jboolean JNICALL Java_com_ibm_platform_OSMemory_isLittleEndianImpl(JNIEnv * env,
jclass clazz)
 {
   return JNI_TRUE;
 }
 
-JNIEXPORT jint OS_JNI (getPointerSizeImpl) (JNIEnv * env, jclass clazz)
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSMemory_getPointerSizeImpl (JNIEnv * env, jclass
clazz)
 {
   return 4;
 }
 
-JNIEXPORT jlong OS_JNI (getAddress)
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSMemory_getAddress
   (JNIEnv * env, jobject thiz, jlong address)
 {
   return (jlong) * (long *) ((IDATA) address);
 }
 
-JNIEXPORT void OS_JNI (setAddress)
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setAddress
   (JNIEnv * env, jobject thiz, jlong address, jlong value)
 {
   *(long *) ((IDATA) address) = (long) value;
 }
+
+
+int getPageSize()
+{
+	static int PAGE_SIZE = 0;
+	if(PAGE_SIZE==0)
+		PAGE_SIZE=getpagesize();
+	return PAGE_SIZE;
+}
+
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSMemory_loadImpl
+  (JNIEnv * env, jobject thiz, jlong addr, jlong size){
+   if(mlock((void *)addr, size)!=-1)
+   {
+      if(munlock((void *)addr,size)!=-1)
+	      return 0;  /*normally*/
+   }
+   else{
+      	if(errno == EPERM) /*according to linux sys call, only root can mlock memory.*/
+      	   return 0;
+   }
+   return -1;
+  }
+
+JNIEXPORT jboolean JNICALL Java_com_ibm_platform_OSMemory_isLoadedImpl
+  (JNIEnv * env, jobject thiz, jlong addr, jlong size){
+	  PORT_ACCESS_FROM_ENV (env);
+  	  jboolean result = 0;
+  	  int m_addr = (int)addr;
+	  int PAGE_SIZE = getPageSize();
+	  char* vec = NULL;
+	  int page_count = 0;
+	  int align_offset = m_addr%PAGE_SIZE;//addr should align with the boundary of a page.
+	  m_addr -= align_offset;
+	  size   += align_offset;
+	  page_count = (size+PAGE_SIZE-1)/PAGE_SIZE;
+	  vec = (char *) hymem_allocate_memory(page_count*sizeof(char));
+	  if(mincore((void *)m_addr, size , vec)==0) //or else there is error about the mincore
and return false;
+	  {
+	  	  int i;
+		  for(i=0 ;i<page_count;i++)
+			  if(vec[i]!=1)
+			     break;
+		  if(i==page_count)
+			  result = 1;
+	  }
+	  hymem_free_memory(vec);
+      return result;
+  }
+
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSMemory_flushImpl
+  (JNIEnv * env, jobject thiz, jlong addr, jlong size){
+  return msync((void *)addr, size, MS_SYNC);
+};

Modified: incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/hynio.exp
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/hynio.exp?rev=376690&r1=376689&r2=376690&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/hynio.exp (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/linux.IA32/nio/hynio.exp Fri Feb
10 05:57:38 2006
@@ -1,14 +1,25 @@
 HYNIO_0.1 {
 	global :
+		Java_com_ibm_platform_OSFileSystem_truncateImpl;
+		Java_com_ibm_platform_OSFileSystem_getPageSize;
+		Java_com_ibm_platform_OSFileSystem_writevImpl;
+		Java_com_ibm_platform_OSFileSystem_readvImpl;
+		Java_com_ibm_platform_OSFileSystem_writeImpl;
+		Java_com_ibm_platform_OSFileSystem_openImpl;	
 		Java_com_ibm_platform_OSFileSystem_readDirectImpl;
 		Java_com_ibm_platform_OSFileSystem_writeDirectImpl;
 		Java_com_ibm_platform_OSFileSystem_readImpl;
 		Java_com_ibm_platform_OSFileSystem_seekImpl;
 		Java_com_ibm_platform_OSFileSystem_fflushImpl;
 		Java_com_ibm_platform_OSFileSystem_closeImpl;
-		Java_com_ibm_platform_OSFileSystem_mmapImpl;
 		Java_com_ibm_platform_OSFileSystem_lockImpl;
 		Java_com_ibm_platform_OSFileSystem_unlockImpl;
+		Java_com_ibm_platform_OSFileSystem_transferImpl;
+		Java_com_ibm_platform_OSMemory_isLoadedImpl;
+		Java_com_ibm_platform_OSMemory_loadImpl;
+		Java_com_ibm_platform_OSMemory_mmapImpl;
+		Java_com_ibm_platform_OSMemory_unmapImpl;
+		Java_com_ibm_platform_OSMemory_flushImpl;
 		Java_com_ibm_platform_OSMemory_isLittleEndianImpl;
 		Java_com_ibm_platform_OSMemory_getPointerSizeImpl;
 		Java_com_ibm_platform_OSMemory_getAddress;



Mime
View raw message