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 10:05:38 UTC
svn commit: r1091318 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/ native/ native/include/acr/ native/shared/
Author: mturk
Date: Tue Apr 12 08:05:37 2011
New Revision: 1091318
URL: http://svn.apache.org/viewvc?rev=1091318&view=rev
Log:
Bring back some of the old code. Method rewrite still needed.
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Const.java (with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer.java (with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/GenericPointer.java (with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java (with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java (with props)
commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h (with props)
commons/sandbox/runtime/trunk/src/main/native/shared/constptr.c (with props)
commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ReflectedFieldImpl.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ReflectedMethodImpl.java
commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Const.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Const.java?rev=1091318&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Const.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Const.java Tue Apr 12 08:05:37 2011
@@ -0,0 +1,54 @@
+/* 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 java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation that represents the const type.
+ * <p>
+ * Not very much usable except for documenting the source
+ * until {@code JSR-308} comes out. The intention is to have something
+ * like this:
+ * </p>
+ * <pre>
+ * {@code @Const} Pointer p = new MyPointer();
+ * ...
+ * use p as read only pointer.
+ * ...
+ * </pre>
+ * </p>
+ * This is currently done by explicity creating the {@code ConstPointer}
+ * </p>
+ * <pre>
+ * Pointer p = new MyConstPointer();
+ * ...
+ * use p as read only pointer.
+ * ...
+ * </pre>
+ *
+ * @since Runtime 1.0
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.PARAMETER, ElementType.TYPE})
+public @interface Const
+{
+
+}
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Const.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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=1091318&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer.java Tue Apr 12 08:05:37 2011
@@ -0,0 +1,44 @@
+/* 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++ const pointer.
+ *
+ * @since Runtime 1.0
+ */
+@Const
+final class ConstPointer extends Pointer
+{
+
+ private ConstPointer()
+ {
+ // No instance
+ ISCONST = true;
+ }
+
+ /*
+ * Only created from JNI code.
+ */
+ private ConstPointer(long ptr, long len)
+ {
+ POINTER = ptr;
+ PLENGTH = len;
+ ISCONST = true;
+ }
+
+}
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/GenericPointer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/GenericPointer.java?rev=1091318&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/GenericPointer.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/GenericPointer.java Tue Apr 12 08:05:37 2011
@@ -0,0 +1,43 @@
+/* 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++ pointer.
+ *
+ * @since Runtime 1.0
+ */
+final class GenericPointer extends Pointer
+{
+
+ private GenericPointer()
+ {
+ // No instance
+ }
+
+ /*
+ * Only created from JNI code.
+ */
+ private GenericPointer(long ptr, long len)
+ {
+ POINTER = ptr;
+ PLENGTH = len;
+ ISCONST = false;
+ }
+
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/GenericPointer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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=1091318&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java Tue Apr 12 08:05:37 2011
@@ -0,0 +1,1371 @@
+/* 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;
+
+/**
+ * Memory class.
+ * <p>
+ * <b>Warning:</b><br/>Using this class improperly may crash the running JVM.
+ * </p>
+ *
+ * @since Runtime 1.0
+ */
+public final class Memory
+{
+
+ /**
+ * Default memory alignment.
+ */
+ public static final int DEFAULT_ALIGNMENT = 8;
+
+ /** Alignment to {@code boundary} function.
+ * @return {@code int} aligned to the {@code boundary}.
+ */
+ public static final int align(int size, int boundary)
+ {
+ return ((size + (boundary - 1)) & ~(boundary - 1));
+ }
+
+ /** Alignment to default {@code boundary} function.
+ * @return {@code int} aligned to {@code 8} bytes.
+ */
+ public static final int align(int size)
+ {
+ return align(size, DEFAULT_ALIGNMENT);
+ }
+
+ /** Alignment to {@code boundary} function.
+ * @return {@code long} aligned to the {@code boundary}.
+ */
+ public static final long align(long size, int boundary)
+ {
+ return ((size + (boundary - 1)) & ~(boundary - 1));
+ }
+
+ /** Alignment to default {@code boundary} function.
+ * @return {@code long} aligned to {@code 8} bytes.
+ */
+ public static final long align(long size)
+ {
+ return align(size, DEFAULT_ALIGNMENT);
+ }
+
+
+ private Memory()
+ {
+ // No Instance
+ }
+
+ private static native Pointer nullp0();
+ /**
+ * Create a new {@code null Pointer}.
+ *
+ * <p>
+ * Creating new {@code null} pointers make sense only for
+ * using that object as a reference for methods that
+ * require a {@code Pointer} whose size is unknown at the
+ * time of the call. The method will usually fill the pointer
+ * with the valid memory block area. A typical usage of such
+ * a {code Pointer} can be explained as this:
+ * <pre>
+ *
+ * int method(void **pointer, int size)
+ * {
+ * *pointer = malloc(size + something);
+ * return something;
+ * }
+ *
+ * void *pointer;
+ * method(&pointer, 16);
+ * ...
+ * free(pointer);
+ *
+ * </pre>
+ * The example code uses {@code by-reference} concept to fill in
+ * the provided {@code pointer} with the value unknown at the time
+ * {@code pointer} was declared.
+ * </p>
+ * <p>
+ * Typical usage in Java code would be as follows:
+ * <pre>
+ *
+ * Pointer ptr = Memory.malloc();
+ *
+ * NioByteBuffer b = NioByteBuffer.allocate(ptr, size);
+ *
+ * ...
+ *
+ * ptr.free();
+ *
+ * </pre>
+ * The newly created {@code NioByteBuffer} holds the memory
+ * area pointed by {@code Pointer} object and {@code Pointer}
+ * object holds a native pointer to a physical memory area location.
+ * When done the memory should be released by calling
+ * {@code ptr.free()}.
+ * </p>
+ *
+ * @return {@code null} pointer.
+ * @throws OutOfMemoryError if memory cannot be allocated.
+ */
+ public static Pointer malloc()
+ throws OutOfMemoryError
+ {
+ Pointer p = nullp0();
+ if (p == null)
+ throw new OutOfMemoryError("Memory alloc failed");
+ return p;
+ }
+
+ /**
+ * Allocates {@code size} bytes and returns a {@link Pointer}
+ * to the allocated memory. The memory is not cleared.
+ *
+ * @param size Size of the memory to allocate.
+ * @return new {@link Pointer} containing memory area.
+ *
+ * @throws OutOfMemoryError if memory cannot be allocated.
+ * @throws IllegalArgumentException if the size is less then {@code 1}.
+ */
+ public static native Pointer malloc(long size)
+ throws OutOfMemoryError, IllegalArgumentException;
+
+ /**
+ * Allocates {@code size} bytes and returns a {@link Pointer}
+ * to the allocated memory. The memory is cleared.
+ *
+ * @param size Size of the memory to allocate.
+ * @return new {@link Pointer} containing memory area.
+ *
+ * @throws OutOfMemoryError if memory cannot be allocated.
+ * @throws IllegalArgumentException if the size is less then {@code 1}.
+ */
+ public static native Pointer calloc(long size)
+ throws OutOfMemoryError, IllegalArgumentException;
+
+ private static native void realloc0(Pointer ptr, long size)
+ throws OutOfMemoryError, RuntimeException;
+ /**
+ * Change the size of memory block pointed by {@code ptr}.
+ * <p>
+ * If the Pointer was created using {@code slice} the
+ * method will throw {@code RuntimeException} because the
+ * sliced memory points to the shared memory segment and
+ * cannot be reallocated.
+ * </p>
+ *
+ * @param ptr Pointer which size to change..
+ * @param size The new size of the memory block.
+ *
+ * @throws OutOfMemoryError if memory cannot be allocated.
+ * @throws IllegalArgumentException if the size is less then {@code 1}.
+ * @throws RuntimeException if the {@code ptr} points to an invalid address.
+ */
+ public static void realloc(Pointer ptr, long size)
+ throws OutOfMemoryError, IllegalArgumentException, RuntimeException
+ {
+ if (size < 1L)
+ throw new IllegalArgumentException();
+
+ realloc0(ptr, size);
+ }
+
+ private static native int peek0(long addr);
+ /**
+ * Get a {@code byte} value this {@code pointer} contains at the
+ * {@code index}.
+ *
+ * @return a {@code byte} at {@code index}.
+ * @throws IndexOutOfBoundsException if {@code index} would cause access
+ * outside the pointer address space.
+ * @throws NullPointerException if pointer is {@code null}.
+ */
+ public static int peek(Pointer ptr, long index)
+ throws IndexOutOfBoundsException, NullPointerException
+ {
+ if (ptr == null)
+ throw new NullPointerException();
+ if (ptr.POINTER == 0L)
+ throw new NullPointerException();
+ else if (index < 0L || index >= ptr.PLENGTH)
+ throw new IndexOutOfBoundsException();
+ return peek0(ptr.POINTER + index);
+ }
+
+ private static native void poke0(long addr, int v);
+ /**
+ * Set a {@code byte} value to this {@code pointer} at the
+ * {@code index} location.
+ *
+ * @param value Value to set at {@code index}.
+ * @throws IndexOutOfBoundsException if {@code index} would cause access
+ * outside the pointer address space.
+ * @throws NullPointerException if pointer is {@code null}.
+ */
+ public static void poke(Pointer ptr, long index, int value)
+ throws IndexOutOfBoundsException, NullPointerException
+ {
+ if (ptr == null)
+ throw new NullPointerException();
+ if (ptr.POINTER == 0L)
+ throw new NullPointerException();
+ else if (index < 0L || index >= ptr.PLENGTH)
+ throw new IndexOutOfBoundsException();
+ else if (ptr.ISCONST)
+ throw new UnsupportedOperationException();
+ poke0(ptr.POINTER + index, value);
+ }
+
+
+ private static native Pointer slice0(long src, long size)
+ throws IndexOutOfBoundsException;
+ private static native Pointer slice1(long src, long size)
+ throws IndexOutOfBoundsException;
+ /**
+ * Creates a new {@link Pointer} object whose content is a shared
+ * subsequence of a {@code src} memory address.
+ * <p>
+ * Sliced memory cannot be reallocated. Calling {@link #realloc(Pointer, long) realloc}
+ * will throw an {@code RuntimeException} if such attempt is made.
+ * </p>
+ * <p>
+ * Calling {@link Pointer#free() Pointer.free()} has no effect on sliced
+ * memory pointer.
+ * </p>
+ * @param src {@code Pointer} whose content to use.
+ * @param offset offset from the {@code src} memory address.
+ * @param size size of the destination memory.
+ * @return new {@link Pointer}.
+ *
+ * @throws IllegalArgumentException if the {@code offset} is
+ * {@code negative} or {@code size} is {@code zero}.
+ * @throws IndexOutOfBoundsException if the operation would cause
+ * access of data outside allocated memory bounds.
+ * @throws NullPointerException if {@code src} is {@code null}.
+ */
+ public static Pointer slice(Pointer src, long offset, long size)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException
+ {
+ if (src == null)
+ throw new NullPointerException();
+ if (offset < 0L || size < 1L)
+ throw new IllegalArgumentException();
+ if (src.POINTER == 0L)
+ throw new NullPointerException();
+ if (offset + size > src.PLENGTH)
+ throw new IndexOutOfBoundsException();
+ if (src.ISCONST)
+ return slice1(src.POINTER + offset, size);
+ else
+ return slice0(src.POINTER + offset, size);
+ }
+
+ 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.
+ *
+ * @param src {@code Pointer} whose content to use.
+ * @param offset offset from the {@code src} memory address.
+ * @param size size of the destination memory.
+ * @return new {@link Pointer}.
+ *
+ * @throws IllegalArgumentException if the {@code offset} is
+ * {@code negative} or {@code size} is {@code zero}.
+ * @throws IndexOutOfBoundsException if the operation would cause
+ * access of data outside allocated memory bounds.
+ * @throws NullPointerException if {@code src} is {@code null}.
+ * @throws RuntimeException if memory is corrupted.
+ * @throws OutOfMemoryError if memory cannot be dipicated.
+ */
+ public static Pointer dup(Pointer src, long offset, long size)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException, RuntimeException, OutOfMemoryError
+ {
+ if (src == null || src.POINTER == 0L)
+ throw new NullPointerException();
+ if (offset < 0L || size < 1L)
+ throw new IllegalArgumentException();
+ if (offset + size > src.PLENGTH)
+ throw new IndexOutOfBoundsException();
+
+ return dup0(src.POINTER + offset, size);
+ }
+
+ private static native void copy0(long src, long dst, long length)
+ throws RuntimeException;
+ /**
+ * Copy the memory area from {@code src} to {@code dst}.
+ * <p>
+ * Method uses the {@code memcpy} function to do a copying, meaning
+ * that {@code source} and {@code destination} memory areas should
+ * not overlap.
+ * </p>
+ *
+ * @param src {@code Pointer} whose content to use.
+ * @param srcPos starting position in the source memory.
+ * @param dst destination {@code Pointer}.
+ * @param dstPos starting position in the destination 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 RuntimeException if memory is corrupted.
+ * @throws UnsupportedOperationException if {@code dst} is
+ * instance of {@code ConstPointer}.
+ */
+ public static void copy(Pointer src, long srcPos, Pointer dst,
+ long dstPos, long length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException, RuntimeException,
+ UnsupportedOperationException
+ {
+ if (src == null || dst == null)
+ throw new NullPointerException();
+ if (src.POINTER == 0L || dst.POINTER == 0L)
+ throw new NullPointerException();
+ if (srcPos < 0L || dstPos < 0L || length < 1L)
+ throw new IllegalArgumentException();
+ if (dst.ISCONST)
+ throw new UnsupportedOperationException();
+ if (srcPos + length > src.PLENGTH)
+ throw new IndexOutOfBoundsException();
+ if (dstPos + length > dst.PLENGTH)
+ throw new IndexOutOfBoundsException();
+ copy0(src.POINTER + srcPos, dst.POINTER + dstPos, length);
+ }
+
+ private static native void move0(long src, long dst, long length)
+ throws RuntimeException;
+ /**
+ * Copy the memory area from {@code src} to {@code dst}.
+ * <p>
+ * Method uses the {@code memmove} function to do a copying, meaning
+ * that {@code src} and {@code dst} memory areas can overlap.
+ * </p>
+ *
+ * @param src {@code Pointer} whose content to use.
+ * @param srcPos starting position in the source memory.
+ * @param dst destination {@code Pointer}.
+ * @param dstPos starting position in the destination 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 RuntimeException if memory is corrupted.
+ * @throws UnsupportedOperationException if {@code dst} is
+ * instance of {@code ConstPointer}.
+ */
+ public static void move(Pointer src, long srcPos, Pointer dst,
+ long dstPos, long length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException, RuntimeException,
+ UnsupportedOperationException
+ {
+ if (src == null || dst == null)
+ throw new NullPointerException();
+ if (src.POINTER == 0L || dst.POINTER == 0L)
+ throw new NullPointerException();
+ if (srcPos < 0L || dstPos < 0L || length < 1L)
+ throw new IllegalArgumentException();
+ if (dst.ISCONST)
+ throw new UnsupportedOperationException();
+ if (srcPos + length > src.PLENGTH)
+ throw new IndexOutOfBoundsException();
+ if (dstPos + length > dst.PLENGTH)
+ throw new IndexOutOfBoundsException();
+ move0(src.POINTER + srcPos, dst.POINTER + dstPos, length);
+ }
+
+ private static native void clear0(long ptr, long length)
+ throws RuntimeException;
+ /**
+ * Set the {@code ptr} memory area from {@code src} to {@code zero}.
+ *
+ * @param ptr {@code Pointer} whose content to use.
+ * @param offset starting position in the memory.
+ * @param length the number of bytes to be clear.
+ *
+ * @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 RuntimeException if memory is corrupted.
+ * @throws UnsupportedOperationException if {@code ptr} is
+ * instance of {@code ConstPointer}.
+ */
+ public static void clear(Pointer ptr, long offset, long length)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException, RuntimeException,
+ UnsupportedOperationException
+ {
+ if (ptr == null || ptr.POINTER == 0L)
+ throw new NullPointerException();
+ if (offset < 0L || length < 1L)
+ throw new IllegalArgumentException();
+ if (ptr.ISCONST)
+ throw new UnsupportedOperationException();
+ if (offset + length > ptr.PLENGTH)
+ throw new IndexOutOfBoundsException();
+ clear0(ptr.POINTER + offset, length);
+ }
+
+ private static native void set0(long ptr, long length, int val)
+ throws RuntimeException;
+ /**
+ * Set the {@code ptr} memory area from {@code src} to {@code val}.
+ *
+ * @param ptr {@code Pointer} whose content to use.
+ * @param offset starting position in the memory.
+ * @param length the number of bytes to be set.
+ * @param val value to set.
+ *
+ * @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 RuntimeException if memory is corrupted.
+ * @throws UnsupportedOperationException if {@code ptr} is
+ * instance of {@code ConstPointer}.
+ */
+ public static void set(Pointer ptr, long offset, long length, int val)
+ throws IndexOutOfBoundsException, IllegalArgumentException,
+ NullPointerException, RuntimeException,
+ UnsupportedOperationException
+ {
+ if (ptr == null || ptr.POINTER == 0L)
+ throw new NullPointerException();
+ if (offset < 0L || length < 1L)
+ throw new IllegalArgumentException();
+ if (ptr.ISCONST)
+ throw new UnsupportedOperationException();
+ if (offset + length > ptr.PLENGTH)
+ throw new IndexOutOfBoundsException();
+ set0(ptr.POINTER + offset, length, val);
+ }
+
+ private static native byte[] array0(long ptr, int length)
+ throws IndexOutOfBoundsException, OutOfMemoryError;
+ /**
+ * Return the {@code ptr} memory area from {@code src} to {@code byte} 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 byte[] toByteArray(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 array0(ptr.POINTER + offset, length);
+ }
+
+ private static native char[] array1(long ptr, int length)
+ throws IndexOutOfBoundsException, OutOfMemoryError;
+ /**
+ * Return the {@code ptr} memory area from {@code src} to {@code char} array.
+ *
+ * @param ptr {@code Pointer} whose content to use.
+ * @param offset starting position in {@code chars} in the memory.
+ * @param length the number of chars use.
+ * @return new {@code char} 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 char[] toCharArray(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) * 2) > ptr.PLENGTH)
+ throw new IndexOutOfBoundsException();
+
+ return array1(ptr.POINTER + offset * 2, length);
+ }
+
+ private static native short[] array2(long ptr, int length)
+ throws IndexOutOfBoundsException, OutOfMemoryError;
+ /**
+ * Return the {@code ptr} memory area from {@code src} to {@code short} array.
+ *
+ * @param ptr {@code Pointer} whose content to use.
+ * @param offset starting position in {@code chars} in the memory.
+ * @param length the number of chars use.
+ * @return new {@code short} 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 short[] toShortArray(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) * 2) > ptr.PLENGTH)
+ throw new IndexOutOfBoundsException();
+
+ return array2(ptr.POINTER + offset * 2, length);
+ }
+
+ private static native int[] array3(long ptr, int length)
+ throws IndexOutOfBoundsException, OutOfMemoryError;
+ /**
+ * Return the {@code ptr} memory area from {@code src} to {@code int} array.
+ *
+ * @param ptr {@code Pointer} whose content to use.
+ * @param offset starting position in {@code ints} in the memory.
+ * @param length the number of chars use.
+ * @return new {@code int} 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 int[] toIntegerArray(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) * 4) > ptr.PLENGTH)
+ throw new IndexOutOfBoundsException();
+
+ return array3(ptr.POINTER + offset * 4, length);
+ }
+
+ private static native long[] array4(long ptr, int length)
+ throws IndexOutOfBoundsException, OutOfMemoryError;
+ /**
+ * Return the {@code ptr} memory area from {@code src} to
+ * {@code long} array.
+ *
+ * @param ptr {@code Pointer} whose content to use.
+ * @param offset starting position in {@code longs} in the memory.
+ * @param length the number of chars use.
+ * @return new {@code long} 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 long[] toLongArray(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) * 8) > ptr.PLENGTH)
+ throw new IndexOutOfBoundsException();
+
+ return array4(ptr.POINTER + offset * 8, length);
+ }
+
+ private static native float[] array5(long ptr, int length)
+ throws IndexOutOfBoundsException, OutOfMemoryError;
+ /**
+ * Return the {@code ptr} memory area from {@code src} to
+ * {@code float} array.
+ *
+ * @param ptr {@code Pointer} whose content to use.
+ * @param offset starting position in {@code floats} in the memory.
+ * @param length the number of chars use.
+ * @return new {@code long} 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 float[] toFloatArray(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) * 4) > ptr.PLENGTH)
+ throw new IndexOutOfBoundsException();
+
+ return array5(ptr.POINTER + offset * 4, length);
+ }
+
+ private static native double[] array6(long ptr, int length)
+ throws IndexOutOfBoundsException, OutOfMemoryError;
+ /**
+ * Return the {@code ptr} memory area from {@code src} to
+ * {@code double} array.
+ *
+ * @param ptr {@code Pointer} whose content to use.
+ * @param offset starting position in {@code doubles} in the memory.
+ * @param length the number of chars use.
+ * @return new {@code long} 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 double[] toDoubleArray(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) * 8) > ptr.PLENGTH)
+ throw new IndexOutOfBoundsException();
+
+ return array6(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)
+ 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, byte[] 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();
+
+ acpy0(src.POINTER + srcPos, dst, dstPos, length);
+ }
+
+ private static native void acpy1(long src, char[] 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 chars 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, char[] 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) * 2) > src.PLENGTH)
+ throw new IndexOutOfBoundsException();
+
+ acpy1(src.POINTER + srcPos * 2, dst, dstPos, length);
+ }
+
+ private static native void acpy2(long src, short[] 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 shorts 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, short[] 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) * 2) > src.PLENGTH)
+ throw new IndexOutOfBoundsException();
+
+ acpy2(src.POINTER + srcPos * 2, dst, dstPos, length);
+ }
+
+ private static native void acpy3(long src, int[] 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 ints 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, int[] 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) * 4) > src.PLENGTH)
+ throw new IndexOutOfBoundsException();
+
+ acpy3(src.POINTER + srcPos * 4, dst, dstPos, length);
+ }
+
+ private static native void acpy4(long src, long[] 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 longs 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, long[] 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) * 8) > src.PLENGTH)
+ throw new IndexOutOfBoundsException();
+
+ acpy4(src.POINTER + srcPos * 8, dst, dstPos, length);
+ }
+
+ private static native void acpy5(long src, float[] 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 longs 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, float[] 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) * 4) > src.PLENGTH)
+ throw new IndexOutOfBoundsException();
+
+ acpy5(src.POINTER + srcPos * 4, dst, dstPos, length);
+ }
+
+ private static native void acpy6(long src, double[] 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 longs 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, double[] 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) * 8) > src.PLENGTH)
+ throw new IndexOutOfBoundsException();
+
+ acpy6(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)
+ 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(byte[] 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();
+ pcpy0(src, srcPos, dst.POINTER + dstPos, length);
+ }
+
+ private static native void pcpy1(char[] 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(char[] 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) * 2) > dst.PLENGTH)
+ throw new IndexOutOfBoundsException();
+ if (dst.ISCONST)
+ throw new UnsupportedOperationException();
+ pcpy1(src, srcPos, dst.POINTER + dstPos * 2, length);
+ }
+
+ private static native void pcpy2(short[] 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(short[] 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) * 2) > dst.PLENGTH)
+ throw new IndexOutOfBoundsException();
+ if (dst.ISCONST)
+ throw new UnsupportedOperationException();
+ pcpy2(src, srcPos, dst.POINTER + dstPos * 2, length);
+ }
+
+ private static native void pcpy3(int[] 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(int[] 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) * 4) > dst.PLENGTH)
+ throw new IndexOutOfBoundsException();
+ if (dst.ISCONST)
+ throw new UnsupportedOperationException();
+ pcpy3(src, srcPos, dst.POINTER + dstPos * 4, length);
+ }
+
+ private static native void pcpy4(long[] 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(long[] 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) * 8) > dst.PLENGTH)
+ throw new IndexOutOfBoundsException();
+ if (dst.ISCONST)
+ throw new UnsupportedOperationException();
+ pcpy4(src, srcPos, dst.POINTER + dstPos * 8, length);
+ }
+
+ private static native void pcpy5(float[] 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(float[] 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) * 4) > dst.PLENGTH)
+ throw new IndexOutOfBoundsException();
+ if (dst.ISCONST)
+ throw new UnsupportedOperationException();
+ pcpy5(src, srcPos, dst.POINTER + dstPos * 4, length);
+ }
+
+ private static native void pcpy6(double[] 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(double[] 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) * 8) > dst.PLENGTH)
+ 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);
+ }
+
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java?rev=1091318&r1=1091317&r2=1091318&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Platform.java Tue Apr 12 08:05:37 2011
@@ -24,7 +24,7 @@ import java.nio.charset.Charset;
* @since Runtime 1.0
*
*/
-class Platform
+final class Platform
{
private Platform()
Added: 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=1091318&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java Tue Apr 12 08:05:37 2011
@@ -0,0 +1,217 @@
+/* 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.apache.commons.runtime.util.Utils;
+
+/** Represents the Operating System C/C++ native pointer.
+ * <p>
+ * <b>Warning:</b><br/>Using this class improperly may crash the running JVM.
+ * </p>
+ * @since Runtime 1.0
+ */
+public abstract class Pointer implements Comparable<Pointer>
+{
+
+ protected long POINTER;
+ protected long PLENGTH;
+ protected boolean ISCONST;
+
+ /**
+ * Create new {@code null} Pointer instance.
+ * <p>
+ * This method is convinience for {@link Memory#malloc() Memory.malloc()}
+ * method.
+ * </p>
+ * @return new {@code null} Pointer.
+ * @throws OutOfMemoryError if memory cannot be allocated.
+ * @see Memory#malloc()
+ */
+ public static final Pointer createInstance()
+ throws OutOfMemoryError
+ {
+ return Memory.malloc();
+ }
+
+ /*
+ * Pointer can only be created from the native code.
+ * Suppress any instantiation except from internal classes.
+ */
+ protected Pointer()
+ {
+ // No Instance
+ }
+
+ private native void free0(long p)
+ throws Throwable;
+
+ private static native Pointer nullptr0();
+
+ /**
+ * Represents a C/C++ NULL {@code pointer}.
+ */
+ public static final Pointer NULL;
+ static {
+ NULL = nullptr0();
+ }
+
+ /**
+ * Address of the internal pointer.
+ *
+ * @return Internal pointer address casted to the {@code long}.
+ */
+ public long address()
+ {
+ return POINTER;
+ }
+
+ /**
+ * Size of the memory area this pointer consumes.
+ * <p>
+ * If the {@code this} Pointer does not have a length
+ * the returned size if Pointer {@code SIZEOF}.
+ *</p>
+ *
+ * @return Internal pointer size.
+ */
+ public long sizeof()
+ {
+ return PLENGTH;
+ }
+
+
+ /**
+ * Check if the pointer is valid
+ * @return true if the internal pointer is not {@code NULL}.
+ */
+ public boolean isNull()
+ {
+ return POINTER == 0L;
+ }
+
+ /**
+ * Compares this {@code Pointer} to the specified object.
+ *
+ * @param other a {@code Pointer}
+ * @return true if the class of this {@code Pointer} object and the
+ * class of {@code other} are exactly equal, and the C/C++
+ * pointers being pointed to by these objects are also
+ * equal. Returns false otherwise.
+ */
+ @Override
+ public boolean equals(Object other)
+ {
+ if (other == null)
+ return false;
+ if (other == this)
+ return true;
+ if (other instanceof Pointer)
+ return POINTER == ((Pointer)other).POINTER;
+ else
+ return false;
+ }
+
+ private static native int memcmp0(long a, long b, long length);
+ /**
+ * Compares this {@code Pointer} to the specified object for order
+ *
+ * @param other the {@code Pointer} to be Compared
+ * @return a negative integer, zero or positive integer as this object
+ * is less then, equal, or greater then the specified object.
+ */
+ @Override
+ public int compareTo(Pointer other)
+ throws ClassCastException
+ {
+ if (other == null)
+ throw new ClassCastException();
+ if (POINTER == 0L)
+ return -1;
+ if (other.POINTER == 0L)
+ return 1;
+ if (PLENGTH == other.PLENGTH)
+ return memcmp0(POINTER, other.POINTER, PLENGTH);
+ else if (PLENGTH > other.PLENGTH)
+ return 1;
+ else
+ return -1;
+ }
+
+ /**
+ * Called by the garbage collector when the object is destroyed.
+ * The class will free internal resources allocated by the Operating system.
+ * @see Object#finalize()
+ * @throws Throwable the {@code Exception} raised by this method.
+ */
+ @Override
+ protected final void finalize()
+ throws Throwable
+ {
+ try {
+ if (!ISCONST)
+ free0(POINTER);
+ } finally {
+ POINTER = 0L;
+ }
+ }
+
+ /**
+ * Free the allocated resource by the Operating system.
+ * <p>
+ * Note that {@code Object.finalize()} method will call
+ * this function. However if the native code can block for
+ * long time explicit {@code free()} should be called.
+ * </p>
+ * @see #finalize()
+ * @throws Throwable the {@code Exception} raised by this method.
+ */
+ public final void free()
+ throws Throwable
+ {
+ if (ISCONST)
+ throw new UnsupportedOperationException();
+ if (POINTER == 0L)
+ throw new NullPointerException();
+ try {
+ free0(POINTER);
+ } finally {
+ POINTER = 0L;
+ }
+ }
+
+ /**
+ * Returns a string representation of the Pointer.
+ * The returned string is hexadecimal representation of the underlying
+ * pointer.
+ * @return a hexadecimal representation of the pointer.
+ */
+ @Override
+ public String toString()
+ {
+ if (POINTER != 0L) {
+ if (Platform.SIZEOF_POINTER == 4)
+ return "0x" + Utils.hex((int)(POINTER & 0x00000000FFFFFFFFL));
+ else
+ return "0x" + Utils.hex(POINTER);
+ }
+ else {
+ return "(nil)";
+ }
+ }
+
+}
+
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ReflectedFieldImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ReflectedFieldImpl.java?rev=1091318&r1=1091317&r2=1091318&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ReflectedFieldImpl.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ReflectedFieldImpl.java Tue Apr 12 08:05:37 2011
@@ -24,7 +24,7 @@ import java.lang.reflect.Method;
* @since Runtime 1.0
*
*/
-class ReflectedFieldImpl extends ReflectedField
+final class ReflectedFieldImpl extends ReflectedField
{
public ReflectedFieldImpl(Class clazz, String name, String signature, boolean isStatic)
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ReflectedMethodImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ReflectedMethodImpl.java?rev=1091318&r1=1091317&r2=1091318&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ReflectedMethodImpl.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ReflectedMethodImpl.java Tue Apr 12 08:05:37 2011
@@ -24,7 +24,7 @@ import java.lang.reflect.Method;
* @since Runtime 1.0
*
*/
-class ReflectedMethodImpl extends ReflectedMethod
+final class ReflectedMethodImpl extends ReflectedMethod
{
public ReflectedMethodImpl(Class clazz, String signature)
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=1091318&r1=1091317&r2=1091318&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 08:05:37 2011
@@ -90,11 +90,13 @@ LIBSOURCES=\
$(TOPDIR)/shared/bzip2.c \
$(TOPDIR)/shared/callback.c \
$(TOPDIR)/shared/clazz.c \
+ $(TOPDIR)/shared/constptr.c \
$(TOPDIR)/shared/debug.c \
$(TOPDIR)/shared/error.c \
$(TOPDIR)/shared/iofd.c \
$(TOPDIR)/shared/memory.c \
$(TOPDIR)/shared/native.c \
+ $(TOPDIR)/shared/pointer.c \
$(TOPDIR)/shared/object.c \
$(TOPDIR)/shared/observer.c \
$(TOPDIR)/shared/reflect.c \
Added: 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=1091318&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h Tue Apr 12 08:05:37 2011
@@ -0,0 +1,48 @@
+/* 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.
+ */
+
+#ifndef _ACR_POINTER_H
+#define _ACR_POINTER_H
+
+#include "acr/jniapi.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file pointer.h
+ * @brief
+ *
+ * ACR Pointer support.
+ *
+ */
+
+ACR_CLASS_CTOR(ConstPointer);
+ACR_CLASS_DTOR(ConstPointer);
+ACR_CLASS_CTOR(GenericPointer);
+ACR_CLASS_DTOR(GenericPointer);
+
+jobject
+AcrNewConstPointer(JNI_STDENV, void *ptr, size_t len);
+jobject
+AcrNewGenericPointer(JNI_STDENV, void *ptr, size_t len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ACR_POINTER_H */
Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/native/shared/constptr.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/constptr.c?rev=1091318&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/constptr.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/constptr.c Tue Apr 12 08:05:37 2011
@@ -0,0 +1,75 @@
+/* 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 "ConstPointer"
+};
+
+J_DECLARE_M_ID(0000) = {
+ 0,
+ "<init>",
+ "(JJ)V"
+};
+
+ACR_CLASS_CTOR(ConstPointer)
+{
+ int rv;
+
+ if ((rv = AcrLoadClass(env, &_clazzn, 0)) != 0)
+ return rv;
+ J_LOAD_METHOD(0000);
+ _clazzn.u = 1;
+ return 0;
+}
+
+ACR_CLASS_DTOR(ConstPointer)
+{
+ AcrUnloadClass(env, &_clazzn);
+}
+
+jobject
+AcrNewConstPointer(JNI_STDENV, void *ptr, size_t len)
+{
+ jobject po;
+
+ if (!CLAZZ_LOADED) {
+ ACR_THROW_MSG(ACR_EX_EINSTANCE, "GenericPointer 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;
+}
+
+ACR_JNI_EXPORT(jobject, Pointer, nullptr0)(JNI_STDARGS)
+{
+ return AcrNewConstPointer(env, 0, 0);
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/constptr.c
------------------------------------------------------------------------------
svn:eol-style = native
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=1091318&r1=1091317&r2=1091318&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 08:05:37 2011
@@ -15,6 +15,8 @@
*/
#include "acr/memory.h"
+#include "acr/pointer.h"
+#include "acr/clazz.h"
/*
* A function that is called when allocation fails.
Added: 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=1091318&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Tue Apr 12 08:05:37 2011
@@ -0,0 +1,95 @@
+/* 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 "GenericPointer"
+};
+
+J_DECLARE_M_ID(0000) = {
+ 0,
+ "<init>",
+ "(JJ)V"
+};
+
+J_DECLARE_F_ID(0000) = {
+ INVALID_FIELD_OFFSET,
+ INVALID_FIELD_OFFSET,
+ 0,
+ "POINTER",
+ "J"
+};
+
+J_DECLARE_F_ID(0001) = {
+ INVALID_FIELD_OFFSET,
+ INVALID_FIELD_OFFSET,
+ 0,
+ "PLENGTH",
+ "J"
+};
+
+ACR_CLASS_CTOR(GenericPointer)
+{
+ int rv;
+
+ if ((rv = AcrLoadClass(env, &_clazzn, 0)) != 0)
+ return rv;
+ J_LOAD_METHOD(0000);
+ J_LOAD_IFIELD(0000);
+ J_LOAD_IFIELD(0001);
+ UNSAFE_IFIELD(0000);
+ UNSAFE_IFIELD(0001);
+ _clazzn.u = 1;
+ return 0;
+}
+
+ACR_CLASS_DTOR(GenericPointer)
+{
+ AcrUnloadClass(env, &_clazzn);
+}
+
+jobject
+AcrNewGenericPointer(JNI_STDENV, void *ptr, size_t len)
+{
+ jobject po;
+
+ if (!CLAZZ_LOADED) {
+ ACR_THROW_MSG(ACR_EX_EINSTANCE, "GenericPointer 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;
+}
+
+ACR_JNI_EXPORT(void, Pointer, free0)(JNI_STDARGS, jlong ptr)
+{
+ AcrFree(J2P(ptr, void *));
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
------------------------------------------------------------------------------
svn:eol-style = native