You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/10/19 13:00:40 UTC
svn commit: r826633 - in /commons/sandbox/runtime/trunk/src/main/native:
Makefile.in Makefile.msc.in configure os/unix/memalign.c os/win32/memalign.c
Author: mturk
Date: Mon Oct 19 11:00:40 2009
New Revision: 826633
URL: http://svn.apache.org/viewvc?rev=826633&view=rev
Log:
Add aligned memory support
Added:
commons/sandbox/runtime/trunk/src/main/native/os/unix/memalign.c (with props)
commons/sandbox/runtime/trunk/src/main/native/os/win32/memalign.c (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/Makefile.in
commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
commons/sandbox/runtime/trunk/src/main/native/configure
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=826633&r1=826632&r2=826633&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Mon Oct 19 11:00:40 2009
@@ -128,6 +128,7 @@
$(SRCDIR)/os/unix/ios.$(OBJ) \
$(SRCDIR)/os/unix/group.$(OBJ) \
$(SRCDIR)/os/unix/user.$(OBJ) \
+ $(SRCDIR)/os/unix/memalign.$(OBJ) \
$(SRCDIR)/os/unix/mmap.$(OBJ) \
$(SRCDIR)/os/unix/mutex.$(OBJ) \
$(SRCDIR)/os/unix/pipe.$(OBJ) \
@@ -165,6 +166,7 @@
$(SRCDIR)/os/unix/ios.$(OBJ) \
$(SRCDIR)/os/unix/group.$(OBJ) \
$(SRCDIR)/os/unix/user.$(OBJ) \
+ $(SRCDIR)/os/unix/memalign.$(OBJ) \
$(SRCDIR)/os/unix/mmap.$(OBJ) \
$(SRCDIR)/os/unix/mutex.$(OBJ) \
$(SRCDIR)/os/unix/pipe.$(OBJ) \
@@ -199,6 +201,7 @@
$(SRCDIR)/os/unix/ios.$(OBJ) \
$(SRCDIR)/os/unix/group.$(OBJ) \
$(SRCDIR)/os/unix/user.$(OBJ) \
+ $(SRCDIR)/os/unix/memalign.$(OBJ) \
$(SRCDIR)/os/unix/mmap.$(OBJ) \
$(SRCDIR)/os/unix/pipe.$(OBJ) \
$(SRCDIR)/os/unix/proc.$(OBJ) \
@@ -234,6 +237,7 @@
$(SRCDIR)/os/unix/ios.$(OBJ) \
$(SRCDIR)/os/unix/group.$(OBJ) \
$(SRCDIR)/os/unix/user.$(OBJ) \
+ $(SRCDIR)/os/unix/memalign.$(OBJ) \
$(SRCDIR)/os/unix/mmap.$(OBJ) \
$(SRCDIR)/os/unix/mutex.$(OBJ) \
$(SRCDIR)/os/unix/pipe.$(OBJ) \
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=826633&r1=826632&r2=826633&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Mon Oct 19 11:00:40 2009
@@ -122,6 +122,7 @@
$(SRCDIR)/os/win32/proc.$(OBJ) \
$(SRCDIR)/os/win32/os.$(OBJ) \
$(SRCDIR)/os/win32/ios.$(OBJ) \
+ $(SRCDIR)/os/win32/memalign.$(OBJ) \
$(SRCDIR)/os/win32/mmap.$(OBJ) \
$(SRCDIR)/os/win32/module.$(OBJ) \
$(SRCDIR)/os/win32/mutex.$(OBJ) \
Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=826633&r1=826632&r2=826633&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Mon Oct 19 11:00:40 2009
@@ -891,6 +891,7 @@
have_strerror_r=0
have_mmap64=0
have_fdatasync=0
+ have_posix_memalign=0
else
have_ktmw32=0
have_off64t=1
@@ -921,6 +922,7 @@
fi
have_mmap64=`have_function mmap64`
have_fdatasync=`have_function fdatasync`
+ have_posix_memalign=`have_function posix_memalign`
fi
if [ ".$host" = ".linux" ]; then
@@ -1026,6 +1028,7 @@
#define HAVE_UCONTEXT_H `have_include ucontext`
#define HAVE_STRERROR_R $have_strerror_r
#define HAVE_MMAP64 $have_mmap64
+#define HAVE_POSIX_MEMALIGN $have_posix_memalign
#define HAVE_FDATASYNC $have_fdatasync
#define HAVE_ACCEPT4 `have_function accept4`
#define HAVE_CLOCK_GETTIME `have_function clock_gettime`
Added: commons/sandbox/runtime/trunk/src/main/native/os/unix/memalign.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/memalign.c?rev=826633&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/memalign.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/memalign.c Mon Oct 19 11:00:40 2009
@@ -0,0 +1,70 @@
+/* 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.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_memory.h"
+#include "acr_pointer.h"
+#include "acr_error.h"
+
+extern acr_size_t acr_page_size;
+/**
+ * Posix aligned memory functions
+ *
+ */
+static int aligned_pointer_cleanup(void *mem, size_t len)
+{
+ if (mem && len) {
+ free(mem);
+ return 0;
+ }
+ else {
+ return ACR_EISNULL;
+ }
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, AlignedMemory, malloc0)(ACR_JNISTDARGS,
+ jlong siz)
+{
+ jobject ptr = NULL;
+ void *mem;
+ acr_size_t ass = (acr_size_t)ACR_ALIGN(siz, acr_page_size);
+
+ UNREFERENCED_O;
+ if (ass < (acr_size_t)siz) {
+ /* Guard against faulty size value */
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EINVAL, 0);
+ return NULL;
+ }
+#if HAVE_POSIX_MEMALIGN
+ if (posix_memalign(&mem, acr_page_size, ass)) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENOMEM, ACR_GET_OS_ERROR());
+ return NULL;
+ }
+#else
+ mem = memalign(acr_page_size, ass);
+ if (!mem) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENOMEM, ACR_GET_OS_ERROR());
+ return NULL;
+ }
+#endif
+ ptr = ACR_NewBasicPointer(_E, mem, ass, aligned_pointer_cleanup);
+ if (!ptr) {
+ free(mem);
+ }
+ return ptr;
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/os/unix/memalign.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/memalign.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/memalign.c?rev=826633&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/memalign.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/memalign.c Mon Oct 19 11:00:40 2009
@@ -0,0 +1,62 @@
+/* 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.
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_memory.h"
+#include "acr_pointer.h"
+#include "acr_error.h"
+
+extern acr_size_t acr_page_size;
+/**
+ * Windows executable memory functions
+ *
+ */
+static int aligned_pointer_cleanup(void *mem, size_t len)
+{
+ if (mem && len) {
+ VirtualFree(mem, 0, MEM_RELEASE);
+ return 0;
+ }
+ else {
+ return ACR_EISNULL;
+ }
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, AlignedMemory, malloc0)(ACR_JNISTDARGS,
+ jlong siz)
+{
+ jobject ptr = NULL;
+ void *mem;
+ acr_size_t ass = (acr_size_t)ACR_ALIGN(siz, acr_page_size);
+
+ UNREFERENCED_O;
+ mem = VirtualAlloc(NULL, ass,
+ MEM_COMMIT | MEM_RESERVE,
+ PAGE_READWRITE);
+ if (mem) {
+ /* Create the Pointer class with default cleanup.
+ */
+ ptr = ACR_NewBasicPointer(_E, mem, ass, aligned_pointer_cleanup);
+ if (!ptr) {
+ VirtualFree(mem, 0, MEM_RELEASE);
+ }
+ }
+ else
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENOMEM, ACR_GET_OS_ERROR());
+ return ptr;
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/memalign.c
------------------------------------------------------------------------------
svn:eol-style = native