[jboss-cvs] JBoss Messaging SVN: r4774 - in trunk: native/src and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Aug 5 16:55:57 EDT 2008
Author: clebert.suconic at jboss.com
Date: 2008-08-05 16:55:57 -0400 (Tue, 05 Aug 2008)
New Revision: 4774
Added:
trunk/native/src/Version.h
Modified:
trunk/native/bin/libJBMLibAIO32.so
trunk/native/bin/libJBMLibAIO64.so
trunk/native/src/AIOController.h
trunk/native/src/AsyncFile.cpp
trunk/native/src/AsyncFile.h
trunk/native/src/LibAIOController.cpp
trunk/native/src/Makefile.am
trunk/native/src/org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl.h
trunk/src/main/org/jboss/messaging/core/asyncio/AsynchronousFile.java
trunk/src/main/org/jboss/messaging/core/asyncio/impl/AsynchronousFileImpl.java
trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/MultiThreadWriteNativeTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/SingleThreadWriteNativeTest.java
Log:
Native tweaks (wiring method size and adding version check)
Modified: trunk/native/bin/libJBMLibAIO32.so
===================================================================
(Binary files differ)
Modified: trunk/native/bin/libJBMLibAIO64.so
===================================================================
(Binary files differ)
Modified: trunk/native/src/AIOController.h
===================================================================
--- trunk/native/src/AIOController.h 2008-08-05 12:57:26 UTC (rev 4773)
+++ trunk/native/src/AIOController.h 2008-08-05 20:55:57 UTC (rev 4774)
@@ -43,7 +43,6 @@
*/
void log(THREAD_CONTEXT threadContext, short level, const char * message);
- int fileHandle;
AsyncFile fileOutput;
void destroy(THREAD_CONTEXT context);
Modified: trunk/native/src/AsyncFile.cpp
===================================================================
--- trunk/native/src/AsyncFile.cpp 2008-08-05 12:57:26 UTC (rev 4773)
+++ trunk/native/src/AsyncFile.cpp 2008-08-05 20:55:57 UTC (rev 4774)
@@ -298,6 +298,18 @@
}
}
+long AsyncFile::getSize()
+{
+ struct stat64 statBuffer;
+
+ if (fstat64(fileHandle, &statBuffer) < 0)
+ {
+ return -1l;
+ }
+ return statBuffer.st_size;
+}
+
+
void AsyncFile::stopPoller(THREAD_CONTEXT threadContext)
{
pollerRunning = 0;
Modified: trunk/native/src/AsyncFile.h
===================================================================
--- trunk/native/src/AsyncFile.h 2008-08-05 12:57:26 UTC (rev 4773)
+++ trunk/native/src/AsyncFile.h 2008-08-05 20:55:57 UTC (rev 4774)
@@ -60,6 +60,8 @@
return fileHandle;
}
+ long getSize();
+
inline void * newBuffer(int size)
{
void * buffer = 0;
Modified: trunk/native/src/LibAIOController.cpp
===================================================================
--- trunk/native/src/LibAIOController.cpp 2008-08-05 12:57:26 UTC (rev 4773)
+++ trunk/native/src/LibAIOController.cpp 2008-08-05 20:55:57 UTC (rev 4774)
@@ -32,6 +32,7 @@
#include "AIOController.h"
#include "JNICallbackAdapter.h"
#include "AIOException.h"
+#include "Version.h"
@@ -143,40 +144,6 @@
}
}
-JNIEXPORT jobject JNICALL Java_org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl_newBuffer
- (JNIEnv * env, jobject, jlong size)
-{
- try
- {
-
- if (size % ALIGNMENT)
- {
- throwException(env, "java/lang/RuntimeException", "Buffer size needs to be aligned to 512");
- return 0;
- }
-
- void * buffer = 0;
- if (::posix_memalign(&buffer, 512, size))
- {
- throw AIOException(10, "Error on posix_memalign");
- }
- return env->NewDirectByteBuffer(buffer, size);
- }
- catch (AIOException& e)
- {
- throwException(env, "java/lang/RuntimeException", e.what());
- return 0;
- }
-}
-
-JNIEXPORT void JNICALL Java_org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl_destroyBuffer
- (JNIEnv * env, jobject, jobject jbuffer)
-{
- void * buffer = env->GetDirectBufferAddress(jbuffer);
- free(buffer);
-}
-
-
JNIEXPORT void JNICALL Java_org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl_stopPoller
(JNIEnv *env, jclass, jlong controllerAddress)
{
@@ -224,9 +191,37 @@
}
}
+
+
/** It does nothing... just return true to make sure it has all the binary dependencies */
-JNIEXPORT jboolean JNICALL Java_org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl_isNativeLoaded
+JNIEXPORT jint JNICALL Java_org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl_getNativeVersion
(JNIEnv *, jclass)
+
{
- return 1;
+ return _VERSION_NATIVE_AIO;
}
+
+
+JNIEXPORT jlong JNICALL Java_org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl_size0
+ (JNIEnv * env, jobject, jlong controllerAddress)
+{
+ try
+ {
+ AIOController * controller = (AIOController *) controllerAddress;
+
+ long size = controller->fileOutput.getSize();
+ if (size < 0)
+ {
+ throwException(env, "java/lang/RuntimeException", "native method size failed");
+ return -1l;
+ }
+ return size;
+ }
+ catch (AIOException& e)
+ {
+ throwException(env, "java/lang/RuntimeException", e.what());
+ return -1l;
+ }
+
+}
+
Modified: trunk/native/src/Makefile.am
===================================================================
--- trunk/native/src/Makefile.am 2008-08-05 12:57:26 UTC (rev 4773)
+++ trunk/native/src/Makefile.am 2008-08-05 20:55:57 UTC (rev 4774)
@@ -4,4 +4,5 @@
libJBMLibAIO_la_SOURCES = AIOController.cpp AIOController.h AIOException.h AsyncFile.cpp \
AsyncFile.h CallbackAdapter.h JAIODatatypes.h JavaUtilities.cpp \
JavaUtilities.h JNICallbackAdapter.cpp JNICallbackAdapter.h LibAIOController.cpp \
- LockClass.h org_jboss_messaging_core_persistence_impl_libaio_jni_impl_AsynchronousFileImpl.h
+ LockClass.h org_jboss_messaging_core_persistence_impl_libaio_jni_impl_AsynchronousFileImpl.h \
+ Version.h
Added: trunk/native/src/Version.h
===================================================================
--- trunk/native/src/Version.h (rev 0)
+++ trunk/native/src/Version.h 2008-08-05 20:55:57 UTC (rev 4774)
@@ -0,0 +1,5 @@
+
+#ifndef _VERSION_NATIVE_AIO
+#define _VERSION_NATIVE_AIO 10
+#endif
+
Modified: trunk/native/src/org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl.h
===================================================================
--- trunk/native/src/org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl.h 2008-08-05 12:57:26 UTC (rev 4773)
+++ trunk/native/src/org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl.h 2008-08-05 20:55:57 UTC (rev 4774)
@@ -10,6 +10,7 @@
/* Inaccessible static: log */
/* Inaccessible static: totalMaxIO */
/* Inaccessible static: loaded */
+/* Inaccessible static: EXPECTED_NATIVE_VERSION */
/*
* Class: org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl
* Method: init
@@ -20,6 +21,14 @@
/*
* Class: org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl
+ * Method: size0
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL Java_org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl_size0
+ (JNIEnv *, jobject, jlong);
+
+/*
+ * Class: org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl
* Method: write
* Signature: (JJJLjava/nio/ByteBuffer;Lorg/jboss/messaging/core/asyncio/AIOCallback;)V
*/
@@ -60,10 +69,10 @@
/*
* Class: org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl
- * Method: isNativeLoaded
- * Signature: ()Z
+ * Method: getNativeVersion
+ * Signature: ()I
*/
-JNIEXPORT jboolean JNICALL Java_org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl_isNativeLoaded
+JNIEXPORT jint JNICALL Java_org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl_getNativeVersion
(JNIEnv *, jclass);
/*
@@ -74,22 +83,6 @@
JNIEXPORT void JNICALL Java_org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl_internalPollEvents
(JNIEnv *, jclass, jlong);
-/*
- * Class: org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl
- * Method: destroyBuffer
- * Signature: (Ljava/nio/ByteBuffer;)V
- */
-JNIEXPORT void JNICALL Java_org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl_destroyBuffer
- (JNIEnv *, jobject, jobject);
-
-/*
- * Class: org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl
- * Method: newBuffer
- * Signature: (J)Ljava/nio/ByteBuffer;
- */
-JNIEXPORT jobject JNICALL Java_org_jboss_messaging_core_asyncio_impl_AsynchronousFileImpl_newBuffer
- (JNIEnv *, jobject, jlong);
-
#ifdef __cplusplus
}
#endif
Modified: trunk/src/main/org/jboss/messaging/core/asyncio/AsynchronousFile.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/asyncio/AsynchronousFile.java 2008-08-05 12:57:26 UTC (rev 4773)
+++ trunk/src/main/org/jboss/messaging/core/asyncio/AsynchronousFile.java 2008-08-05 20:55:57 UTC (rev 4774)
@@ -52,10 +52,8 @@
void fill(long position, int blocks, long size, byte fillChar);
- ByteBuffer newBuffer(long size);
+ ByteBuffer newBuffer(int size);
- void destroyBuffer(ByteBuffer buffer);
-
int getBlockSize();
String getFileName();
Modified: trunk/src/main/org/jboss/messaging/core/asyncio/impl/AsynchronousFileImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/asyncio/impl/AsynchronousFileImpl.java 2008-08-05 12:57:26 UTC (rev 4773)
+++ trunk/src/main/org/jboss/messaging/core/asyncio/impl/AsynchronousFileImpl.java 2008-08-05 20:55:57 UTC (rev 4774)
@@ -53,6 +53,8 @@
private static AtomicInteger totalMaxIO = new AtomicInteger(0);
private static boolean loaded = false;
+
+ private static int EXPECTED_NATIVE_VERSION = 10;
static void addMax(int io)
{
@@ -71,7 +73,15 @@
{
log.trace(name + " being loaded");
System.loadLibrary(name);
- return isNativeLoaded();
+ if (getNativeVersion() != EXPECTED_NATIVE_VERSION)
+ {
+ log.warn("You have a native library with a different version than expected");
+ return false;
+ }
+ else
+ {
+ return true;
+ }
}
catch (Throwable e)
{
@@ -216,8 +226,7 @@
public long size()
{
checkOpened();
- // TODO: wire this method to ftell
- return 0;
+ return size0(handler);
}
public void fill(final long position, final int blocks, final long size, final byte fillChar)
@@ -236,6 +245,18 @@
return fileName;
}
+ // Should we make this method static?
+ public ByteBuffer newBuffer(int size)
+ {
+ if (size % getBlockSize() != 0)
+ {
+ throw new RuntimeException("Buffer size needs to be aligned to 512");
+ }
+
+ return ByteBuffer.allocateDirect((int)size);
+ }
+
+
// Private
// ---------------------------------------------------------------------------------
@@ -292,6 +313,8 @@
private static native long init(String fileName, int maxIO, Logger logger);
+ private native long size0(long handle);
+
private native void write(long handle, long position, long size, ByteBuffer buffer, AIOCallback aioPackage);
private native void read(long handle, long position, long size, ByteBuffer buffer, AIOCallback aioPackage);
@@ -303,18 +326,11 @@
private static native void stopPoller(long handler);
/** A native method that does nothing, and just validate if the ELF dependencies are loaded and on the correct platform as this binary format */
- private static native boolean isNativeLoaded();
+ private static native int getNativeVersion();
/** Poll asynchrounous events from internal queues */
private static native void internalPollEvents(long handler);
- // Should we make this method static?
- public native void destroyBuffer(ByteBuffer buffer);
-
- // Should we make this method static?
- public native ByteBuffer newBuffer(long size);
-
-
// Inner classes
// -----------------------------------------------------------------------------------------
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/MultiThreadWriteNativeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/MultiThreadWriteNativeTest.java 2008-08-05 12:57:26 UTC (rev 4773)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/MultiThreadWriteNativeTest.java 2008-08-05 20:55:57 UTC (rev 4774)
@@ -206,9 +206,6 @@
log.debug(Thread.currentThread().getName() + " Rec/Sec= " + (NUMBER_OF_LINES * 1000 / (endtime-startTime)) + " total time = " + (endtime-startTime) + " number of lines=" + NUMBER_OF_LINES);
- libaio.destroyBuffer(buffer);
-
-
for (CountDownCallback callback: list)
{
assertTrue (callback.doneCalled);
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/SingleThreadWriteNativeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/SingleThreadWriteNativeTest.java 2008-08-05 12:57:26 UTC (rev 4773)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/asyncio/SingleThreadWriteNativeTest.java 2008-08-05 20:55:57 UTC (rev 4774)
@@ -166,8 +166,6 @@
assertFalse(callback.errorCalled);
}
- controller.destroyBuffer(block);
-
controller.close();
} finally
{
@@ -288,8 +286,6 @@
{
assertEquals((byte) (i % 100), bytesRead[i]);
}
-
- controller.destroyBuffer(buffer);
} finally
{
try
@@ -555,8 +551,6 @@
assertFalse(tmp.errorCalled);
}
- controller.destroyBuffer(block);
-
controller.close();
} finally
{
@@ -634,8 +628,7 @@
assertTrue(aioBlock.errorCalled);
assertFalse(aioBlock.doneCalled);
-
- controller.destroyBuffer(block);
+
} catch (Exception e)
{
throw e;
@@ -659,6 +652,26 @@
}
+ public void testSize() throws Exception
+ {
+ final AsynchronousFileImpl controller = new AsynchronousFileImpl();
+
+ final int NUMBER_LINES = 10;
+ final int SIZE = 1024;
+
+ controller.open(FILE_NAME, 1);
+
+ log.debug("Filling file");
+
+ controller.fill(0, 1, NUMBER_LINES * SIZE, (byte) 'j');
+
+ assertEquals (NUMBER_LINES * SIZE, controller.size());
+
+ controller.close();
+
+ }
+
+
private void addString(String str, ByteBuffer buffer)
{
CharBuffer charBuffer = CharBuffer.wrap(str);
More information about the jboss-cvs-commits
mailing list