Author: tellison
Date: Fri Feb 10 05:56:29 2006
New Revision: 376688
URL: http://svn.apache.org/viewcvs?rev=376688&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/win.IA32/nio/IMemorySystem.h
Modified:
incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/IFileSystem.h
incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSFileSystem.c
incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSFileSystem.h
incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSFileSystemWin32.c
incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSMemory.c
incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSMemory.h
incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSMemoryWin32.c
incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/hynio.def
incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/makefile
incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/port/hyfile.c
Modified: incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/IFileSystem.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/IFileSystem.h?rev=376688&r1=376687&r2=376688&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/IFileSystem.h (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/IFileSystem.h Fri Feb
10 05:56:29 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 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.
@@ -33,12 +33,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
Added: incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/IMemorySystem.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/IMemorySystem.h?rev=376688&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/IMemorySystem.h (added)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/IMemorySystem.h Fri
Feb 10 05:56:29 2006
@@ -0,0 +1,32 @@
+/* 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.
+ */
+#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/win.IA32/nio/OSFileSystem.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSFileSystem.c?rev=376688&r1=376687&r2=376688&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSFileSystem.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSFileSystem.c Fri Feb
10 05:56:29 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 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,6 +18,7 @@
*/
#include <harmony.h>
+#include <string.h>
#include "OSFileSystem.h"
#include "IFileSystem.h"
@@ -28,10 +29,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 *) buf, (IDATA) nbytes);
+ return (jlong) hyfile_read ((IDATA) fd, (void *) (buf+offset), (IDATA) nbytes);
}
/*
@@ -40,10 +41,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 *) buf,
+ return (jlong) hyfile_write ((IDATA) fd, (const void *) (buf+offset),
(IDATA) nbytes);
}
@@ -72,6 +73,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.
*
@@ -148,4 +173,112 @@
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/win.IA32/nio/OSFileSystem.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSFileSystem.h?rev=376688&r1=376687&r2=376688&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSFileSystem.h (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSFileSystem.h Fri Feb
10 05:56:29 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 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,11 +17,10 @@
#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)
-extern "C"
-{
+#ifdef __cplusplus
+extern "C" {
#endif
/*
* Class: com_ibm_platform_OSFileSystem
@@ -30,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
@@ -54,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
@@ -74,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
@@ -86,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/win.IA32/nio/OSFileSystemWin32.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSFileSystemWin32.c?rev=376688&r1=376687&r2=376688&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSFileSystemWin32.c
(original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSFileSystemWin32.c
Fri Feb 10 05:56:29 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 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,75 +17,23 @@
* Win32 specific natives supporting the file system interface.
*/
-#include <windows.h>
-#include <harmony.h>
+#if defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_)
+#undef _WINSOCKAPI_
+#endif
+#include <windows.h>
+#include "nethelp.h"
+#include <stdio.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 SOCKET OSSOCKET;
+typedef struct hysocket_struct
{
-
- DWORD flProtect = 0;
- DWORD dwDesiredAccess = 0; /* Access control for mapping view. */
- HANDLE hFileMappingObject = 0;
- LPVOID mapAddress = 0;
- DWORD dwFileOffsetLow = (DWORD) (offset & 0xFFFFFFFF);
- DWORD dwFileOffsetHigh = (DWORD) ((offset >> 0x20) & 0x7FFFFFFF);
-
- // Convert from Java mapping mode to windows mapping mode.
- switch (mmode)
- {
- case com_ibm_platform_IFileSystem_MMAP_READ_ONLY:
- flProtect = PAGE_READONLY;
- dwDesiredAccess = FILE_MAP_READ;
- break;
- case com_ibm_platform_IFileSystem_MMAP_READ_WRITE:
- flProtect = PAGE_READWRITE;
- dwDesiredAccess = FILE_MAP_WRITE;
- break;
- case com_ibm_platform_IFileSystem_MMAP_WRITE_COPY:
- flProtect = PAGE_WRITECOPY;
- dwDesiredAccess = FILE_MAP_COPY;
- break;
- default:
- return -1;
- }
-
- /* First create a file mapping handle. */
- hFileMappingObject = CreateFileMapping ((HANDLE) fd, /* [in] file handle */
- (LPSECURITY_ATTRIBUTES) NULL, /* [in] mapping is
not inherited */
- flProtect, /* [in] protection mode for mapped
data */
- (DWORD) 0, /* [in] maximum size high */
- (DWORD) 0, /* [in] maximum size low */
- (LPCTSTR) NULL); /* [in] name for mapping
object */
-
- if (!hFileMappingObject || hFileMappingObject == INVALID_HANDLE_VALUE)
- {
- return -1;
- }
-
- /* Secondly create a view on that mapping object. */
-
- mapAddress = MapViewOfFile (hFileMappingObject, /* [in] open file mapping object
*/
- dwDesiredAccess, /* [in] access to the file view */
- dwFileOffsetHigh, /* [in] high offset where mapping is to begin
*/
- dwFileOffsetLow, /* [in] low offset where mapping is to begin
*/
- (SIZE_T) size); /* [in] number of bytes to map */
-
- if (mapAddress == NULL)
- {
- return -1;
- }
-
- return (jlong) mapAddress;
-}
+ OSSOCKET ipv4;
+ OSSOCKET ipv6;
+ U_8 flags;
+} hysocket_struct;
/**
* Lock the file identified by the given handle.
@@ -163,5 +111,134 @@
return (jint) 0;
}
return (jint) - 1;
+}
+
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSFileSystem_getPageSize
+ (JNIEnv * env, jobject thiz)
+{
+ static DWORD pageSize = 0;
+ if(!pageSize){
+ SYSTEM_INFO info;
+ GetSystemInfo(&info);
+ pageSize = info.dwPageSize;
+ }
+ 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 = (*env)->GetLongArrayElements(env, jbuffers, &bufsCopied);
+ jint *offsets = (*env)->GetIntArrayElements(env, joffsets, &offsetsCopied);
+ jint *lengths = (*env)->GetIntArrayElements(env, jlengths, &lengthsCopied);
+ long totalRead = 0;
+ int i = 0;
+ while(i<size){
+ long bytesRead = hyfile_read ((IDATA) fd, (void *) (*(bufs+i)+*(offsets+i)), (IDATA)
*(lengths+i));
+ if(bytesRead == -1){
+ totalRead = -1;
+ break;
+ }
+ totalRead += bytesRead;
+ i++;
+ }
+ 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);
+ }
+ 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 = (*env)->GetLongArrayElements(env, jbuffers, &bufsCopied);
+ jint *offsets = (*env)->GetIntArrayElements(env, joffsets, &offsetsCopied);
+ jint *lengths = (*env)->GetIntArrayElements(env, jlengths, &lengthsCopied);
+ long totalWritten = 0;
+ int i = 0;
+ while(i<size){
+ long bytesWritten = hyfile_write ((IDATA) fd, (void *) (*(bufs+i)+*(offsets+i)), (IDATA)
*(lengths+i));
+ if(bytesWritten == -1){
+ totalWritten = -1;
+ break;
+ }
+ totalWritten += bytesWritten;
+ i++;
+ }
+ 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);
+ }
+ return totalWritten;
+}
+
+/*
+ * 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 length =0;
+ HANDLE hfile = (HANDLE)fd;
+ OVERLAPPED overlapped;
+ SOCKET socket;
+ //TODO IPV6
+
+ hysocket_t hysocketP = getJavaIoFileDescriptorContentsAsAPointer(env,sd);
+ if (!hysock_socketIsValid (hysocketP)){
+ printf("not valid socket\n");
+ }
+ printf("hysocketP:%p\n",hysocketP);
+ if(hysocketP == NULL)
+ {
+ printf("Error getJavaIoFileDescriptorContentsAsAPointer!\n");
+ return -1;}
+
+ socket = (SOCKET)hysocketP->ipv4;
+ printf("socket:%p\n",socket);
+ overlapped.Offset = (int)offset;
+ overlapped.OffsetHigh = (int)(offset>>32);
+
+ TransmitFile(socket,hfile,(int)count,0,&overlapped,NULL,0);
+ printf("TrasmitFile Error %d\n",GetLastError());
+ if(GetOverlappedResult((HANDLE)socket,&overlapped,(LPDWORD)&length,1))
+ {
+ return length; //OK
+ }
+ else
+ {
+ printf("GetOverlappedResult Error %d\n",GetLastError());
+ return -1;//ERROR
+ }
}
Modified: incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSMemory.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSMemory.c?rev=376688&r1=376687&r2=376688&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSMemory.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSMemory.c Fri Feb 10
05:56:29 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 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.
@@ -20,6 +20,7 @@
#include <string.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)
@@ -73,6 +74,17 @@
}
}
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_getCharArray
+ (JNIEnv * env, jobject thiz, jlong address, jcharArray jdest, jint offset, jint length){
+ jboolean isCopy;
+ jchar *dest = (*env)->GetCharArrayElements (env, jdest, &isCopy);
+ memcpy (dest + offset, (const void *) address, (size_t) length);
+ if (isCopy == JNI_TRUE)
+ {
+ (*env)->ReleaseCharArrayElements (env, jdest, dest, 0);
+ }
+ }
+
JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setByteArray
(JNIEnv * env, jobject thiz, jlong address, jbyteArray byteArray,
jint offset, jint length)
@@ -86,6 +98,17 @@
}
}
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setCharArray
+ (JNIEnv * env, jobject thiz, jlong address, jcharArray jsrc, jint offset, jint length){
+ jboolean isCopy;
+ jchar *src = (*env)->GetCharArrayElements (env, jsrc, &isCopy);
+ memcpy ((void *) address, (const jchar *) src + offset, (size_t) length);
+ if (isCopy == JNI_TRUE)
+ {
+ (*env)->ReleaseCharArrayElements (env, jsrc, src, JNI_ABORT);
+ }
+ }
+
JNIEXPORT jbyte JNICALL Java_com_ibm_platform_OSMemory_getByte
(JNIEnv * env, jobject thiz, jlong address)
{
@@ -158,3 +181,54 @@
*(jdouble *) 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;
+ I_32 mapmode = 0;
+
+ // Convert from Java mapping mode to port library mapping mode.
+ /* TPE - removed until portlib fixed
+ switch (mmode)
+ {
+ case com_ibm_platform_IMemorySystem_MMAP_READ_ONLY:
+ mapmode = HYPORT_MMAP_CAPABILITY_READ;
+ break;
+ case com_ibm_platform_IMemorySystem_MMAP_READ_WRITE:
+ mapmode = HYPORT_MMAP_CAPABILITY_READ|HYPORT_MMAP_CAPABILITY_WRITE;
+ break;
+ case com_ibm_platform_IMemorySystem_MMAP_WRITE_COPY:
+ mapmode = HYPORT_MMAP_CAPABILITY_COPYONWRITE;
+ break;
+ default:
+ return -1;
+ }
+
+ hymmap_map_filehandler((void *)fd, &mapAddress, mapmode, (IDATA)alignment, (IDATA)size);
+ */
+
+ if (mapAddress == NULL)
+ {
+ return -1;
+ }
+
+ return (jlong) mapAddress;
+}
Modified: incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSMemory.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSMemory.h?rev=376688&r1=376687&r2=376688&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSMemory.h (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSMemory.h Fri Feb 10
05:56:29 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 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,11 +17,10 @@
#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)
-extern "C"
-{
+#ifdef __cplusplus
+extern "C" {
#endif
/* Inaccessible static: POINTER_SIZE */
/* Inaccessible static: NATIVE_ORDER */
@@ -82,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
@@ -180,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: 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: (Lcom/ibm/platform/struct/PlatformAddress;J)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);
+
+/*
+ * Class: com_ibm_platform_OSMemory
+ * Method: mmapImpl
+ * Signature: (JJJII)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);
+
+#ifdef __cplusplus
}
#endif
#endif
Modified: incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSMemoryWin32.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSMemoryWin32.c?rev=376688&r1=376687&r2=376688&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSMemoryWin32.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/OSMemoryWin32.c Fri
Feb 10 05:56:29 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 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.
@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <string.h>
+#include <windows.h>
#include "OSMemory.h"
JNIEXPORT jboolean JNICALL Java_com_ibm_platform_OSMemory_isLittleEndianImpl
@@ -59,4 +60,36 @@
#endif
}
+
+
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSMemory_loadImpl
+ (JNIEnv * env, jobject thiz, jlong addr, jlong size){
+ /* FIXME:
+ * lock the memory make the pages be loaded into physical memory
+ * and unlock then to make them swappable
+ * maybe can be improved
+ * */
+ if(0 != VirtualLock((void *)addr, (SIZE_T)size)){
+ VirtualUnlock((void *)addr, (SIZE_T)size);
+ return 0;
+ }else{
+ printf("lock error: %d\n", GetLastError());
+ return -1;
+ }
+ }
+
+JNIEXPORT jboolean JNICALL Java_com_ibm_platform_OSMemory_isLoadedImpl
+ (JNIEnv * env, jobject thiz, jlong addr, jlong size){
+ /* FIXME:
+ * Windows only provides readiness status of memory pages
+ * by VirtualQuery(EX), seems not enough to support this
+ * function
+ * */
+ return JNI_FALSE;
+ }
+
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSMemory_flushImpl
+ (JNIEnv * env, jobject thiz, jlong addr, jlong size){
+ return (jint)FlushViewOfFile((void *)addr, (SIZE_T)size);
+ }
Modified: incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/hynio.def
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/hynio.def?rev=376688&r1=376687&r2=376688&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/hynio.def (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/hynio.def Fri Feb 10
05:56:29 2006
@@ -5,15 +5,26 @@
.text EXECUTE READ
EXPORTS
+ 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
Modified: incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/makefile
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/makefile?rev=376688&r1=376687&r2=376688&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/makefile (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/nio/makefile Fri Feb 10
05:56:29 2006
@@ -46,7 +46,7 @@
VIRTFILES1 = hynio.res
-SYSLIBFILES1 = ws2_32.lib Iphlpapi.lib
+SYSLIBFILES1 = ws2_32.lib Iphlpapi.lib Mswsock.lib
MDLLIBFILES1 = ..\lib\hycommon.lib ..\lib\hysig.lib ..\lib\hyzip.lib ..\lib\hyzlib.lib
MDLLIBFILES2 = ..\lib\hypool.lib ..\lib\hyfdlibm.lib ..\lib\hythr.lib ..\lib\vmi.lib
Modified: incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/port/hyfile.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/port/hyfile.c?rev=376688&r1=376687&r2=376688&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/port/hyfile.c (original)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/win.IA32/port/hyfile.c Fri Feb 10
05:56:29 2006
@@ -1,4 +1,4 @@
-/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1991, 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.
@@ -539,7 +539,7 @@
I_32 error;
lowerOffset = (DWORD) (offset & 0xFFFFFFFF);
- upperOffset = (DWORD) (offset >> 32);
+ upperOffset = (DWORD) ((offset >> 32) & 0x7FFFFFFF);
if ((whence < HySeekSet) || (whence > HySeekEnd))
{
@@ -904,7 +904,7 @@
I_32 lowValue, highValue;
lowValue = (I_32) (newLength & 0xFFFFFFFF);
- highValue = (I_32) (newLength >> 32);
+ highValue = (I_32) ((newLength >> 32) & 0x7FFFFFFF);
result = SetFilePointer ((HANDLE) fd, lowValue, &highValue, FILE_BEGIN);
error = GetLastError ();
|