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 2011/04/12 13:53:14 UTC

svn commit: r1091379 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ native/include/acr/ native/os/unix/ native/shared/ test/org/apache/commons/runtime/

Author: mturk
Date: Tue Apr 12 11:53:14 2011
New Revision: 1091379

URL: http://svn.apache.org/viewvc?rev=1091379&view=rev
Log:
Implement few basic Memory/Pointer methods

Added:
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMemory.java   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
    commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c
    commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
    commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
    commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer.java?rev=1091379&r1=1091378&r2=1091379&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer.java Tue Apr 12 11:53:14 2011
@@ -25,9 +25,10 @@ package org.apache.commons.runtime;
 final class ConstPointer extends Pointer
 {
 
-    private ConstPointer()
+    public ConstPointer()
     {
-        // No instance
+        POINTER = 0L;
+        PLENGTH = 0L;
     }
 
     /*

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java?rev=1091379&r1=1091378&r2=1091379&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java Tue Apr 12 11:53:14 2011
@@ -69,7 +69,7 @@ public final class Memory
         // No Instance
     }
 
-    private static native Pointer nullp0();
+    private static native Pointer alloc0();
     /**
      * Create a new {@code null Pointer}.
      *
@@ -124,9 +124,9 @@ public final class Memory
     public static Pointer malloc()
         throws OutOfMemoryError
     {
-        Pointer p = nullp0();
+        Pointer p = alloc0();
         if (p == null)
-            throw new OutOfMemoryError("Memory alloc failed");
+            throw new OutOfMemoryError("Memory allocation failed");
         return p;
     }
 
@@ -156,8 +156,8 @@ public final class Memory
     public static native Pointer calloc(long size)
         throws OutOfMemoryError, IllegalArgumentException;
 
-    private static native void realloc0(Pointer ptr, long size)
-        throws OutOfMemoryError, RuntimeException;
+    private static native long realloc0(long addr, long size)
+        throws RuntimeException;
     /**
      * Change the size of memory block pointed by {@code ptr}.
      * <p>
@@ -179,8 +179,11 @@ public final class Memory
     {
         if (size < 1L)
             throw new IllegalArgumentException();
-
-        realloc0(ptr, size);
+        long p = realloc0(ptr.POINTER, size);
+        if (p == 0L)
+            throw new OutOfMemoryError("Memory re-allocation failed");
+        ptr.POINTER = p;
+        ptr.PLENGTH = size;
     }
 
     private static native int peek0(long addr);
@@ -224,7 +227,7 @@ public final class Memory
             throw new NullPointerException();
         else if (index < 0L || index >= ptr.PLENGTH)
             throw new IndexOutOfBoundsException();
-        else if (ptr.ISCONST)
+        else if (ptr.isConst())
             throw new UnsupportedOperationException();
         poke0(ptr.POINTER + index, value);
     }
@@ -268,7 +271,7 @@ public final class Memory
             throw new NullPointerException();
         if (offset + size > src.PLENGTH)
             throw new IndexOutOfBoundsException();
-        if (src.ISCONST)
+        if (src.isConst())
             return slice1(src.POINTER + offset, size);
         else
             return slice0(src.POINTER + offset, size);
@@ -349,7 +352,7 @@ public final class Memory
             throw new NullPointerException();
         if (srcPos < 0L || dstPos < 0L || length < 1L)
             throw new IllegalArgumentException();
-        if (dst.ISCONST)
+        if (dst.isConst())
             throw new UnsupportedOperationException();
         if (srcPos + length > src.PLENGTH)
             throw new IndexOutOfBoundsException();
@@ -396,7 +399,7 @@ public final class Memory
             throw new NullPointerException();
         if (srcPos < 0L || dstPos < 0L || length < 1L)
             throw new IllegalArgumentException();
-        if (dst.ISCONST)
+        if (dst.isConst())
             throw new UnsupportedOperationException();
         if (srcPos + length > src.PLENGTH)
             throw new IndexOutOfBoundsException();
@@ -433,7 +436,7 @@ public final class Memory
             throw new NullPointerException();
         if (offset < 0L || length < 1L)
             throw new IllegalArgumentException();
-        if (ptr.ISCONST)
+        if (ptr.isConst())
             throw new UnsupportedOperationException();
         if (offset + length > ptr.PLENGTH)
             throw new IndexOutOfBoundsException();
@@ -469,7 +472,7 @@ public final class Memory
             throw new NullPointerException();
         if (offset < 0L || length < 1L)
             throw new IllegalArgumentException();
-        if (ptr.ISCONST)
+        if (ptr.isConst())
             throw new UnsupportedOperationException();
         if (offset + length > ptr.PLENGTH)
             throw new IndexOutOfBoundsException();
@@ -1075,7 +1078,7 @@ public final class Memory
             throw new ArrayIndexOutOfBoundsException();
         if (dstPos + length > dst.PLENGTH)
             throw new IndexOutOfBoundsException();
-        if (dst.ISCONST)
+        if (dst.isConst())
             throw new UnsupportedOperationException();
         pcpy0(src, srcPos, dst.POINTER + dstPos, length);
     }
@@ -1116,7 +1119,7 @@ public final class Memory
             throw new ArrayIndexOutOfBoundsException();
         if (((dstPos + length) * 2) > dst.PLENGTH)
             throw new IndexOutOfBoundsException();
-        if (dst.ISCONST)
+        if (dst.isConst())
             throw new UnsupportedOperationException();
         pcpy1(src, srcPos, dst.POINTER + dstPos * 2, length);
     }
@@ -1157,7 +1160,7 @@ public final class Memory
             throw new ArrayIndexOutOfBoundsException();
         if (((dstPos + length) * 2) > dst.PLENGTH)
             throw new IndexOutOfBoundsException();
-        if (dst.ISCONST)
+        if (dst.isConst())
             throw new UnsupportedOperationException();
         pcpy2(src, srcPos, dst.POINTER + dstPos * 2, length);
     }
@@ -1198,7 +1201,7 @@ public final class Memory
             throw new ArrayIndexOutOfBoundsException();
         if (((dstPos + length) * 4) > dst.PLENGTH)
             throw new IndexOutOfBoundsException();
-        if (dst.ISCONST)
+        if (dst.isConst())
             throw new UnsupportedOperationException();
         pcpy3(src, srcPos, dst.POINTER + dstPos * 4, length);
     }
@@ -1239,7 +1242,7 @@ public final class Memory
             throw new ArrayIndexOutOfBoundsException();
         if (((dstPos + length) * 8) > dst.PLENGTH)
             throw new IndexOutOfBoundsException();
-        if (dst.ISCONST)
+        if (dst.isConst())
             throw new UnsupportedOperationException();
         pcpy4(src, srcPos, dst.POINTER + dstPos * 8, length);
     }
@@ -1280,7 +1283,7 @@ public final class Memory
             throw new ArrayIndexOutOfBoundsException();
         if (((dstPos + length) * 4) > dst.PLENGTH)
             throw new IndexOutOfBoundsException();
-        if (dst.ISCONST)
+        if (dst.isConst())
             throw new UnsupportedOperationException();
         pcpy5(src, srcPos, dst.POINTER + dstPos * 4, length);
     }
@@ -1321,7 +1324,7 @@ public final class Memory
             throw new ArrayIndexOutOfBoundsException();
         if (((dstPos + length) * 8) > dst.PLENGTH)
             throw new IndexOutOfBoundsException();
-        if (dst.ISCONST)
+        if (dst.isConst())
             throw new UnsupportedOperationException();
         pcpy6(src, srcPos, dst.POINTER + dstPos * 8, length);
     }
@@ -1362,7 +1365,7 @@ public final class Memory
             throw new ArrayIndexOutOfBoundsException();
         if (dstPos + length > dst.PLENGTH)
             throw new IndexOutOfBoundsException();
-        if (dst.ISCONST)
+        if (dst.isConst())
             throw new UnsupportedOperationException();
         pcpy7(src, srcPos, dst.POINTER + dstPos, length);
     }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java?rev=1091379&r1=1091378&r2=1091379&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java Tue Apr 12 11:53:14 2011
@@ -62,7 +62,7 @@ public abstract class Pointer implements
      */
     public static final Pointer NULL;
     static {
-        NULL = nullptr0();
+        NULL = new ConstPointer();
     }
 
     /**

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h?rev=1091379&r1=1091378&r2=1091379&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h Tue Apr 12 11:53:14 2011
@@ -1608,6 +1608,7 @@ ACR_INLINE(DWORD) AcrNetOsError()
 #define ACR_THROW_OS_ERROR(CL)  AcrThrowException(env, (CL), ACR_GET_OS_ERROR())
 #endif
 #define ACR_THROW_MSG(CL, MS)   AcrThrow(env, (CL), MS)
+#define ACR_THROW_EXCEPTION(CL) AcrThrow(env, (CL), AcrExceptionDescription())
 
 #ifdef __cplusplus
 extern "C" {

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h?rev=1091379&r1=1091378&r2=1091379&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jniapi.h Tue Apr 12 11:53:14 2011
@@ -101,6 +101,8 @@ void AcrExceptionHandler(unsigned int, s
 #else
 void AcrExceptionHandler(int);
 #endif
+const char *
+AcrExceptionDescription(void);
 
 JNIEnv *
 AcrGetJNIEnv(void);

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h?rev=1091379&r1=1091378&r2=1091379&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h Tue Apr 12 11:53:14 2011
@@ -52,7 +52,7 @@
                 ((Type *)AcrRealloc(env, (Mem), sizeof(Type) * (size_t)(Size)))
 #endif
 
-#define ACR_FFREE(Mem) _pr_free((void *)(Mem))
+#define ACR_FFREE(Mem) AcrFree((void *)(Mem))
 #define ACR_MEMZERO(Type, Mem, Size)                            \
     do {                                                        \
         if ((Mem) && (Size))                                    \

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c?rev=1091379&r1=1091378&r2=1091379&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/init.c Tue Apr 12 11:53:14 2011
@@ -27,6 +27,79 @@ static volatile int    _threadkey_inited
 static pthread_mutex_t _lib_mutex  = PTHREAD_MUTEX_INITIALIZER;
 #if HAVE_THREAD_LOCAL
 ACR_THREAD acr_exc_t   acr_exception_frame = { 0, 0, 0, 0, 0, 0 };
+/*
+ * 1. Signals SIGKILL, SIGSTOP cannot be blocked.
+ * 2. Signals SIGCONT, SIGTSTP, SIGTTIN, SIGTTOU are not blocked because
+ *    dealing with these signals is dangerous.
+ * 3. Signals SIGILL, SIGABRT, SIGFPE, SIGSEGV, SIGTRAP, SIGIOT, SIGEMT,
+ *    SIGBUS, SIGSYS, SIGSTKFLT are not blocked because these are synchronous
+ *    signals, which may require immediate intervention, otherwise the
+ *    process may starve.
+ */
+static int sig_blocked[] = {
+#ifdef SIGHUP
+    SIGHUP,
+#endif
+#ifdef SIGINT
+    SIGINT,
+#endif
+#ifdef SIGQUIT
+    SIGQUIT,
+#endif
+#ifdef SIGPIPE
+    SIGPIPE,
+#endif
+#ifdef SIGALRM
+    SIGALRM,
+#endif
+#ifdef SIGTERM
+    SIGTERM,
+#endif
+#ifdef SIGUSR1
+    SIGUSR1,
+#endif
+#ifdef SIGUSR2
+    SIGUSR2,
+#endif
+#ifdef SIGCHLD
+    SIGCHLD,
+#endif
+#ifdef SIGCLD
+    SIGCLD,
+#endif
+#ifdef SIGURG
+    SIGURG,
+#endif
+#ifdef SIGIO
+    SIGIO,
+#endif
+#ifdef SIGPOLL
+    SIGPOLL,
+#endif
+#ifdef SIGXCPU
+    SIGXCPU,
+#endif
+#ifdef SIGXFSZ
+    SIGXFSZ,
+#endif
+#ifdef SIGVTALRM
+    SIGVTALRM,
+#endif
+#ifdef SIGPROF
+    SIGPROF,
+#endif
+#ifdef SIGPWR
+    SIGPWR,
+#endif
+#ifdef SIGLOST
+    SIGLOST,
+#endif
+#ifdef SIGWINCH
+    SIGWINCH,
+#endif
+    -1
+};
+
 #endif
 
 typedef struct tlsd_t
@@ -111,6 +184,30 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
         return JNI_ERR;
     if (AcrInitCoreClasses(env) != 0)
         return JNI_ERR;
+#if HAVE_THREAD_LOCAL
+    {
+        struct sigaction act;
+        int i;
+        memset(&act, 0, sizeof(struct sigaction));
+        sigemptyset(&act.sa_mask);
+        act.sa_handler = AcrExceptionHandler;
+        act.sa_flags   = 0;
+#ifdef SA_INTERRUPT
+        act.sa_flags |= SA_INTERRUPT;
+#endif
+        for (i = 0; sig_blocked[i] > 0; i++) {
+            /* Block most signals during SIGSEGV handling
+             */
+            sigaddset(&act.sa_mask, sig_blocked[i]);
+        }
+        /* Handle SIGSEGV signal
+         */
+        sigaction(SIGSEGV, &act, (struct sigaction *)0);
+#if defined(HPUX11) || defined(DARWIN)
+        sigaction(SIGBUS,  &act, (struct sigaction *)0);
+#endif
+    }        
+#endif
     return JNI_VERSION_1_4;
 }
 
@@ -170,11 +267,24 @@ void AcrExceptionHandler(int sig)
         }
     }    
 }
+const char *
+AcrExceptionDescription()
+{
+    return strsignal(acr_exception_frame.code);
+}
+
 #else
 void AcrExceptionHandler(int sig)
 {
     /* Not implemented */
 }
+
+const char *
+AcrExceptionDescription()
+{
+    return 0;
+}
+
 #endif
 
 #if defined(__GNUC__) || defined(__SUNPRO_C)

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=1091379&r1=1091378&r2=1091379&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Tue Apr 12 11:53:14 2011
@@ -221,9 +221,9 @@ AcrLoadRuntimeClasses(JNI_STDENV)
 {
     ACR_CLASS_LOAD(Callback);
     ACR_CLASS_LOPT(Unsafe);
-    ACR_CLASS_LOPT(ConstPointer);
-    ACR_CLASS_LOPT(HeapPointer);
-    ACR_CLASS_LOPT(FileDescriptor);
+    ACR_CLASS_LOAD(ConstPointer);
+    ACR_CLASS_LOAD(HeapPointer);
+    ACR_CLASS_LOAD(FileDescriptor);
 
 #ifdef WIN32
 
@@ -285,6 +285,10 @@ AcrLoadClass(JNI_STDENV, JAVA_C_ID *claz
         /* Exception has been thrown
          * We could clear the exception here.
          */
+#if defined(DEBUG) || defined(_DEBUG)
+        fprintf(stderr, "Cannot find %s\n", clazz->n);
+        (*env)->ExceptionDescribe(env);
+#endif
         goto failed;
     }
     clazz->i = (jclass)(*env)->NewGlobalRef(env, c);
@@ -299,6 +303,10 @@ AcrLoadClass(JNI_STDENV, JAVA_C_ID *claz
         snprintf(an, ACR_SBUFF_SIZ, "[L%s;", clazz->n);
         c = (jobject)(*env)->FindClass(env, an);
         if (c == 0) {
+#if defined(DEBUG) || defined(_DEBUG)
+            fprintf(stderr, "Cannot find %s\n", an);
+            (*env)->ExceptionDescribe(env);
+#endif
             goto failed;
         }
         clazz->a = (jclass)(*env)->NewGlobalRef(env, c);

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/memory.c?rev=1091379&r1=1091378&r2=1091379&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/memory.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/memory.c Tue Apr 12 11:53:14 2011
@@ -241,3 +241,93 @@ AcrWcsdup(JNI_STDENV, const wchar_t *str
         AcrMemoryAbort(env, ACR_ENOMEM, wcslen(str) * sizeof(wchar_t), 0, 0, 0);
     return rv;
 }
+
+ACR_JNI_EXPORT(jobject, Memory, alloc0)(JNI_STDARGS)
+{
+    return AcrNewHeapPointer(env, 0, 0);
+}
+
+ACR_JNI_EXPORT(jobject, Memory, malloc)(JNI_STDARGS, jlong siz)
+{
+    jobject ptr = 0;
+    void   *mem;
+    jlong   sza = ACR_ALIGN_DEFAULT(siz);
+
+    if (sza < 1 || sza > SIZE_T_MAX) {
+        ACR_THROW(ACR_EX_EINVAL, 0);
+        return 0;
+    }
+    mem = malloc((size_t)sza);
+    if (mem != 0) {
+        /* Create the HeapPointer class.
+         */
+        ptr = AcrNewHeapPointer(env, mem, (size_t)siz);
+        if (ptr == 0)
+            free(mem);
+    }
+    return ptr;
+}
+
+ACR_JNI_EXPORT(jobject, Memory, calloc)(JNI_STDARGS, jlong siz)
+{
+    jobject ptr = 0;
+    void   *mem;
+    jlong   sza = ACR_ALIGN_DEFAULT(siz);
+
+    if (sza < 1 || sza > SIZE_T_MAX) {
+        ACR_THROW(ACR_EX_EINVAL, 0);
+        return 0;
+    }
+    mem = calloc(1, (size_t)sza);
+    if (mem != 0) {
+        /* Create the HeapPointer class.
+         */
+        ptr = AcrNewHeapPointer(env, mem, (size_t)siz);
+        if (ptr == 0)
+            free(mem);
+    }
+    return ptr;
+}
+
+ACR_JNI_EXPORT(jlong, Memory, realloc0)(JNI_STDARGS, jlong ptr, jlong siz)
+{
+    void   *mem = J2P(ptr, void *);
+    jlong   sza = ACR_ALIGN_DEFAULT(siz);
+
+    if (sza < 1 || sza > SIZE_T_MAX) {
+        ACR_THROW(ACR_EX_EINVAL, 0);
+        return 0;
+    }
+    if (mem == 0)
+        mem = malloc((size_t)sza);
+    else
+        mem = realloc(mem, (size_t)sza);
+    return P2J(mem);
+}
+
+ACR_JNI_EXPORT(jint, Memory, peek0)(JNI_STDARGS, jlong a)
+{
+    jint rv = -1;
+
+    __SEH_TRY
+    {
+        rv = *(J2P(a, unsigned char *));
+    }
+    __SEH_CATCH
+    {
+        ACR_THROW_EXCEPTION(ACR_EX_ERUNTIME);
+    }
+    return rv;
+}
+
+ACR_JNI_EXPORT(void, Memory, poke0)(JNI_STDARGS, jlong a, jint v)
+{
+    __SEH_TRY
+    {
+        *(J2P(a, unsigned char *)) = (unsigned char)(v & 0xFF);
+    }
+    __SEH_CATCH
+    {
+        ACR_THROW_EXCEPTION(ACR_EX_ERUNTIME);
+    }
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c?rev=1091379&r1=1091378&r2=1091379&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Tue Apr 12 11:53:14 2011
@@ -75,7 +75,7 @@ ACR_CLASS_DTOR(HeapPointer)
 }
 
 jobject
-AcrNewGenericPointer(JNI_STDENV, void *ptr, size_t len)
+AcrNewHeapPointer(JNI_STDENV, void *ptr, size_t len)
 {
     jobject po;
 

Added: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMemory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMemory.java?rev=1091379&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMemory.java (added)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMemory.java Tue Apr 12 11:53:14 2011
@@ -0,0 +1,42 @@
+/* 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 org.testng.annotations.*;
+import org.testng.Assert;
+import java.io.IOException;
+
+public class TestMemory
+{
+
+
+    @Test(groups = { "private" })
+    public void malloc()
+    {
+        Pointer p = Memory.malloc();
+        Assert.assertNotNull(p);
+    }
+
+    @Test(groups = { "private" }, expectedExceptions={ RuntimeException.class, NullPointerException.class })
+    public void sigsegv()
+    {
+        Pointer p = Memory.malloc();
+        Assert.assertNotNull(p);
+        Memory.poke(p, 0, 1);
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestMemory.java
------------------------------------------------------------------------------
    svn:eol-style = native