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 2009/06/19 11:32:03 UTC

svn commit: r786428 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/ main/native/ main/native/shared/ test/org/apache/commons/runtime/

Author: mturk
Date: Fri Jun 19 09:32:02 2009
New Revision: 786428

URL: http://svn.apache.org/viewvc?rev=786428&view=rev
Log:
Move peek/poke to new Structure class

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure.java   (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure32.java   (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure64.java   (with props)
    commons/sandbox/runtime/trunk/src/main/native/shared/structure.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java
    commons/sandbox/runtime/trunk/src/main/native/Makefile.in
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java?rev=786428&r1=786427&r2=786428&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java Fri Jun 19 09:32:02 2009
@@ -179,21 +179,6 @@
     public abstract int    peek(int index)
         throws IndexOutOfBoundsException, NullPointerException;
 
-    public abstract int    peek16(int index)
-        throws IndexOutOfBoundsException, NullPointerException;
-
-    public abstract int    peek32(int index)
-        throws IndexOutOfBoundsException, NullPointerException;
-
-    public abstract long   peek64(int index)
-        throws IndexOutOfBoundsException, NullPointerException;
-
-    public abstract float  peek32f(int index)
-        throws IndexOutOfBoundsException, NullPointerException;
-
-    public abstract double peek64f(int index)
-        throws IndexOutOfBoundsException, NullPointerException;
-
     /**
      * Set a {@code byte} value to this {@code pointer} at the
      * {@code index} location.
@@ -206,21 +191,6 @@
     public abstract void poke(int index, int value)
         throws IndexOutOfBoundsException, NullPointerException;
 
-    public abstract void poke16(int index, int value)
-        throws IndexOutOfBoundsException, NullPointerException;
-
-    public abstract void poke32(int index, int value)
-        throws IndexOutOfBoundsException, NullPointerException;
-
-    public abstract void poke32(int index, float value)
-        throws IndexOutOfBoundsException, NullPointerException;
-
-    public abstract void poke64(int index, long value)
-        throws IndexOutOfBoundsException, NullPointerException;
-
-    public abstract void poke64(int index, double value)
-        throws IndexOutOfBoundsException, NullPointerException;
-
     /**
      * Copy the memory area from {@code this} pointer to {@code dst}.
      * <p>
@@ -273,6 +243,8 @@
                NullPointerException;
 
 
+    public abstract Structure asStructure();
+
     /**
      * Returns a string representation of the Pointer.
      * The returned string is hexadecimal representation of the underlying

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java?rev=786428&r1=786427&r2=786428&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java Fri Jun 19 09:32:02 2009
@@ -24,10 +24,13 @@
  */
 class Pointer32 extends Pointer {
 
-    private int     POINTER;
-    private int     CLEANUP;
-    private int     PLENGTH;
+    private   int     CLEANUP;
+    protected int     POINTER;
+    protected int     PLENGTH;
 
+    protected Pointer32()
+    {
+    }
     /*
      * Only created from JNI code.
      */
@@ -64,13 +67,7 @@
         return new Integer(PLENGTH);
     }
 
-    private static native int    peek0(int addr);
-    private static native int    peek1(int addr);
-    private static native int    peek2(int addr);
-    private static native long   peek3(int addr);
-    private static native float  peek4(int addr);
-    private static native double peek5(int addr);
-
+    private static native int peek0(int addr);
     public int peek(int index)
         throws IndexOutOfBoundsException, NullPointerException
     {
@@ -81,63 +78,7 @@
         return peek0(POINTER + index);
     }
 
-    public int peek16(int index)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0)
-            throw new NullPointerException();
-        else if (index < 0 || index >= PLENGTH / 2)
-            throw new IndexOutOfBoundsException();
-        return peek1(POINTER + index / 2);
-    }
-
-    public int peek32(int index)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0)
-            throw new NullPointerException();
-        else if (index < 0 || index >= PLENGTH / 4)
-            throw new IndexOutOfBoundsException();
-        return peek2(POINTER + index / 4);
-    }
-
-    public long peek64(int index)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0)
-            throw new NullPointerException();
-        else if (index < 0 || index >= PLENGTH / 8)
-            throw new IndexOutOfBoundsException();
-        return peek3(POINTER + index / 8);
-    }
-
-    public float peek32f(int index)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0)
-            throw new NullPointerException();
-        else if (index < 0 || index >= PLENGTH / 4)
-            throw new IndexOutOfBoundsException();
-        return peek4(POINTER + index / 4);
-    }
-
-    public double peek64f(int index)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0)
-            throw new NullPointerException();
-        else if (index < 0 || index >= PLENGTH / 8)
-            throw new IndexOutOfBoundsException();
-        return peek5(POINTER + index / 8);
-    }
-
-    private static native void  poke0(int addr, int    v);
-    private static native void  poke1(int addr, int    v);
-    private static native void  poke2(int addr, int    v);
-    private static native void  poke3(int addr, long   v);
-    private static native void  poke4(int addr, float  v);
-    private static native void  poke5(int addr, double v);
-
+    private static native void poke0(int addr, int    v);
     public void poke(int index, int value)
         throws IndexOutOfBoundsException, NullPointerException
     {
@@ -148,56 +89,6 @@
         poke0(POINTER + index, value);
     }
 
-    public void poke16(int index, int value)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0)
-            throw new NullPointerException();
-        else if (index < 0 || index >= PLENGTH / 2)
-            throw new IndexOutOfBoundsException();
-        poke1(POINTER + index / 2, value);
-    }
-
-    public void poke32(int index, int value)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0)
-            throw new NullPointerException();
-        else if (index < 0 || index >= PLENGTH / 4)
-            throw new IndexOutOfBoundsException();
-        poke2(POINTER + index / 4, value);
-    }
-
-    public void poke32(int index, float value)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0)
-            throw new NullPointerException();
-        else if (index < 0 || index >= PLENGTH / 4)
-            throw new IndexOutOfBoundsException();
-        poke4(POINTER + index / 4, value);
-    }
-
-    public void poke64(int index, long value)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0)
-            throw new NullPointerException();
-        else if (index < 0 || index >= PLENGTH / 8)
-            throw new IndexOutOfBoundsException();
-        poke3(POINTER + index / 8, value);
-    }
-
-    public void poke64(int index, double value)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0)
-            throw new NullPointerException();
-        else if (index < 0 || index >= PLENGTH / 8)
-            throw new IndexOutOfBoundsException();
-        poke5(POINTER + index / 8, value);
-    }
-
     private static native void copy0(int src, int dst, int length);
     private static native void move0(int src, int dst, int length);
 
@@ -235,6 +126,11 @@
         move0(s32.POINTER + (int)dstPos, POINTER + (int)srcPos, (int)length);
     }
 
+    public Structure asStructure()
+    {
+        return new Structure32(this);
+    }
+
     public String toString()
     {
         if (POINTER != 0) {

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java?rev=786428&r1=786427&r2=786428&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java Fri Jun 19 09:32:02 2009
@@ -24,9 +24,9 @@
  */
 class Pointer64 extends Pointer {
 
-    private long    POINTER;
-    private long    CLEANUP;
-    private long    PLENGTH;
+    private   long    CLEANUP;
+    protected long    POINTER;
+    protected long    PLENGTH;
 
     /*
      * Only created from JNI code.
@@ -65,12 +65,6 @@
     }
 
     private static native int    peek0(long addr);
-    private static native int    peek1(long addr);
-    private static native int    peek2(long addr);
-    private static native long   peek3(long addr);
-    private static native float  peek4(long addr);
-    private static native double peek5(long addr);
-
     public int peek(int index)
         throws IndexOutOfBoundsException, NullPointerException
     {
@@ -81,63 +75,7 @@
         return peek0(POINTER + index);
     }
 
-    public int peek16(int index)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0L)
-            throw new NullPointerException();
-        else if (index < 0L || index >= PLENGTH / 2)
-            throw new IndexOutOfBoundsException();
-        return peek1(POINTER + index / 2);
-    }
-
-    public int peek32(int index)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0L)
-            throw new NullPointerException();
-        else if (index < 0L || index >= PLENGTH / 4)
-            throw new IndexOutOfBoundsException();
-        return peek2(POINTER + index / 4);
-    }
-
-    public long peek64(int index)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0L)
-            throw new NullPointerException();
-        else if (index < 0L || index >= PLENGTH / 8)
-            throw new IndexOutOfBoundsException();
-        return peek3(POINTER + index / 8);
-    }
-
-    public float peek32f(int index)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0L)
-            throw new NullPointerException();
-        else if (index < 0L || index >= PLENGTH / 4)
-            throw new IndexOutOfBoundsException();
-        return peek4(POINTER + index / 4);
-    }
-
-    public double peek64f(int index)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0L)
-            throw new NullPointerException();
-        else if (index < 0L || index >= PLENGTH / 8)
-            throw new IndexOutOfBoundsException();
-        return peek5(POINTER + index / 8);
-    }
-
     private static native void  poke0(long addr, int    v);
-    private static native void  poke1(long addr, int    v);
-    private static native void  poke2(long addr, int    v);
-    private static native void  poke3(long addr, long   v);
-    private static native void  poke4(long addr, float  v);
-    private static native void  poke5(long addr, double v);
-
     public void poke(int index, int value)
         throws IndexOutOfBoundsException, NullPointerException
     {
@@ -148,56 +86,6 @@
         poke0(POINTER + index, value);
     }
 
-    public void poke16(int index, int value)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0L)
-            throw new NullPointerException();
-        else if (index < 0L || index >= PLENGTH / 2)
-            throw new IndexOutOfBoundsException();
-        poke1(POINTER + index / 2, value);
-    }
-
-    public void poke32(int index, int value)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0L)
-            throw new NullPointerException();
-        else if (index < 0L || index >= PLENGTH / 4)
-            throw new IndexOutOfBoundsException();
-        poke2(POINTER + index / 4, value);
-    }
-
-    public void poke32(int index, float value)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0L)
-            throw new NullPointerException();
-        else if (index < 0L || index >= PLENGTH / 4)
-            throw new IndexOutOfBoundsException();
-        poke4(POINTER + index / 4, value);
-    }
-
-    public void poke64(int index, long value)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0L)
-            throw new NullPointerException();
-        else if (index < 0L || index >= PLENGTH / 8)
-            throw new IndexOutOfBoundsException();
-        poke3(POINTER + index / 8, value);
-    }
-
-    public void poke64(int index, double value)
-        throws IndexOutOfBoundsException, NullPointerException
-    {
-        if (POINTER == 0L)
-            throw new NullPointerException();
-        else if (index < 0L || index >= PLENGTH / 8)
-            throw new IndexOutOfBoundsException();
-        poke5(POINTER + index / 8, value);
-    }
-
     private static native void copy0(long src, long dst, long length);
     private static native void move0(long src, long dst, long length);
 
@@ -235,6 +123,11 @@
         move0(s64.POINTER + dstPos, POINTER + srcPos, length);
     }
 
+    public Structure asStructure()
+    {
+        return new Structure64(this);
+    }
+
     public String toString()
     {
         if (POINTER != 0L) {

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure.java?rev=786428&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure.java Fri Jun 19 09:32:02 2009
@@ -0,0 +1,111 @@
+/* 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++ Structure pointer.
+ * <p>
+ * <b>Warning:</b><br/>Using this class improperly may crash the running JVM.
+ * </p>
+ * @since Runtime 1.0
+ */
+public abstract class Structure
+{
+
+    /**
+     * Compares this {@code Structure} to the specified object.
+     *
+     * @param other a {@code Structure}
+     * @return  true if the class of this {@code Structure} 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 abstract boolean equals(Object other);
+
+    /*
+     * Structure can only be created from Pointer class.
+     */
+    protected Structure()
+    {
+        // No Instance except from derrived class
+    }
+
+    /**
+     * Get a {@code byte} value this {@code structure} 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 abstract int    peek(int index)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    public abstract int    peek16(int index)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    public abstract int    peek32(int index)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    public abstract long   peek64(int index)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    public abstract float  peek32f(int index)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    public abstract double peek64f(int index)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    /**
+     * Set a {@code byte} value to this {@code structure} 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 abstract void   poke(int index, int value)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    public abstract void   poke16(int index, int value)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    public abstract void   poke32(int index, int value)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    public abstract void   poke32(int index, float value)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    public abstract void   poke64(int index, long value)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    public abstract void   poke64(int index, double value)
+        throws IndexOutOfBoundsException, NullPointerException;
+
+    /**
+     * Returns a string representation of the Structure.
+     * The returned string is hexadecimal representation of the underlying
+     * pointer.
+     * @return a hexadecimal representation of the pointer.
+     */
+    @Override
+    public abstract String toString();
+
+}

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

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure32.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure32.java?rev=786428&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure32.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure32.java Fri Jun 19 09:32:02 2009
@@ -0,0 +1,189 @@
+/* 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 32-bit C/C++ Structure pointer.
+ * <p>
+ * <b>Warning:</b><br/>Using this class improperly may crash the running JVM.
+ * </p>
+ * @since Runtime 1.0
+ */
+class Structure32 extends Structure {
+
+    private Pointer32 POINTER;
+
+    protected Structure32(Pointer32 ptr)
+    {
+        POINTER = ptr;
+    }
+
+    private static native int    peek0(int addr);
+    private static native int    peek1(int addr);
+    private static native int    peek2(int addr);
+    private static native long   peek3(int addr);
+    private static native float  peek4(int addr);
+    private static native double peek5(int addr);
+
+    private static native void   poke0(int addr, int    v);
+    private static native void   poke1(int addr, int    v);
+    private static native void   poke2(int addr, int    v);
+    private static native void   poke3(int addr, long   v);
+    private static native void   poke4(int addr, float  v);
+    private static native void   poke5(int addr, double v);
+
+    public boolean equals(Object other)
+    {
+        if (other == null)
+            return false;
+        if (other == this)
+            return true;
+        if (Structure32.class != other.getClass())
+            return false;
+        return POINTER.equals(((Structure32)other).POINTER);
+    }
+
+    public int peek(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= POINTER.PLENGTH)
+            throw new IndexOutOfBoundsException();
+        return peek0(POINTER.POINTER + index);
+    }
+
+    public int peek16(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= POINTER.PLENGTH / 2)
+            throw new IndexOutOfBoundsException();
+        return peek1(POINTER.POINTER + index / 2);
+    }
+
+    public int peek32(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= POINTER.PLENGTH / 4)
+            throw new IndexOutOfBoundsException();
+        return peek2(POINTER.POINTER + index / 4);
+    }
+
+    public long peek64(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= POINTER.PLENGTH / 8)
+            throw new IndexOutOfBoundsException();
+        return peek3(POINTER.POINTER + index / 8);
+    }
+
+    public float peek32f(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= POINTER.PLENGTH / 4)
+            throw new IndexOutOfBoundsException();
+        return peek4(POINTER.POINTER + index / 4);
+    }
+
+    public double peek64f(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= POINTER.PLENGTH / 8)
+            throw new IndexOutOfBoundsException();
+        return peek5(POINTER.POINTER + index / 8);
+    }
+
+    public void poke(int index, int value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= POINTER.PLENGTH)
+            throw new IndexOutOfBoundsException();
+        poke0(POINTER.POINTER + index, value);
+    }
+
+    public void poke16(int index, int value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= POINTER.PLENGTH / 2)
+            throw new IndexOutOfBoundsException();
+        poke1(POINTER.POINTER + index / 2, value);
+    }
+
+    public void poke32(int index, int value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= POINTER.PLENGTH / 4)
+            throw new IndexOutOfBoundsException();
+        poke2(POINTER.POINTER + index / 4, value);
+    }
+
+    public void poke32(int index, float value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= POINTER.PLENGTH / 4)
+            throw new IndexOutOfBoundsException();
+        poke4(POINTER.POINTER + index / 4, value);
+    }
+
+    public void poke64(int index, long value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= POINTER.PLENGTH / 8)
+            throw new IndexOutOfBoundsException();
+        poke3(POINTER.POINTER + index / 8, value);
+    }
+
+    public void poke64(int index, double value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0)
+            throw new NullPointerException();
+        else if (index < 0 || index >= POINTER.PLENGTH / 8)
+            throw new IndexOutOfBoundsException();
+        poke5(POINTER.POINTER + index / 8, value);
+    }
+
+    public String toString()
+    {
+        if (POINTER != null) {
+            return POINTER.toString();
+        }
+        else {
+            return "(nil)";
+        }
+    }
+
+}

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

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure64.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure64.java?rev=786428&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure64.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Structure64.java Fri Jun 19 09:32:02 2009
@@ -0,0 +1,189 @@
+/* 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 64-bit C/C++ Structure pointer.
+ * <p>
+ * <b>Warning:</b><br/>Using this class improperly may crash the running JVM.
+ * </p>
+ * @since Runtime 1.0
+ */
+class Structure64 extends Structure {
+
+    private Pointer64 POINTER;
+
+    protected Structure64(Pointer64 ptr)
+    {
+        POINTER = ptr;
+    }
+
+    private static native int    peek0(long addr);
+    private static native int    peek1(long addr);
+    private static native int    peek2(long addr);
+    private static native long   peek3(long addr);
+    private static native float  peek4(long addr);
+    private static native double peek5(long addr);
+
+    private static native void   poke0(long addr, int    v);
+    private static native void   poke1(long addr, int    v);
+    private static native void   poke2(long addr, int    v);
+    private static native void   poke3(long addr, long   v);
+    private static native void   poke4(long addr, float  v);
+    private static native void   poke5(long addr, double v);
+
+    public boolean equals(Object other)
+    {
+        if (other == null)
+            return false;
+        if (other == this)
+            return true;
+        if (Structure64.class != other.getClass())
+            return false;
+        return POINTER.equals(((Structure64)other).POINTER);
+    }
+
+    public int peek(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= POINTER.PLENGTH)
+            throw new IndexOutOfBoundsException();
+        return peek0(POINTER.POINTER + index);
+    }
+
+    public int peek16(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= POINTER.PLENGTH / 2)
+            throw new IndexOutOfBoundsException();
+        return peek1(POINTER.POINTER + index / 2);
+    }
+
+    public int peek32(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= POINTER.PLENGTH / 4)
+            throw new IndexOutOfBoundsException();
+        return peek2(POINTER.POINTER + index / 4);
+    }
+
+    public long peek64(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= POINTER.PLENGTH / 8)
+            throw new IndexOutOfBoundsException();
+        return peek3(POINTER.POINTER + index / 8);
+    }
+
+    public float peek32f(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= POINTER.PLENGTH / 4)
+            throw new IndexOutOfBoundsException();
+        return peek4(POINTER.POINTER + index / 4);
+    }
+
+    public double peek64f(int index)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= POINTER.PLENGTH / 8)
+            throw new IndexOutOfBoundsException();
+        return peek5(POINTER.POINTER + index / 8);
+    }
+
+    public void poke(int index, int value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0 || index >= POINTER.PLENGTH)
+            throw new IndexOutOfBoundsException();
+        poke0(POINTER.POINTER + index, value);
+    }
+
+    public void poke16(int index, int value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= POINTER.PLENGTH / 2)
+            throw new IndexOutOfBoundsException();
+        poke1(POINTER.POINTER + index / 2, value);
+    }
+
+    public void poke32(int index, int value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= POINTER.PLENGTH / 4)
+            throw new IndexOutOfBoundsException();
+        poke2(POINTER.POINTER + index / 4, value);
+    }
+
+    public void poke32(int index, float value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= POINTER.PLENGTH / 4)
+            throw new IndexOutOfBoundsException();
+        poke4(POINTER.POINTER + index / 4, value);
+    }
+
+    public void poke64(int index, long value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= POINTER.PLENGTH / 8)
+            throw new IndexOutOfBoundsException();
+        poke3(POINTER.POINTER + index / 8, value);
+    }
+
+    public void poke64(int index, double value)
+        throws IndexOutOfBoundsException, NullPointerException
+    {
+        if (POINTER.POINTER == 0L)
+            throw new NullPointerException();
+        else if (index < 0L || index >= POINTER.PLENGTH / 8)
+            throw new IndexOutOfBoundsException();
+        poke5(POINTER.POINTER + index / 8, value);
+    }
+
+    public String toString()
+    {
+        if (POINTER != null) {
+            return POINTER.toString();
+        }
+        else {
+            return "(nil)";
+        }
+    }
+
+}

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

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=786428&r1=786427&r2=786428&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Fri Jun 19 09:32:02 2009
@@ -83,6 +83,7 @@
 	$(SRCDIR)/shared/modules.$(OBJ) \
 	$(SRCDIR)/shared/native.$(OBJ) \
 	$(SRCDIR)/shared/pointer.$(OBJ) \
+	$(SRCDIR)/shared/structure.$(OBJ) \
 	$(SRCDIR)/shared/string.$(OBJ) \
 	$(SRCDIR)/shared/tables.$(OBJ) \
 	$(SRCDIR)/shared/version.$(OBJ)

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=786428&r1=786427&r2=786428&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Fri Jun 19 09:32:02 2009
@@ -77,6 +77,7 @@
 	$(SRCDIR)/shared/modules.$(OBJ) \
 	$(SRCDIR)/shared/native.$(OBJ) \
 	$(SRCDIR)/shared/pointer.$(OBJ) \
+	$(SRCDIR)/shared/structure.$(OBJ) \
 	$(SRCDIR)/shared/string.$(OBJ) \
 	$(SRCDIR)/shared/tables.$(OBJ) \
 	$(SRCDIR)/shared/version.$(OBJ)

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c?rev=786428&r1=786427&r2=786428&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Fri Jun 19 09:32:02 2009
@@ -182,41 +182,6 @@
     return *(N2P(a, char *));
 }
 
-ACR_PTR_EXPORT_DECLARE(jint, peek1)(ACR_JNISTDARGS, jniptr a)
-{
-    UNREFERENCED_STDARGS;
-
-    return *(N2P(a, short *));
-}
-
-ACR_PTR_EXPORT_DECLARE(jint, peek2)(ACR_JNISTDARGS, jniptr a)
-{
-    UNREFERENCED_STDARGS;
-
-    return *(N2P(a, jint *));
-}
-
-ACR_PTR_EXPORT_DECLARE(jlong, peek3)(ACR_JNISTDARGS, jniptr a)
-{
-    UNREFERENCED_STDARGS;
-
-    return *(N2P(a, jlong *));
-}
-
-ACR_PTR_EXPORT_DECLARE(jfloat, peek4)(ACR_JNISTDARGS, jniptr a)
-{
-    UNREFERENCED_STDARGS;
-
-    return *(N2P(a, jfloat *));
-}
-
-ACR_PTR_EXPORT_DECLARE(jdouble, peek5)(ACR_JNISTDARGS, jniptr a)
-{
-    UNREFERENCED_STDARGS;
-
-    return *(N2P(a, jdouble *));
-}
-
 ACR_PTR_EXPORT_DECLARE(void, poke0)(ACR_JNISTDARGS, jniptr a, jint v)
 {
     UNREFERENCED_STDARGS;
@@ -224,41 +189,6 @@
     *(N2P(a, char *)) = (char)v;
 }
 
-ACR_PTR_EXPORT_DECLARE(void, poke1)(ACR_JNISTDARGS, jniptr a, jint v)
-{
-    UNREFERENCED_STDARGS;
-
-    *(N2P(a, short *)) = (short)v;
-}
-
-ACR_PTR_EXPORT_DECLARE(void, poke2)(ACR_JNISTDARGS, jniptr a, jint v)
-{
-    UNREFERENCED_STDARGS;
-
-    *(N2P(a, jint *)) = v;
-}
-
-ACR_PTR_EXPORT_DECLARE(void, poke3)(ACR_JNISTDARGS, jniptr a, jlong v)
-{
-    UNREFERENCED_STDARGS;
-
-    *(N2P(a, jlong *)) = v;
-}
-
-ACR_PTR_EXPORT_DECLARE(void, poke4)(ACR_JNISTDARGS, jniptr a, jfloat v)
-{
-    UNREFERENCED_STDARGS;
-
-    *(N2P(a, jfloat *)) = v;
-}
-
-ACR_PTR_EXPORT_DECLARE(void, poke5)(ACR_JNISTDARGS, jniptr a, jdouble v)
-{
-    UNREFERENCED_STDARGS;
-
-    *(N2P(a, jdouble *)) = v;
-}
-
 ACR_PTR_EXPORT_DECLARE(void, copy0)(ACR_JNISTDARGS, jniptr s,
                                     jniptr d, jniptr l)
 {

Added: commons/sandbox/runtime/trunk/src/main/native/shared/structure.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/structure.c?rev=786428&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/structure.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/structure.c Fri Jun 19 09:32:02 2009
@@ -0,0 +1,122 @@
+/* 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.h"
+#include "acr_private.h"
+#include "acr_error.h"
+#include "acr_clazz.h"
+#include "acr_pointer.h"
+
+/**
+ * Structure class utilities
+ */
+#if CC_SIZEOF_VOIDP == 8
+#define ACR_STR_EXPORT_DECLARE(RT, FN)  \
+    JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_Structure64_##FN
+
+#else
+#define ACR_STR_EXPORT_DECLARE(RT, FN)  \
+    JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_Structure32_##FN
+#endif
+
+ACR_STR_EXPORT_DECLARE(jint, peek0)(ACR_JNISTDARGS, jniptr a)
+{
+    UNREFERENCED_STDARGS;
+
+    return *(N2P(a, char *));
+}
+
+ACR_STR_EXPORT_DECLARE(jint, peek1)(ACR_JNISTDARGS, jniptr a)
+{
+    UNREFERENCED_STDARGS;
+
+    return *(N2P(a, short *));
+}
+
+ACR_STR_EXPORT_DECLARE(jint, peek2)(ACR_JNISTDARGS, jniptr a)
+{
+    UNREFERENCED_STDARGS;
+
+    return *(N2P(a, jint *));
+}
+
+ACR_STR_EXPORT_DECLARE(jlong, peek3)(ACR_JNISTDARGS, jniptr a)
+{
+    UNREFERENCED_STDARGS;
+
+    return *(N2P(a, jlong *));
+}
+
+ACR_STR_EXPORT_DECLARE(jfloat, peek4)(ACR_JNISTDARGS, jniptr a)
+{
+    UNREFERENCED_STDARGS;
+
+    return *(N2P(a, jfloat *));
+}
+
+ACR_STR_EXPORT_DECLARE(jdouble, peek5)(ACR_JNISTDARGS, jniptr a)
+{
+    UNREFERENCED_STDARGS;
+
+    return *(N2P(a, jdouble *));
+}
+
+ACR_STR_EXPORT_DECLARE(void, poke0)(ACR_JNISTDARGS, jniptr a, jint v)
+{
+    UNREFERENCED_STDARGS;
+
+    *(N2P(a, char *)) = (char)v;
+}
+
+ACR_STR_EXPORT_DECLARE(void, poke1)(ACR_JNISTDARGS, jniptr a, jint v)
+{
+    UNREFERENCED_STDARGS;
+
+    *(N2P(a, short *)) = (short)v;
+}
+
+ACR_STR_EXPORT_DECLARE(void, poke2)(ACR_JNISTDARGS, jniptr a, jint v)
+{
+    UNREFERENCED_STDARGS;
+
+    *(N2P(a, jint *)) = v;
+}
+
+ACR_STR_EXPORT_DECLARE(void, poke3)(ACR_JNISTDARGS, jniptr a, jlong v)
+{
+    UNREFERENCED_STDARGS;
+
+    *(N2P(a, jlong *)) = v;
+}
+
+ACR_STR_EXPORT_DECLARE(void, poke4)(ACR_JNISTDARGS, jniptr a, jfloat v)
+{
+    UNREFERENCED_STDARGS;
+
+    *(N2P(a, jfloat *)) = v;
+}
+
+ACR_STR_EXPORT_DECLARE(void, poke5)(ACR_JNISTDARGS, jniptr a, jdouble v)
+{
+    UNREFERENCED_STDARGS;
+
+    *(N2P(a, jdouble *)) = v;
+}

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

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java?rev=786428&r1=786427&r2=786428&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestMemory.java Fri Jun 19 09:32:02 2009
@@ -310,8 +310,9 @@
     {
         Pointer p = Memory.calloc(1000);
         assertNotNull("Pointer", p);
-        p.poke16(498, 2303);
-        assertEquals("Value", 2303, p.peek16(498));
+        Structure s = p.asStructure();
+        s.poke16(498, 2303);
+        assertEquals("Value", 2303, s.peek16(498));
 
         p.free();
     }
@@ -321,8 +322,9 @@
     {
         Pointer p = Memory.calloc(1000);
         assertNotNull("Pointer", p);
-        p.poke32(246, 230364);
-        assertEquals("Value", 230364, p.peek32(246));
+        Structure s = p.asStructure();
+        s.poke32(246, 230364);
+        assertEquals("Value", 230364, s.peek32(246));
 
         p.free();
     }
@@ -332,8 +334,9 @@
     {
         Pointer p = Memory.calloc(1000);
         assertNotNull("Pointer", p);
-        p.poke64(117, 23031964L);
-        assertEquals("Value", 23031964L, p.peek64(117));
+        Structure s = p.asStructure();
+        s.poke64(117, 23031964L);
+        assertEquals("Value", 23031964L, s.peek64(117));
 
         p.free();
     }
@@ -343,8 +346,9 @@
     {
         Pointer p = Memory.calloc(1000);
         assertNotNull("Pointer", p);
-        p.poke32(246, 2303.64F);
-        assertEquals("Value", 2303.64F, p.peek32f(246));
+        Structure s = p.asStructure();
+        s.poke32(246, 2303.64F);
+        assertEquals("Value", 2303.64F, s.peek32f(246));
 
         p.free();
     }
@@ -354,8 +358,9 @@
     {
         Pointer p = Memory.calloc(1000);
         assertNotNull("Pointer", p);
-        p.poke64(117, 2303.1964);
-        assertEquals("Value", 2303.1964, p.peek64f(117));
+        Structure s = p.asStructure();
+        s.poke64(117, 2303.1964);
+        assertEquals("Value", 2303.1964, s.peek64f(117));
 
         p.free();
     }