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 16:47:08 UTC

svn commit: r1091437 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ native/ native/include/acr/ native/shared/

Author: mturk
Date: Tue Apr 12 14:47:07 2011
New Revision: 1091437

URL: http://svn.apache.org/viewvc?rev=1091437&view=rev
Log:
Implement copy methods. Use macros and different namings

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SlicePointer.java   (with props)
    commons/sandbox/runtime/trunk/src/main/native/shared/sliceptr.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
    commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h
    commons/sandbox/runtime/trunk/src/main/native/shared/memory.c

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=1091437&r1=1091436&r2=1091437&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 14:47:07 2011
@@ -69,7 +69,8 @@ public final class Memory
         // No Instance
     }
 
-    private static native Pointer alloc0();
+    private static native Pointer alloc0()
+        throws OutOfMemoryError;
     /**
      * Create a new {@code null Pointer}.
      *
@@ -124,10 +125,7 @@ public final class Memory
     public static Pointer malloc()
         throws OutOfMemoryError
     {
-        Pointer p = alloc0();
-        if (p == null)
-            throw new OutOfMemoryError("Memory allocation failed");
-        return p;
+        return alloc0();
     }
 
     /**
@@ -279,9 +277,6 @@ public final class Memory
 
     private static native Pointer dup0(long src, long size)
         throws OutOfMemoryError, RuntimeException;
-    private static native Pointer dup0(Pointer src, long offset, long size)
-        throws IndexOutOfBoundsException, OutOfMemoryError,
-               RuntimeException;
     /**
      * Creates a new {@link Pointer} object whose content is a duplicated
      * subsequence of a {@code src} memory address.
@@ -479,7 +474,7 @@ public final class Memory
         set0(ptr.POINTER + offset, length, val);
     }
 
-    private static native byte[] array0(long ptr, int length)
+    private static native byte[] toByteArray0(long ptr, int length)
         throws IndexOutOfBoundsException, OutOfMemoryError;
     /**
      * Return the {@code ptr} memory area from {@code src} to {@code byte} array.
@@ -508,10 +503,10 @@ public final class Memory
         if (offset + length > ptr.PLENGTH)
             throw new IndexOutOfBoundsException();
 
-        return array0(ptr.POINTER + offset, length);
+        return toByteArray0(ptr.POINTER + offset, length);
     }
 
-    private static native char[] array1(long ptr, int length)
+    private static native char[] toCharArray0(long ptr, int length)
         throws IndexOutOfBoundsException, OutOfMemoryError;
     /**
      * Return the {@code ptr} memory area from {@code src} to {@code char} array.
@@ -540,10 +535,10 @@ public final class Memory
         if (((offset + length) * 2) > ptr.PLENGTH)
             throw new IndexOutOfBoundsException();
 
-        return array1(ptr.POINTER + offset * 2, length);
+        return toCharArray0(ptr.POINTER + offset * 2, length);
     }
 
-    private static native short[] array2(long ptr, int length)
+    private static native short[] toShortArray0(long ptr, int length)
         throws IndexOutOfBoundsException, OutOfMemoryError;
     /**
      * Return the {@code ptr} memory area from {@code src} to {@code short} array.
@@ -572,10 +567,10 @@ public final class Memory
         if (((offset + length) * 2) > ptr.PLENGTH)
             throw new IndexOutOfBoundsException();
 
-        return array2(ptr.POINTER + offset * 2, length);
+        return toShortArray0(ptr.POINTER + offset * 2, length);
     }
 
-    private static native int[] array3(long ptr, int length)
+    private static native int[] toIntArray0(long ptr, int length)
         throws IndexOutOfBoundsException, OutOfMemoryError;
     /**
      * Return the {@code ptr} memory area from {@code src} to {@code int} array.
@@ -593,7 +588,7 @@ public final class Memory
      * @throws NullPointerException if {@code ptr} is {@code null}.
      * @throws OutOfMemoryError if memory cannot be dipicated.
      */
-    public static int[] toIntegerArray(Pointer ptr, long offset, int length)
+    public static int[] toIntArray(Pointer ptr, long offset, int length)
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException, OutOfMemoryError
     {
@@ -604,10 +599,10 @@ public final class Memory
         if (((offset + length) * 4) > ptr.PLENGTH)
             throw new IndexOutOfBoundsException();
 
-        return array3(ptr.POINTER + offset * 4, length);
+        return toIntArray0(ptr.POINTER + offset * 4, length);
     }
 
-    private static native long[] array4(long ptr, int length)
+    private static native long[] toLongArray0(long ptr, int length)
         throws IndexOutOfBoundsException, OutOfMemoryError;
     /**
      * Return the {@code ptr} memory area from {@code src} to
@@ -637,10 +632,10 @@ public final class Memory
         if (((offset + length) * 8) > ptr.PLENGTH)
             throw new IndexOutOfBoundsException();
 
-        return array4(ptr.POINTER + offset * 8, length);
+        return toLongArray0(ptr.POINTER + offset * 8, length);
     }
 
-    private static native float[] array5(long ptr, int length)
+    private static native float[] toFloatArray0(long ptr, int length)
         throws IndexOutOfBoundsException, OutOfMemoryError;
     /**
      * Return the {@code ptr} memory area from {@code src} to
@@ -670,10 +665,10 @@ public final class Memory
         if (((offset + length) * 4) > ptr.PLENGTH)
             throw new IndexOutOfBoundsException();
 
-        return array5(ptr.POINTER + offset * 4, length);
+        return toFloatArray0(ptr.POINTER + offset * 4, length);
     }
 
-    private static native double[] array6(long ptr, int length)
+    private static native double[] toDoubleArray0(long ptr, int length)
         throws IndexOutOfBoundsException, OutOfMemoryError;
     /**
      * Return the {@code ptr} memory area from {@code src} to
@@ -703,43 +698,11 @@ public final class Memory
         if (((offset + length) * 8) > ptr.PLENGTH)
             throw new IndexOutOfBoundsException();
 
-        return array6(ptr.POINTER + offset * 8, length);
+        return toDoubleArray0(ptr.POINTER + offset * 8, length);
     }
 
-    private static native boolean[] array7(long ptr, int length)
-        throws IndexOutOfBoundsException, OutOfMemoryError;
-    /**
-     * Return the {@code ptr} memory area from {@code src} to {@code boolean} array.
-     *
-     * @param ptr {@code Pointer} whose content to use.
-     * @param offset starting position in the memory.
-     * @param length the number of bytes use.
-     * @return new {@code byte} array with values from {@code src} memory area.
-     *
-     * @throws IllegalArgumentException if the {@code offset}
-     *          is {@code negative} or {@code length}
-     *          is {@code zero}.
-     * @throws IndexOutOfBoundsException if the operation would cause
-     *          access of data outside allocated memory bounds.
-     * @throws NullPointerException if {@code ptr} is {@code null}.
-     * @throws OutOfMemoryError if memory cannot be dipicated.
-     */
-    public static boolean[] toBooleanArray(Pointer ptr, long offset, int length)
-        throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException, OutOfMemoryError
-    {
-        if (ptr == null || ptr.POINTER == 0L)
-            throw new NullPointerException();
-        if (offset < 0L || length < 1)
-            throw new IllegalArgumentException();
-        if (offset + length > ptr.PLENGTH)
-            throw new IndexOutOfBoundsException();
-
-        return array7(ptr.POINTER + offset, length);
-    }
-
-    private static native void acpy0(long src, byte[] dst,
-                                     int dstPos, int length)
+    private static native void toByteArray1(long src, byte[] dst,
+                                            int dstPos, int length)
         throws ArrayIndexOutOfBoundsException;
     /**
      * Copy the memory area from {@code src} pointer to array
@@ -773,11 +736,11 @@ public final class Memory
         if (srcPos + length > src.PLENGTH)
             throw new IndexOutOfBoundsException();
 
-        acpy0(src.POINTER + srcPos, dst, dstPos, length);
+        toByteArray1(src.POINTER + srcPos, dst, dstPos, length);
     }
 
-    private static native void acpy1(long src, char[] dst,
-                                     int dstPos, int length)
+    private static native void toCharArray1(long src, char[] dst,
+                                            int dstPos, int length)
         throws ArrayIndexOutOfBoundsException;
     /**
      * Copy the memory area from {@code src} pointer to array
@@ -811,11 +774,11 @@ public final class Memory
         if (((srcPos + length) * 2) > src.PLENGTH)
             throw new IndexOutOfBoundsException();
 
-        acpy1(src.POINTER + srcPos * 2, dst, dstPos, length);
+        toCharArray1(src.POINTER + srcPos * 2, dst, dstPos, length);
     }
 
-    private static native void acpy2(long src, short[] dst,
-                                     int dstPos, int length)
+    private static native void toShortArray1(long src, short[] dst,
+                                             int dstPos, int length)
         throws ArrayIndexOutOfBoundsException;
     /**
      * Copy the memory area from {@code src} pointer to array
@@ -849,11 +812,11 @@ public final class Memory
         if (((srcPos + length) * 2) > src.PLENGTH)
             throw new IndexOutOfBoundsException();
 
-        acpy2(src.POINTER + srcPos * 2, dst, dstPos, length);
+        toShortArray1(src.POINTER + srcPos * 2, dst, dstPos, length);
     }
 
-    private static native void acpy3(long src, int[] dst,
-                                     int dstPos, int length)
+    private static native void toIntArray1(long src, int[] dst,
+                                          int dstPos, int length)
         throws ArrayIndexOutOfBoundsException;
     /**
      * Copy the memory area from {@code src} pointer to array
@@ -887,11 +850,11 @@ public final class Memory
         if (((srcPos + length) * 4) > src.PLENGTH)
             throw new IndexOutOfBoundsException();
 
-        acpy3(src.POINTER + srcPos * 4, dst, dstPos, length);
+        toIntArray1(src.POINTER + srcPos * 4, dst, dstPos, length);
     }
 
-    private static native void acpy4(long src, long[] dst,
-                                     int dstPos, int length)
+    private static native void toLongArray1(long src, long[] dst,
+                                            int dstPos, int length)
         throws ArrayIndexOutOfBoundsException;
     /**
      * Copy the memory area from {@code src} pointer to array
@@ -925,11 +888,11 @@ public final class Memory
         if (((srcPos + length) * 8) > src.PLENGTH)
             throw new IndexOutOfBoundsException();
 
-        acpy4(src.POINTER + srcPos * 8, dst, dstPos, length);
+        toLongArray1(src.POINTER + srcPos * 8, dst, dstPos, length);
     }
 
-    private static native void acpy5(long src, float[] dst,
-                                     int dstPos, int length)
+    private static native void toFloatArray1(long src, float[] dst,
+                                             int dstPos, int length)
         throws ArrayIndexOutOfBoundsException;
     /**
      * Copy the memory area from {@code src} pointer to array
@@ -963,11 +926,11 @@ public final class Memory
         if (((srcPos + length) * 4) > src.PLENGTH)
             throw new IndexOutOfBoundsException();
 
-        acpy5(src.POINTER + srcPos * 4, dst, dstPos, length);
+        toFloatArray1(src.POINTER + srcPos * 4, dst, dstPos, length);
     }
 
-    private static native void acpy6(long src, double[] dst,
-                                     int dstPos, int length)
+    private static native void toDoubleArray1(long src, double[] dst,
+                                              int dstPos, int length)
         throws ArrayIndexOutOfBoundsException;
     /**
      * Copy the memory area from {@code src} pointer to array
@@ -1001,49 +964,11 @@ public final class Memory
         if (((srcPos + length) * 8) > src.PLENGTH)
             throw new IndexOutOfBoundsException();
 
-        acpy6(src.POINTER + srcPos * 8, dst, dstPos, length);
+        toDoubleArray1(src.POINTER + srcPos * 8, dst, dstPos, length);
     }
 
-    private static native void acpy7(long src, boolean[] dst,
-                                     int dstPos, int length)
-        throws ArrayIndexOutOfBoundsException;
-    /**
-     * Copy the memory area from {@code src} pointer to array
-     * pointed by {@code dst}.
-     *
-     * @param src source memory {@code Pointer}.
-     * @param srcPos starting position in the source memory.
-     * @param dst destination {@code array}.
-     * @param dstPos starting position in the destination array.
-     * @param length the number of bytes to be copied.
-     *
-     * @throws IllegalArgumentException if the {@code srcPos} or
-     *          {@code dstPos} is {@code negative} or {@code length}
-     *          is {@code zero}.
-     * @throws IndexOutOfBoundsException if the operation would cause
-     *          access of data outside allocated memory bounds.
-     * @throws NullPointerException if {@code src} or {@code dst} is
-     *          {@code null}.
-     */
-    public static void copy(Pointer src, long srcPos, boolean[] dst,
-                            int dstPos, int length)
-        throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException
-    {
-        if (src == null || src.POINTER == 0L)
-            throw new NullPointerException();
-        if (srcPos < 0L || dstPos < 0 || length == 0)
-            throw new IllegalArgumentException();
-        if (dstPos + length > dst.length)
-            throw new ArrayIndexOutOfBoundsException();
-        if (srcPos + length > src.PLENGTH)
-            throw new IndexOutOfBoundsException();
-
-        acpy7(src.POINTER + srcPos, dst, dstPos, length);
-    }
-
-    private static native void pcpy0(byte[] src, int srcPos, long dst,
-                                     int length)
+    private static native void fromByteArray0(byte[] src, int srcPos, long dst,
+                                              int length)
         throws ArrayIndexOutOfBoundsException;
     /**
      * Copy the array pointed by {@code src} to the memory area
@@ -1080,11 +1005,11 @@ public final class Memory
             throw new IndexOutOfBoundsException();
         if (dst.isConst())
             throw new UnsupportedOperationException();
-        pcpy0(src, srcPos, dst.POINTER + dstPos, length);
+        fromByteArray0(src, srcPos, dst.POINTER + dstPos, length);
     }
 
-    private static native void pcpy1(char[] src, int srcPos, long dst,
-                                     int length)
+    private static native void fromCharArray0(char[] src, int srcPos, long dst,
+                                              int length)
         throws ArrayIndexOutOfBoundsException;
     /**
      * Copy the array pointed by {@code src} to the memory area
@@ -1121,11 +1046,11 @@ public final class Memory
             throw new IndexOutOfBoundsException();
         if (dst.isConst())
             throw new UnsupportedOperationException();
-        pcpy1(src, srcPos, dst.POINTER + dstPos * 2, length);
+        fromCharArray0(src, srcPos, dst.POINTER + dstPos * 2, length);
     }
 
-    private static native void pcpy2(short[] src, int srcPos, long dst,
-                                     int length)
+    private static native void fromShortArray0(short[] src, int srcPos, long dst,
+                                               int length)
         throws ArrayIndexOutOfBoundsException;
     /**
      * Copy the array pointed by {@code src} to the memory area
@@ -1162,11 +1087,11 @@ public final class Memory
             throw new IndexOutOfBoundsException();
         if (dst.isConst())
             throw new UnsupportedOperationException();
-        pcpy2(src, srcPos, dst.POINTER + dstPos * 2, length);
+        fromShortArray0(src, srcPos, dst.POINTER + dstPos * 2, length);
     }
 
-    private static native void pcpy3(int[] src, int srcPos, long dst,
-                                     int length)
+    private static native void fromIntArray0(int[] src, int srcPos, long dst,
+                                             int length)
         throws ArrayIndexOutOfBoundsException;
     /**
      * Copy the array pointed by {@code src} to the memory area
@@ -1203,11 +1128,11 @@ public final class Memory
             throw new IndexOutOfBoundsException();
         if (dst.isConst())
             throw new UnsupportedOperationException();
-        pcpy3(src, srcPos, dst.POINTER + dstPos * 4, length);
+        fromIntArray0(src, srcPos, dst.POINTER + dstPos * 4, length);
     }
 
-    private static native void pcpy4(long[] src, int srcPos, long dst,
-                                     int length)
+    private static native void fromLongArray0(long[] src, int srcPos, long dst,
+                                              int length)
         throws ArrayIndexOutOfBoundsException;
     /**
      * Copy the array pointed by {@code src} to the memory area
@@ -1244,11 +1169,11 @@ public final class Memory
             throw new IndexOutOfBoundsException();
         if (dst.isConst())
             throw new UnsupportedOperationException();
-        pcpy4(src, srcPos, dst.POINTER + dstPos * 8, length);
+        fromLongArray0(src, srcPos, dst.POINTER + dstPos * 8, length);
     }
 
-    private static native void pcpy5(float[] src, int srcPos, long dst,
-                                     int length)
+    private static native void fromFloatArray0(float[] src, int srcPos, long dst,
+                                               int length)
         throws ArrayIndexOutOfBoundsException;
     /**
      * Copy the array pointed by {@code src} to the memory area
@@ -1285,11 +1210,11 @@ public final class Memory
             throw new IndexOutOfBoundsException();
         if (dst.isConst())
             throw new UnsupportedOperationException();
-        pcpy5(src, srcPos, dst.POINTER + dstPos * 4, length);
+        fromFloatArray0(src, srcPos, dst.POINTER + dstPos * 4, length);
     }
 
-    private static native void pcpy6(double[] src, int srcPos, long dst,
-                                     int length)
+    private static native void fromDoubleArray0(double[] src, int srcPos, long dst,
+                                                int length)
         throws ArrayIndexOutOfBoundsException;
     /**
      * Copy the array pointed by {@code src} to the memory area
@@ -1326,48 +1251,7 @@ public final class Memory
             throw new IndexOutOfBoundsException();
         if (dst.isConst())
             throw new UnsupportedOperationException();
-        pcpy6(src, srcPos, dst.POINTER + dstPos * 8, length);
-    }
-
-    private static native void pcpy7(boolean[] src, int srcPos, long dst,
-                                     int length)
-        throws ArrayIndexOutOfBoundsException;
-    /**
-     * Copy the array pointed by {@code src} to the memory area
-     * pointed by {@code dst} pointer.
-     *
-     * @param src source {@code array}.
-     * @param srcPos starting position in the source array.
-     * @param dst source memory {@code Pointer}.
-     * @param dstPos starting position in the source memory.
-     * @param length the number of bytes to be copied.
-     *
-     * @throws IllegalArgumentException if the {@code srcPos} or
-     *          {@code dstPos} is {@code negative} or {@code length}
-     *          is {@code zero}.
-     * @throws IndexOutOfBoundsException if the operation would cause
-     *          access of data outside allocated memory bounds.
-     * @throws NullPointerException if {@code src} or {@code dst} is
-     *          {@code null}.
-     * @throws UnsupportedOperationException if {@code dst} is
-     *          instance of {@code ConstPointer}.
-     */
-    public static void copy(boolean[] src, int srcPos, Pointer dst,
-                            long dstPos, int length)
-        throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException, UnsupportedOperationException
-    {
-        if (dst == null || dst.POINTER == 0L)
-            throw new NullPointerException();
-        if (srcPos < 0 || dstPos < 0L || length == 0)
-            throw new IllegalArgumentException();
-        if (dstPos + length > src.length)
-            throw new ArrayIndexOutOfBoundsException();
-        if (dstPos + length > dst.PLENGTH)
-            throw new IndexOutOfBoundsException();
-        if (dst.isConst())
-            throw new UnsupportedOperationException();
-        pcpy7(src, srcPos, dst.POINTER + dstPos, length);
+        fromDoubleArray0(src, srcPos, dst.POINTER + dstPos * 8, length);
     }
 
 }

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SlicePointer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SlicePointer.java?rev=1091437&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SlicePointer.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SlicePointer.java Tue Apr 12 14:47:07 2011
@@ -0,0 +1,59 @@
+/* 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;
+
+/**
+ * Represents the Operating System C/C++ nocleanup pointer.
+ *
+ * @since Runtime 1.0
+ */
+final class SlicePointer extends Pointer
+{
+
+    private static native void free0(long p)
+        throws Throwable;
+
+    private SlicePointer()
+    {
+        // No instance
+    }
+
+    /*
+     * Only created from JNI code.
+     */
+    private SlicePointer(long ptr, long len)
+    {
+        POINTER = ptr;
+        PLENGTH = len;
+    }
+
+    @Override
+    public final boolean isConst()
+    {
+        return false;
+    }
+
+    @Override
+    public final void free()
+        throws Throwable
+    {
+        if (POINTER == 0L)
+            throw new NullPointerException();
+        POINTER = 0L;
+    }
+}
+

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

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1091437&r1=1091436&r2=1091437&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Tue Apr 12 14:47:07 2011
@@ -100,6 +100,7 @@ LIBSOURCES=\
 	$(TOPDIR)/shared/object.c \
 	$(TOPDIR)/shared/observer.c \
 	$(TOPDIR)/shared/reflect.c \
+	$(TOPDIR)/shared/sliceptr.c \
 	$(TOPDIR)/shared/string.c \
 	$(TOPDIR)/shared/system.c \
 	$(TOPDIR)/shared/unsafe.c \

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h?rev=1091437&r1=1091436&r2=1091437&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h Tue Apr 12 14:47:07 2011
@@ -35,11 +35,15 @@ ACR_CLASS_CTOR(ConstPointer);
 ACR_CLASS_DTOR(ConstPointer);
 ACR_CLASS_CTOR(HeapPointer);
 ACR_CLASS_DTOR(HeapPointer);
+ACR_CLASS_CTOR(SlicePointer);
+ACR_CLASS_DTOR(SlicePointer);
 
 jobject
 AcrNewConstPointer(JNI_STDENV, void *ptr, size_t len);
 jobject
 AcrNewHeapPointer(JNI_STDENV, void *ptr, size_t len);
+jobject
+AcrNewSlicePointer(JNI_STDENV, void *ptr, size_t len);
 
 #ifdef __cplusplus
 }

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=1091437&r1=1091436&r2=1091437&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 14:47:07 2011
@@ -265,6 +265,9 @@ ACR_JNI_EXPORT(jobject, Memory, malloc)(
         if (ptr == 0)
             free(mem);
     }
+    else {
+        ACR_THROW(ACR_EX_ENOMEM, 0);        
+    }
     return ptr;
 }
 
@@ -286,6 +289,9 @@ ACR_JNI_EXPORT(jobject, Memory, calloc)(
         if (ptr == 0)
             free(mem);
     }
+    else {
+        ACR_THROW(ACR_EX_ENOMEM, 0);        
+    }
     return ptr;
 }
 
@@ -331,3 +337,201 @@ ACR_JNI_EXPORT(void, Memory, poke0)(JNI_
         ACR_THROW_EXCEPTION(ACR_EX_ERUNTIME);
     }
 }
+
+ACR_JNI_EXPORT(jobject, Memory, slice0)(JNI_STDARGS,
+                                        jlong src, jlong siz)
+{
+    size_t  ss = (size_t)siz;
+    char   *sp = J2P(src, char *);
+
+    /* Create the ConstPointer class.
+     */
+    return AcrNewSlicePointer(env, sp, ss);
+}
+
+ACR_JNI_EXPORT(jobject, Memory, slice1)(JNI_STDARGS,
+                                        jlong src, jlong siz)
+{
+    size_t  ss = (size_t)siz;
+    char   *sp = J2P(src, char *);
+
+    /* Create the ConstPointer class.
+     */
+    return AcrNewConstPointer(env, sp, ss);
+}
+
+ACR_JNI_EXPORT(jobject, Memory, dup0)(JNI_STDARGS,
+                                      jlong src, jlong siz)
+{
+    jobject po = 0;
+    size_t  ss = (size_t)siz;
+    void   *dp;
+    char   *sp = J2P(src, char *);
+
+    dp = malloc(ACR_ALIGN_DEFAULT(ss));
+    if (dp == 0) {
+        /* Allocation failed.
+         */
+        ACR_THROW(ACR_EX_ENOMEM, 0);
+        return 0;
+    }
+    /* Copy the original content */
+    __SEH_TRY
+    {
+        memcpy(dp, sp, ss);
+        po = AcrNewHeapPointer(env, dp, ss);
+    }
+    __SEH_CATCH
+    {
+        ACR_THROW_EXCEPTION(ACR_EX_ERUNTIME);
+    }
+    if (po == 0) {
+        /* Destroy the the memory we failed to attach
+         * to the new Pointer object.
+         */
+        free(dp);
+    }
+    return po;
+}
+
+ACR_JNI_EXPORT(void, Memory, copy0)(JNI_STDARGS, jlong src,
+                                    jlong dst, jlong size)
+{
+    size_t  cs = (size_t)size;
+    char    *d = J2P(dst, char *);
+    char    *s = J2P(src, char *);
+
+    /* Do a memcpy */
+    __SEH_TRY
+    {
+        memcpy(d, s, cs);
+    }
+    __SEH_CATCH
+    {
+        ACR_THROW_EXCEPTION(ACR_EX_ERUNTIME);
+    }
+}
+
+ACR_JNI_EXPORT(void, Memory, move0)(JNI_STDARGS, jlong src,
+                                    jlong dst, jlong size)
+{
+    size_t  cs = (size_t)size;
+    char    *d = J2P(dst, char *);
+    char    *s = J2P(src, char *);
+
+    /* Do a memmove */
+    __SEH_TRY
+    {
+        memmove(d, s, cs);
+    }
+    __SEH_CATCH
+    {
+        ACR_THROW_EXCEPTION(ACR_EX_ERUNTIME);
+    }
+}
+
+ACR_JNI_EXPORT(void, Memory, clear0)(JNI_STDARGS, jlong  dst, jlong size)
+{
+    size_t  cs = (size_t)size;
+    char    *d = J2P(dst, char *);
+
+    /* Do a memset */
+    __SEH_TRY
+    {
+        memset(d, 0, cs);
+    }
+    __SEH_CATCH
+    {
+        ACR_THROW_EXCEPTION(ACR_EX_ERUNTIME);
+    }
+}
+
+ACR_JNI_EXPORT(void, Memory, cleanse0)(JNI_STDARGS, jlong  dst, jlong size)
+{
+    size_t  cs = (size_t)size;
+    char    *d = J2P(dst, char *);
+
+    /* Do a memset */
+    __SEH_TRY
+    {
+        AcrMemCleanse(d, cs);
+    }
+    __SEH_CATCH
+    {
+        ACR_THROW_EXCEPTION(ACR_EX_ERUNTIME);
+    }
+}
+
+ACR_JNI_EXPORT(void, Memory, set0)(JNI_STDARGS, jlong dst,
+                                   jlong size, jint c)
+{
+    size_t  cs = (size_t)size;
+    char    *d = J2P(dst, char *);
+
+    /* Do a memset */
+    __SEH_TRY
+    {
+        memset(d, c, cs);
+    }
+    __SEH_CATCH
+    {
+        ACR_THROW_EXCEPTION(ACR_EX_ERUNTIME);
+    }
+}
+
+#define TO_SCALAR_ARRAY(Type, Name)   \
+ACR_JNI_EXPORT(j##Type##Array, Memory, to##Name##Array0)(JNI_STDARGS,       \
+                                                    jlong ptr, jint size)   \
+{                                                                           \
+    j##Type##Array oa;                                                      \
+    jsize   cs = (jsize)size;                                               \
+    j##Type *p = J2P(ptr, j##Type *);                                       \
+    oa = (*env)->New##Name##Array(env, cs);                                 \
+    if (oa != 0)                                                            \
+        (*env)->Set##Name##ArrayRegion(env, oa, 0, cs, p);                  \
+    return oa;                                                              \
+}
+
+TO_SCALAR_ARRAY(byte,   Byte)
+TO_SCALAR_ARRAY(char,   Char)
+TO_SCALAR_ARRAY(short,  Short)
+TO_SCALAR_ARRAY(int,    Int)
+TO_SCALAR_ARRAY(long,   Long)
+TO_SCALAR_ARRAY(float,  Float)
+TO_SCALAR_ARRAY(double, Double)
+
+#define SCALAR_ARRAY_CPY(Type, Name)   \
+ACR_JNI_EXPORT(void, Memory, to##Name##Array1)(JNI_STDARGS,                 \
+                                               jlong ptr,                   \
+                                               j##Type##Array dst,          \
+                                               jint off, jint len)          \
+{                                                                           \
+    j##Type *p = J2P(ptr, j##Type *);                                       \
+    (*env)->Set##Name##ArrayRegion(env, dst, (jsize)off, (jsize)len, p);    \
+}
+
+SCALAR_ARRAY_CPY(byte,   Byte)
+SCALAR_ARRAY_CPY(char,   Char)
+SCALAR_ARRAY_CPY(short,  Short)
+SCALAR_ARRAY_CPY(int,    Int)
+SCALAR_ARRAY_CPY(long,   Long)
+SCALAR_ARRAY_CPY(float,  Float)
+SCALAR_ARRAY_CPY(double, Double)
+
+#define SCALAR_ARRAY_SET(Type, Name)   \
+ACR_JNI_EXPORT(void, Memory, from##Name##Array0)(JNI_STDARGS,               \
+                                                 j##Type##Array src,        \
+                                                 jint off, jlong ptr,       \
+                                                 jint len)                  \
+{                                                                           \
+    j##Type *p = J2P(ptr, j##Type *);                                       \
+    (*env)->Get##Name##ArrayRegion(env, src, (jsize)off, (jsize)len, p);    \
+}
+
+SCALAR_ARRAY_SET(byte,   Byte)
+SCALAR_ARRAY_SET(char,   Char)
+SCALAR_ARRAY_SET(short,  Short)
+SCALAR_ARRAY_SET(int,    Int)
+SCALAR_ARRAY_SET(long,   Long)
+SCALAR_ARRAY_SET(float,  Float)
+SCALAR_ARRAY_SET(double, Double)

Added: commons/sandbox/runtime/trunk/src/main/native/shared/sliceptr.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/sliceptr.c?rev=1091437&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/sliceptr.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/sliceptr.c Tue Apr 12 14:47:07 2011
@@ -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.
+ */
+
+/*
+ *
+ * @author Mladen Turk
+ */
+
+#include "acr/pointer.h"
+#include "acr/clazz.h"
+#include "acr/memory.h"
+#include "acr/unsafe.h"
+
+J_DECLARE_CLAZZ = {
+    INVALID_FIELD_OFFSET,
+    0,
+    0,
+    0,
+    ACR_CLASS_PATH "SlicePointer"
+};
+
+J_DECLARE_M_ID(0000) = {
+    0,
+    "<init>",
+    "(JJ)V"
+};
+
+ACR_CLASS_CTOR(SlicePointer)
+{
+    int rv;
+
+    if ((rv = AcrLoadClass(env, &_clazzn, 0)) != 0)
+        return rv;
+    J_LOAD_METHOD(0000);
+    _clazzn.u = 1;
+    return 0;
+}
+
+ACR_CLASS_DTOR(SlicePointer)
+{
+    AcrUnloadClass(env, &_clazzn);
+}
+
+jobject
+AcrNewSlicePointer(JNI_STDENV, void *ptr, size_t len)
+{
+    jobject po;
+
+    if (!CLAZZ_LOADED) {
+        ACR_THROW_MSG(ACR_EX_EINSTANCE, "SlicePointer not initialized");
+        return 0;
+    }
+    po = (*env)->NewObject(env, _clazzn.i, J4MID(0000), P2J(ptr), (jlong)len);
+    if (po == 0)
+        ACR_SET_OS_ERROR(ACR_ENOMEM);
+    return po;
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/sliceptr.c
------------------------------------------------------------------------------
    svn:eol-style = native