[prev in list] [next in list] [prev in thread] [next in thread]
List: jakarta-commons-dev
Subject: svn commit: r809666 - in /commons/sandbox/runtime/trunk/src/main:
From: mturk () apache ! org
Date: 2009-08-31 17:13:07
Message-ID: 20090831171307.3C8722388902 () eris ! apache ! org
[Download RAW message or body]
Author: mturk
Date: Mon Aug 31 17:13:06 2009
New Revision: 809666
URL: http://svn.apache.org/viewvc?rev=809666&view=rev
Log:
Add initial MemoryMappedFile api
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMappedFile.java \
(with props) Modified:
commons/sandbox/runtime/trunk/src/main/native/os/unix/pmmap.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/pmmap.c
commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMappedFile.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMappedFile.java?rev=809666&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMappedFile.java \
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMappedFile.java \
Mon Aug 31 17:13:06 2009 @@ -0,0 +1,57 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.commons.runtime.io;
+
+import java.io.IOException;
+import java.util.EnumSet;
+import java.util.Vector;
+import org.apache.commons.runtime.Descriptor;
+import org.apache.commons.runtime.Pointer;
+import org.apache.commons.runtime.exception.ClosedDescriptorException;
+import org.apache.commons.runtime.exception.OperatingSystemException;
+import org.apache.commons.runtime.exception.UnsupportedOperatingSystemException;
+
+/**
+ * Represents the memory mapped file.
+ * <p>
+ * </p>
+ */
+public class MemoryMappedFile
+{
+ /*
+ * Reference to the OS memory mapped file descriptor
+ */
+ private Descriptor map;
+
+ /*
+ * List of all mapped regions to this mapped file.
+ * When the MemoryMappedFile is close all Pointer
+ * objects are invalidated
+ */
+ private Vector<Pointer> mappedRegions = new Vector<Pointer>(2);
+
+ private MemoryMappedFile()
+ {
+ // No Instance
+ }
+
+ private MemoryMappedFile(Descriptor map)
+ {
+ this.map = map;
+ }
+
+}
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMappedFile.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/pmmap.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/pmmap.c?rev=809666&r1=809665&r2=809666&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/pmmap.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/pmmap.c Mon Aug 31 17:13:06 \
2009 @@ -27,6 +27,7 @@
#include "acr_memory.h"
#include "acr_string.h"
#include "acr_descriptor.h"
+#include "acr_pointer.h"
#include "acr_file.h"
#include "acr_mmap.h"
@@ -38,9 +39,22 @@
int fd;
int flags;
acr_size_t size;
+ acr_off_t offset;
void *base;
};
+J_DECLARE_CLAZZ = {
+ NULL,
+ NULL,
+ ACR_IO_CLASS_PATH "MemoryMappedFile"
+};
+
+J_DECLARE_M_ID(0000) = {
+ NULL,
+ "<init>",
+ "(L" ACR_CLASS_PATH "Descriptor;)V"
+};
+
static int mmap_cleanup(void *map, int type, unsigned int flags)
{
int rc = 0;
@@ -184,3 +198,123 @@
rc = acr_ioh_open(map, ACR_DT_MMAP, MMAP_OWNS_FILE, mmap_cleanup);
return rc;
}
+
+ACR_DECLARE(void *) ACR_MMap(JNIEnv *_E, int map, acr_off_t offset,
+ acr_size_t size)
+{
+ acr_mmap_t *m = (acr_mmap_t *)ACR_IOH(map);
+
+ if (ACR_IOH_TYPE(map) != ACR_DT_MMAP) {
+ ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE);
+ return NULL;
+ }
+ if (IS_VALID_HANDLE(m->base)) {
+ /* Already mapped.
+ */
+ if (m->offset == offset && m->size == size) {
+ /* Return reference to existing map
+ * if this is the same region.
+ */
+ return m->base;
+ }
+ ACR_THROW_IO_IF_ERR(ACR_EEXIST);
+ return NULL;
+ }
+ m->base = mmap(NULL, size, m->flags, MAP_SHARED, m->fd, offset);
+ if (m->base == MAP_FAILED) {
+ ACR_THROW_IO_ERRNO();
+ return NULL;
+ }
+ m->offset = offset;
+ m->size = size;
+
+ return m->base;
+}
+
+ACR_DECLARE(int) ACR_MUnmap(JNIEnv *_E, int map)
+{
+ acr_mmap_t *m = (acr_mmap_t *)ACR_IOH(map);
+
+ if (ACR_IOH_TYPE(map) != ACR_DT_MMAP) {
+ ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE);
+ return ACR_EFTYPE;
+ }
+ if (IS_INVALID_HANDLE(m->base)) {
+ ACR_THROW_IO_IF_ERR(ACR_EBADF);
+ return ACR_EBADF;
+ }
+ if (munmap(m->base, m->size)) {
+ m->base = MAP_FAILED;
+ ACR_THROW_IO_ERRNO();
+ return ACR_GET_OS_ERROR();
+ }
+ m->base = MAP_FAILED;
+ m->offset = 0;
+ m->size = 0;
+
+ return 0;
+}
+
+ACR_CLASS_LDEF(io_MemoryMappedFile)
+{
+ int rv;
+
+ if ((rv = ACR_LoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS)
+ return rv;
+ J_LOAD_METHOD(0000);
+
+ return ACR_SUCCESS;
+}
+
+ACR_CLASS_UDEF(io_MemoryMappedFile)
+{
+ ACR_UnloadClass(_E, &_clazzn);
+}
+
+ACR_DECLARE(jobject) ACR_MMapFileObjectOpen(JNIEnv *_E,
+ const acr_pchar_t *fname,
+ int flags)
+{
+ jobject mapo;
+ jobject mapd;
+ int imap;
+
+ imap = ACR_MMapOpen(_E, fname, flags);
+ if (imap < 0) {
+
+ return NULL;
+ }
+ /* Create Descriptor Object */
+ mapd = ACR_DescriptorCreate(_E, ACR_DT_MMAP, imap, NULL,
+ mmap_descriptor_cleanup);
+ if (!mapd) {
+
+ return NULL;
+ }
+ mapo = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), mapd);
+ return mapo;
+}
+
+ACR_DECLARE(jobject) ACR_MMapFileObjectCreate(JNIEnv *_E,
+ int file,
+ int flags)
+{
+ jobject mapo;
+ jobject mapd;
+ int imap;
+
+ imap = ACR_MMapCreate(_E, file, flags);
+ if (imap < 0) {
+
+ return NULL;
+ }
+ /* Create Descriptor Object */
+ mapd = ACR_DescriptorCreate(_E, ACR_DT_MMAP, imap, NULL,
+ mmap_descriptor_cleanup);
+ if (!mapd) {
+
+ return NULL;
+ }
+ mapo = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), mapd);
+ return mapo;
+}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/pmmap.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/pmmap.c?rev=809666&r1=809665&r2=809666&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/pmmap.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/pmmap.c Mon Aug 31 \
17:13:06 2009 @@ -27,6 +27,7 @@
#include "acr_memory.h"
#include "acr_string.h"
#include "acr_descriptor.h"
+#include "acr_pointer.h"
#include "acr_file.h"
#include "acr_mmap.h"
@@ -40,6 +41,18 @@
void *base;
};
+J_DECLARE_CLAZZ = {
+ NULL,
+ NULL,
+ ACR_IO_CLASS_PATH "MemoryMappedFile"
+};
+
+J_DECLARE_M_ID(0000) = {
+ NULL,
+ "<init>",
+ "(L" ACR_CLASS_PATH "Descriptor;)V"
+};
+
static int mmap_cleanup(void *map, int type, unsigned int flags)
{
int rc = 0;
@@ -205,3 +218,67 @@
rc = acr_ioh_open(map, ACR_DT_MMAP, MMAP_OWNS_FILE, mmap_cleanup);
return rc;
}
+
+ACR_CLASS_LDEF(io_MemoryMappedFile)
+{
+ int rv;
+
+ if ((rv = ACR_LoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS)
+ return rv;
+ J_LOAD_METHOD(0000);
+
+ return ACR_SUCCESS;
+}
+
+ACR_CLASS_UDEF(io_MemoryMappedFile)
+{
+ ACR_UnloadClass(_E, &_clazzn);
+}
+
+ACR_DECLARE(jobject) ACR_MMapFileObjectOpen(JNIEnv *_E,
+ const acr_pchar_t *fname,
+ int flags)
+{
+ jobject mapo;
+ jobject mapd;
+ int imap;
+
+ imap = ACR_MMapOpen(_E, fname, flags);
+ if (imap < 0) {
+
+ return NULL;
+ }
+ /* Create Descriptor Object */
+ mapd = ACR_DescriptorCreate(_E, ACR_DT_MMAP, imap, NULL,
+ mmap_descriptor_cleanup);
+ if (!mapd) {
+
+ return NULL;
+ }
+ mapo = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), mapd);
+ return mapo;
+}
+
+ACR_DECLARE(jobject) ACR_MMapFileObjectCreate(JNIEnv *_E,
+ int file,
+ int flags)
+{
+ jobject mapo;
+ jobject mapd;
+ int imap;
+
+ imap = ACR_MMapCreate(_E, file, flags);
+ if (imap < 0) {
+
+ return NULL;
+ }
+ /* Create Descriptor Object */
+ mapd = ACR_DescriptorCreate(_E, ACR_DT_MMAP, imap, NULL,
+ mmap_descriptor_cleanup);
+ if (!mapd) {
+
+ return NULL;
+ }
+ mapo = (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), mapd);
+ return mapo;
+}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=809666&r1=809665&r2=809666&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Mon Aug 31 17:13:06 \
2009 @@ -381,6 +381,7 @@
ACR_CLASS_LDEC(Semaphore);
ACR_CLASS_LDEC(SharedMemory);
ACR_CLASS_LDEC(io_File);
+ACR_CLASS_LDEC(io_MemoryMappedFile);
ACR_DECLARE(int) ACR_LoadRuntimeClasses(JNIEnv *_E)
{
@@ -396,6 +397,7 @@
ACR_CLASS_LRUN(Semaphore);
ACR_CLASS_LRUN(SharedMemory);
ACR_CLASS_LRUN(io_File);
+ ACR_CLASS_LRUN(io_MemoryMappedFile);
#ifdef WIN32
#endif
@@ -417,6 +419,7 @@
ACR_CLASS_URUN(Semaphore);
ACR_CLASS_URUN(SharedMemory);
ACR_CLASS_URUN(io_File);
+ ACR_CLASS_URUN(io_MemoryMappedFile);
#ifdef WIN32
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic