Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 64204 invoked from network); 1 Sep 2009 06:40:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Sep 2009 06:40:20 -0000 Received: (qmail 38890 invoked by uid 500); 1 Sep 2009 06:40:19 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 38800 invoked by uid 500); 1 Sep 2009 06:40:19 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 38790 invoked by uid 99); 1 Sep 2009 06:40:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Sep 2009 06:40:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Sep 2009 06:40:17 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 61D7A23888EC; Tue, 1 Sep 2009 06:39:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r809848 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/io/ main/native/os/unix/ main/native/os/win32/ test/org/apache/commons/runtime/ Date: Tue, 01 Sep 2009 06:39:57 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090901063957.61D7A23888EC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Tue Sep 1 06:39:56 2009 New Revision: 809848 URL: http://svn.apache.org/viewvc?rev=809848&view=rev Log: Implement map create API Added: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemoryMap.java (with props) Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMapProvider.java 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/test/org/apache/commons/runtime/TestAll.java Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMapProvider.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMapProvider.java?rev=809848&r1=809847&r2=809848&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMapProvider.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMapProvider.java Tue Sep 1 06:39:56 2009 @@ -55,6 +55,48 @@ this.map = map; } + private static native Descriptor create0(String fname, int flags) + throws IOException, SecurityException, OutOfMemoryError; + /** + * Create new MemoryMapPrivider from the abstract {@code File}. + *

+ *

+ * @param path Abstract path name of the existing file to map. + * @param mode Open mode flags. + */ + public MemoryMapProvider(File path, EnumSet mode) + throws IOException, IllegalArgumentException, OutOfMemoryError + { + int flags = FileOpenMode.bitmapOf(mode); + if (flags == 0) + throw new IllegalArgumentException(); + map = create0(path.getPath(), flags); + } + + private static native Descriptor create1(int fd, int flags) + throws IOException, SecurityException, OutOfMemoryError; + /** + * Create new MemoryMapPrivider from the esisting filr {@code Descriptor}. + *

+ *

+ * @param fd Valid file descriptor. + * @param mode Open mode flags. + */ + public MemoryMapProvider(Descriptor fd, EnumSet mode) + throws IOException, IllegalArgumentException, OutOfMemoryError, + ClosedDescriptorException + { + int flags = FileOpenMode.bitmapOf(mode); + if (flags == 0) + throw new IllegalArgumentException(); + if (fd.valid()) { + map = create1(fd.fd(), flags); + } + else { + throw new ClosedDescriptorException(); + } + } + private static native Pointer map0(int md, long offset, long size) throws IOException, IllegalArgumentException; /** 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=809848&r1=809847&r2=809848&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 Tue Sep 1 06:39:56 2009 @@ -329,6 +329,42 @@ return mapo; } +ACR_IO_EXPORT_DECLARE(jobject, MemoryMapProvider, create0)(ACR_JNISTDARGS, + jstring fname, + jint flags) +{ + + jobject mapd = NULL; + int imap; + + UNREFERENCED_O; + WITH_CSTR(fname) { + imap = ACR_MMapOpen(_E, J2S(fname), flags); + if (imap > 0) { + /* Create Descriptor Object */ + mapd = ACR_DescriptorCreate(_E, ACR_DT_MMAP, imap, NULL, + mmap_descriptor_cleanup); + } + } END_WITH_CSTR(fname); + return mapd; +} + +ACR_IO_EXPORT_DECLARE(jobject, MemoryMapProvider, create1)(ACR_JNISTDARGS, + jint fd, + jint flags) +{ + jobject mapd = NULL; + int imap; + UNREFERENCED_O; + + imap = ACR_MMapCreate(_E, fd, flags); + if (imap > 0) { + mapd = ACR_DescriptorCreate(_E, ACR_DT_MMAP, imap, NULL, + mmap_descriptor_cleanup); + } + return mapd; +} + ACR_IO_EXPORT_DECLARE(jobject, MemoryMapProvider, map0)(ACR_JNISTDARGS, jint map, jlong offset, 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=809848&r1=809847&r2=809848&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 Tue Sep 1 06:39:56 2009 @@ -370,6 +370,42 @@ return mapo; } +ACR_IO_EXPORT_DECLARE(jobject, MemoryMapProvider, create0)(ACR_JNISTDARGS, + jstring fname, + jint flags) +{ + + jobject mapd = NULL; + int imap; + + UNREFERENCED_O; + WITH_WSTR(fname) { + imap = ACR_MMapOpen(_E, J2W(fname), flags); + if (imap > 0) { + /* Create Descriptor Object */ + mapd = ACR_DescriptorCreate(_E, ACR_DT_MMAP, imap, NULL, + mmap_descriptor_cleanup); + } + } END_WITH_WSTR(fname); + return mapd; +} + +ACR_IO_EXPORT_DECLARE(jobject, MemoryMapProvider, create1)(ACR_JNISTDARGS, + jint fd, + jint flags) +{ + jobject mapd = NULL; + int imap; + UNREFERENCED_O; + + imap = ACR_MMapCreate(_E, fd, flags); + if (imap > 0) { + mapd = ACR_DescriptorCreate(_E, ACR_DT_MMAP, imap, NULL, + mmap_descriptor_cleanup); + } + return mapd; +} + ACR_IO_EXPORT_DECLARE(jobject, MemoryMapProvider, map0)(ACR_JNISTDARGS, jint map, jlong offset, Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java?rev=809848&r1=809847&r2=809848&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java (original) +++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java Tue Sep 1 06:39:56 2009 @@ -46,6 +46,7 @@ suite.addTest(TestStrings.suite()); suite.addTest(TestSemaphore.suite()); suite.addTest(TestSharedMemory.suite()); + suite.addTest(TestMemoryMap.suite()); return suite; } Added: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemoryMap.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemoryMap.java?rev=809848&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemoryMap.java (added) +++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemoryMap.java Tue Sep 1 06:39:56 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; + +import java.lang.System; +import junit.framework.*; +import java.util.EnumSet; +import org.apache.commons.runtime.io.*; +import org.apache.commons.runtime.exception.*; + +/** + * SharedMemory Test. + * + */ +public class TestMemoryMap extends TestCase +{ + + public static Test suite() { + TestSuite suite = new TestSuite(TestMemoryMap.class); + return suite; + } + + protected void setUp() + throws Exception + { + System.loadLibrary("acr"); + } + + public void testTestMemoryMapOpen() + throws Throwable + { + File f = new File("org/apache/commons/runtime/TestMemoryMap.class"); + MemoryMapProvider map = new MemoryMapProvider(f, EnumSet.of(FileOpenMode.READ)); + Pointer p = map.map(0, 128); + assertEquals("Class header [0]", (byte)0xCA, (byte)p.peek(0)); + assertEquals("Class header [1]", (byte)0xFE, (byte)p.peek(1)); + assertEquals("Class header [2]", (byte)0xBA, (byte)p.peek(2)); + assertEquals("Class header [3]", (byte)0xBE, (byte)p.peek(3)); + map.close(); + } + +} + Propchange: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemoryMap.java ------------------------------------------------------------------------------ svn:eol-style = native