activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r883369 - in /activemq/sandbox/activemq-apollo/activemq-syscall/src/main: java/org/apache/activemq/syscall/ java/org/apache/activemq/syscall/jni/ java/org/apache/activemq/syscall/util/ native-package/src/
Date Mon, 23 Nov 2009 15:31:41 GMT
Author: chirino
Date: Mon Nov 23 15:31:40 2009
New Revision: 883369

URL: http://svn.apache.org/viewvc?rev=883369&view=rev
Log:
- enable the _GNU_SOURCE define to get teh O_DIRECT define on linux
- support aligning allocated memory


Removed:
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/util/DiskBenchmark.java
Modified:
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/NativeAllocation.java
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/CLibrary.java
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/util/IOBenchmark.java
    activemq/sandbox/activemq-apollo/activemq-syscall/src/main/native-package/src/activemq-syscall.h

Modified: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/NativeAllocation.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/NativeAllocation.java?rev=883369&r1=883368&r2=883369&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/NativeAllocation.java
(original)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/NativeAllocation.java
Mon Nov 23 15:31:40 2009
@@ -22,6 +22,7 @@
 import org.apache.activemq.syscall.jni.CLibrary;
 
 import static org.apache.activemq.syscall.jni.CLibrary.*;
+import static org.apache.activemq.syscall.jni.Posix.*;
 
 /**
  * Wraps up a a native memory allocation in a a Java object
@@ -46,16 +47,43 @@
     
     public static NativeAllocation allocate(byte[] value) {
         int size = value.length;
-        NativeAllocation rc = allocate(size);
+        NativeAllocation rc = allocate(size, false);
         memmove(rc.pointer(), value, size);
         return rc;
     }
     
     static public NativeAllocation allocate(long size) {
-        NativeAllocation rc = new NativeAllocation(calloc(size,1), size);
+        return allocate(size, true);
+    }
+    
+    static public NativeAllocation allocate(long size, boolean zero) {
+        long ptr;
+        if( zero ) {
+            ptr = calloc(size,1);
+        } else {
+            ptr = malloc(size);
+        }
+        NativeAllocation rc = new NativeAllocation(ptr, size);
         rc.allocated = 1;
         return rc;
     }        
+
+    static public NativeAllocation allocate(long size, boolean zero, long alignment) {
+        long ptrp[] = new long[1];
+        int rc = posix_memalign(ptrp, alignment, size);
+        if( rc != 0 ) {
+            if( rc == EINVAL ) {
+                throw new IllegalArgumentException("The alignment parameter is not a power
of 2 and at least as large as sizeof(void *)");
+            }
+            throw new OutOfMemoryError();
+        }
+        if( zero ) {
+            memset(ptrp[0], 0, size);
+        }
+        NativeAllocation na = new NativeAllocation(ptrp[0], size);
+        na.allocated = 1;
+        return na;
+    }        
     
     public void free() {
         // This should be thread safe as long as the JVM continues
@@ -131,4 +159,18 @@
         return new String(bytes(), encoding);
     }
 
+    public void set(byte[] data) {
+        if( data.length > length ) {
+            throw new IllegalArgumentException("data parameter is larger than the native
allocation");
+        }
+        memmove(pointer, data, data.length);
+    }
+
+    public void get(byte[] data) {
+        if( data.length < length ) {
+            throw new IllegalArgumentException("data parameter is smaller than the native
allocation");
+        }
+        memmove(data, pointer, length);
+    }
+
 }
\ No newline at end of file

Modified: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/CLibrary.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/CLibrary.java?rev=883369&r1=883368&r2=883369&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/CLibrary.java
(original)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/jni/CLibrary.java
Mon Nov 23 15:31:40 2009
@@ -18,10 +18,15 @@
 
 import org.fusesource.hawtjni.runtime.JniArg;
 import org.fusesource.hawtjni.runtime.JniClass;
+import org.fusesource.hawtjni.runtime.JniField;
 import org.fusesource.hawtjni.runtime.JniMethod;
 import org.fusesource.hawtjni.runtime.Library;
 import org.fusesource.hawtjni.runtime.MethodFlag;
 
+import static org.fusesource.hawtjni.runtime.MethodFlag.*;
+
+import static org.fusesource.hawtjni.runtime.FieldFlag.*;
+
 import static org.fusesource.hawtjni.runtime.ArgFlag.*;
 import static org.fusesource.hawtjni.runtime.Pointer.*;
 /**
@@ -34,10 +39,20 @@
     final public static Library LIBRARY = new Library("activemq-syscall", CLibrary.class);
     static {
         LIBRARY.load();
+        init();
     }
     
+    @JniMethod(flags={CONSTANT_INITIALIZER})
+    private static final native void init();
+
     final public static long NULL = 0;
     
+    @JniField(flags={CONSTANT}, conditional="defined(ENOMEM)")
+    public static int ENOMEM;
+
+    @JniField(flags={CONSTANT}, conditional="defined(EINVAL)")
+    public static int EINVAL;
+    
     @JniMethod(flags={MethodFlag.CONSTANT_GETTER})
     public static final native int errno();
 

Modified: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/util/IOBenchmark.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/util/IOBenchmark.java?rev=883369&r1=883368&r2=883369&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/util/IOBenchmark.java
(original)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/main/java/org/apache/activemq/syscall/util/IOBenchmark.java
Mon Nov 23 15:31:40 2009
@@ -49,7 +49,6 @@
 import org.apache.commons.cli.PosixParser;
 
 import static java.lang.String.*;
-import static org.apache.activemq.syscall.jni.CLibrary.*;
 import static org.apache.activemq.syscall.jni.IO.*;
 import static org.apache.activemq.util.cli.OptionBuilder.*;
 
@@ -605,7 +604,8 @@
         @Override
         protected void init(boolean write) throws IOException {
             block = block();
-            data = NativeAllocation.allocate(block);
+            data = NativeAllocation.allocate(block.length, false, 512);
+            data.set(block);
             if( write ) {
                 int oflags =  O_CREAT | O_TRUNC | O_WRONLY;
                 int mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH;
@@ -649,7 +649,7 @@
                 @Override
                 public void onSuccess(Long result) {
                     if( next != null ) {
-                        memmove(block, data.pointer(), data.length());
+                        data.get(block);
                         next.onSuccess(block);
                     }
                     super.onSuccess(result);
@@ -695,7 +695,7 @@
         @Override
         protected void write(long offset, byte[] block) throws IOException {
             FutureCallback<Long> callback = nextCallback(null);
-            memmove(data.pointer(), block, data.length());
+            data.set(block);
             fd.write(offset, data, callback);
         }
 
@@ -710,7 +710,8 @@
         @Override
         protected void init(boolean write) throws IOException {
             block = block();
-            data = NativeAllocation.allocate(block);
+            data = NativeAllocation.allocate(block.length, false, 512);
+            data.set(block);
             if( write ) {
                 int oflags =  O_CREAT | O_TRUNC | O_WRONLY;
                 int mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH;
@@ -755,13 +756,13 @@
         @Override
         protected void read(Callback<byte[]> callback) throws IOException {
             fd.read(data);
-            memmove(block, data.pointer(), data.length());
+            data.get(block);
             callback.onSuccess(block);
         }
 
         @Override
         protected void write(byte[] block) throws IOException {
-            memmove(data.pointer(), block, data.length());
+            data.set(block);
             fd.write(data);
         }
 

Modified: activemq/sandbox/activemq-apollo/activemq-syscall/src/main/native-package/src/activemq-syscall.h
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo/activemq-syscall/src/main/native-package/src/activemq-syscall.h?rev=883369&r1=883368&r2=883369&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo/activemq-syscall/src/main/native-package/src/activemq-syscall.h
(original)
+++ activemq/sandbox/activemq-apollo/activemq-syscall/src/main/native-package/src/activemq-syscall.h
Mon Nov 23 15:31:40 2009
@@ -1,9 +1,6 @@
 #ifndef INCLUDED_ACTIVEMQ_SYSCALL_H
 #define INCLUDED_ACTIVEMQ_SYSCALL_H
 
-/* lets make sure we get the thread safe versions of the APIs */
-#define _REENTRANT 
-
 #ifdef HAVE_CONFIG_H
   /* configure based build.. we will use what it discovered about the platform */
   #include "config.h"
@@ -11,15 +8,24 @@
   /* Windows based build */
   #define HAVE_STDLIB_H 1
   #define HAVE_STRINGS_H 1
-    
-  #include <io.h>
-  
+  #define HAVE_IO_H 1
   #define bzero(ptr, len) memset(ptr, 0, len)
   #define open _open
   #define close _close 
   #define fcntl _fcntl
 #endif
 
+/* lets make sure we get the thread safe versions of the APIs */
+#ifndef _REENTRANT
+#define _REENTRANT
+#endif
+
+/* To get the linux posix extensions, consider moving
+   this into the autoconf generation */
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
 #ifdef HAVE_SYS_TYPES_H
   #include <sys/types.h>
 #endif
@@ -52,6 +58,9 @@
   #include <sys/stat.h>
 #endif
 
+#ifdef HAVE_IO_H
+  #include <io.h>
+#endif
 
 
 #include <fcntl.h>



Mime
View raw message