commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r887846 - in /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime: ./ util/
Date Mon, 07 Dec 2009 06:34:02 GMT
Author: mturk
Date: Mon Dec  7 06:34:01 2009
New Revision: 887846

URL: http://svn.apache.org/viewvc?rev=887846&view=rev
Log:
Get rid of 32/64 bit class wrappers. Use long for all platforms as generic pointer storage

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/GenericPointer.java
  (with props)
Removed:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/AbstractPointer.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer32.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ConstPointer64.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor32.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor64.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DirectBuffer32.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DirectBuffer64.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
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Utils.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java?rev=887846&r1=887845&r2=887846&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Descriptor.java
Mon Dec  7 06:34:01 2009
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.SyncFailedException;
 import org.apache.commons.runtime.io.Syncable;
+import org.apache.commons.runtime.util.Utils;
 
 /** Represents the Operating System object descriptor.
  * <p>
@@ -34,7 +35,7 @@
  * </p>
  * @since Runtime 1.0
  */
-public abstract class Descriptor implements Closeable, Flushable, Syncable
+public final class Descriptor implements Closeable, Flushable, Syncable
 {
 
     /* Last error operation.
@@ -49,6 +50,11 @@
      */
     private final int IDFLAGS;
 
+    private int       ISVALID;
+    private int       IHANDLE;
+    private long      PHANDLE;
+    private long      HANDLER;
+
     /* Descriptor's attached context.
      * This is opaque data associated with {@code this} Descriptor.
      * <p>
@@ -72,16 +78,18 @@
         IDFLAGS = 0;
     }
 
-    /**
-     * Called by the implementation class constructor.
-     * <p>
-     * Do not derive from this class.
-     * </p>
+    /*
+     * Descriptor can be only created from native code.
+     * Suppress any instantiation except form JNI.
      */
-    protected  Descriptor(int v)
+    private Descriptor(int v, int i, long l, long h)
     {
         IERRNUM = 0;
         IDFLAGS = v;
+        IHANDLE = i;
+        PHANDLE = l;
+        HANDLER = h;
+        ISVALID = 1;
         CONTEXT = null;
     }
 
@@ -250,13 +258,23 @@
      * @return {@code true} if descriptor is valid and not closed
      *         {@code false} otherwise.
      */
-    public abstract boolean valid();
+    public boolean valid()
+    {
+        // true if both int is negative and pointer is NULL
+        if (ISVALID == 0 || (IHANDLE < 0 && PHANDLE == 0L))
+            return false;
+        else
+            return true;
+    }
 
     /**
      * Get underlying Operating system descriptor.
      * @return operating system descriptor.
      */
-    public abstract int fd();
+    public int fd()
+    {
+        return IHANDLE;
+    }
 
     /**
      * Compares this {@code Descriptor} to the specified object.
@@ -268,7 +286,20 @@
      *      equal. Returns false otherwise.
      */
     @Override
-    public abstract boolean equals(Object other);
+    public boolean equals(Object other)
+    {
+        if (other == null)
+            return false;
+        if (other == this)
+            return true;
+        if (Descriptor.class != other.getClass())
+            return false;
+        if (PHANDLE == ((Descriptor)other).PHANDLE &&
+            IHANDLE == ((Descriptor)other).IHANDLE)
+            return true;
+        else
+            return false;
+    }
 
     /**
      * Returns a string representation of the Descriptor.
@@ -278,7 +309,18 @@
      * @return a string representation of the descriptor.
      */
     @Override
-    public abstract String toString();
+    public String toString()
+    {
+        if (PHANDLE != 0) {
+            return Utils.hex(PHANDLE);
+        }
+        else if (IHANDLE >= 0) {
+            return "#" + Integer.toString(IHANDLE);
+        }
+        else {
+            return "(nil)";
+        }
+    }
 
 }
 

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=887846&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
Mon Dec  7 06:34:01 2009
@@ -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++ pointer.
+ *
+ * @since Runtime 1.0
+ */
+final class GenericPointer extends Pointer
+{
+
+    private GenericPointer()
+    {
+        // No instance
+    }
+
+    /*
+     * Only created from JNI code.
+     */
+    private GenericPointer(long ptr, long clr, long len)
+    {
+        POINTER = ptr;
+        CLEANUP = clr;
+        PLENGTH = len;
+        ISCONST = false;
+    }
+
+}
+

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

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java?rev=887846&r1=887845&r2=887846&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Memory.java Mon
Dec  7 06:34:01 2009
@@ -183,9 +183,56 @@
         realloc0(ptr, size);
     }
 
-    private static native Pointer slice0(Pointer src, long offset, long 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(Pointer src, long offset, long size)
+    private static native Pointer slice1(long src, long size)
         throws IndexOutOfBoundsException;
     /**
      * Creates a new {@link Pointer} object whose content is a shared
@@ -213,14 +260,22 @@
         throws IndexOutOfBoundsException, IllegalArgumentException,
                NullPointerException
     {
+        if (src == null)
+            throw new NullPointerException();
         if (offset < 0L || size < 1L)
             throw new IllegalArgumentException();
-        if (src instanceof ConstPointer)
-            return slice1(src, offset, size);
+        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, offset, size);
+            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;
@@ -245,16 +300,18 @@
         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, offset, size);
+        return dup0(src.POINTER + offset, size);
     }
 
-    private static native void copy0(Pointer src, long srcPos, Pointer dst,
-                                     long dstPos, long length)
-        throws IndexOutOfBoundsException, IllegalArgumentException,
-               RuntimeException;
+    private static native void copy0(long src, long dst, long length)
+        throws RuntimeException;
     /**
      * Copy the memory area from {@code src} to {@code dst}.
      * <p>
@@ -286,20 +343,23 @@
                NullPointerException, RuntimeException,
                UnsupportedOperationException
     {
-        if (srcPos < 0L || dstPos < 0L)
+        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 (length < 1L)
-            throw new IllegalArgumentException();
-        if (dst instanceof ConstPointer)
+        if (dst.ISCONST)
             throw new UnsupportedOperationException();
-
-        copy0(src, srcPos, dst, dstPos, length);
+        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(Pointer src, long srcPos, Pointer dst,
-                                     long dstPos, long length)
-        throws IndexOutOfBoundsException, IllegalArgumentException,
-               RuntimeException;
+    private static native void move0(long src, long dst, long length)
+        throws RuntimeException;
     /**
      * Copy the memory area from {@code src} to {@code dst}.
      * <p>
@@ -330,18 +390,23 @@
                NullPointerException, RuntimeException,
                UnsupportedOperationException
     {
-        if (srcPos < 0L || dstPos < 0L)
+        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 (length < 1L)
-            throw new IllegalArgumentException();
-        if (dst instanceof ConstPointer)
+        if (dst.ISCONST)
             throw new UnsupportedOperationException();
-
-        move0(src, srcPos, dst, dstPos, length);
+        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(Pointer ptr, long offset, long length)
-        throws IndexOutOfBoundsException, RuntimeException;
+    private static native void clear0(long ptr, long length)
+        throws RuntimeException;
     /**
      * Set the {@code ptr} memory area from {@code src} to {@code zero}.
      *
@@ -364,16 +429,19 @@
                NullPointerException, RuntimeException,
                UnsupportedOperationException
     {
+        if (ptr == null || ptr.POINTER == 0L)
+            throw new NullPointerException();
         if (offset < 0L || length < 1L)
             throw new IllegalArgumentException();
-        if (ptr instanceof ConstPointer)
+        if (ptr.ISCONST)
             throw new UnsupportedOperationException();
-
-        clear0(ptr, offset, length);
+        if (offset + length > ptr.PLENGTH)
+            throw new IndexOutOfBoundsException();
+        clear0(ptr.POINTER + offset, length);
     }
 
-    private static native void set0(Pointer ptr, long offset, long length, int val)
-        throws IndexOutOfBoundsException, RuntimeException;
+    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}.
      *
@@ -397,12 +465,15 @@
                NullPointerException, RuntimeException,
                UnsupportedOperationException
     {
+        if (ptr == null || ptr.POINTER == 0L)
+            throw new NullPointerException();
         if (offset < 0L || length < 1L)
             throw new IllegalArgumentException();
-        if (ptr instanceof ConstPointer)
+        if (ptr.ISCONST)
             throw new UnsupportedOperationException();
-
-        set0(ptr, offset, length, val);
+        if (offset + length > ptr.PLENGTH)
+            throw new IndexOutOfBoundsException();
+        set0(ptr.POINTER + offset, length, val);
     }
 
     private static native byte[] array0(Pointer ptr, long offset, int length)

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer.java?rev=887846&r1=887845&r2=887846&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 Mon
Dec  7 06:34:01 2009
@@ -16,49 +16,105 @@
 
 package org.apache.commons.runtime;
 
-/** Represents the Operating System C/C++ pointer.
+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 interface Pointer extends Comparable<Pointer>
+public abstract class Pointer implements Comparable<Pointer>
 {
 
+    protected long    CLEANUP;
+    protected long    POINTER;
+    protected long    PLENGTH;
+    protected boolean ISCONST;
+
+    /**
+     * Create new {@code null} Pointer instance.
+     * <p>
+     * Depending on the platform the created {@code Pointer}
+     * object is either {@code Pointer32} for 32-bit machines
+     * or {@code 64-bit} for 64-bit machines.
+     * </p>
+     * <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 cleanup0()
+        throws Throwable;
+
+    /* Used for finalize only.
+     * Doesn't throw exception in case of error
+     * returned from internal cleanup callback.
+     */
+    private native void cleanup1()
+        throws Throwable;
+
+    private static native Pointer nullp0();
 
     /**
      * Represents a C/C++ NULL {@code pointer}.
      */
-    public static final Pointer NULL = AbstractPointer.NULL;
+    public static final Pointer NULL;
+    static {
+        NULL = nullp0();
+    }
 
     /**
      * Address of the internal pointer.
-     * <p>
-     * Depending on the operating system the {@code Number} can be
-     * either {@code Integer} for 32 bit systems of {@code Long} for
-     * a 64 bit system.
-     *</p>
      *
-     * @return Internal pointer address casted to the {@code Number}.
+     * @return Internal pointer address casted to the {@code long}.
      */
-    public Number address();
+    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 is {@link Sizeof#POINTER Sizeof.POINTER}.
+     * the returned size if Pointer {@code SIZEOF}.
      *</p>
      *
      * @return Internal pointer size.
      */
-    public long sizeof();
+    public long sizeof()
+    {
+        return PLENGTH;    
+    }
+
 
     /**
      * Check if the pointer is valid
      * @return true if the internal pointer is not {@code NULL}.
      */
-    public boolean isNull();
+    public boolean isNull()
+    {
+        return POINTER == 0L;
+    }
 
     /**
      * Compares this {@code Pointer} to the specified object.
@@ -70,94 +126,72 @@
      *      equal. Returns false otherwise.
      */
     @Override
-    public boolean equals(Object other);
+    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;
+    }
 
     /**
-     * Free the allocated resource by the Operating system.
-     * <p>
-     * Note that {@code Object.finalize()} method will call
-     * this method. However if the native code can block for
-     * long time explicit {@code free()} should be called.
-     * </p>
+     * 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.
      */
-    public void free()
-        throws Throwable;
-
-    /**
-     * 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 int    peek(int index)
-        throws IndexOutOfBoundsException, NullPointerException;
-
-    /**
-     * 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 void poke(int index, int value)
-        throws IndexOutOfBoundsException, NullPointerException;
-
-    /**
-     * Copy the memory area from {@code this} pointer 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 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 this} or {@code dst} is
-     *          {@code null}.
-     */
-    public void copy(long srcPos, Pointer dst, long dstPos, long length)
-        throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException;
+    @Override
+    protected final void finalize()
+        throws Throwable
+    {
+        cleanup1();
+    }
 
     /**
-     * Copy the memory area from pointer {@code src} to {@code this} pointer.
+     * Free the allocated resource by the Operating system.
      * <p>
-     * Method uses the {@code memmove} function to do a copying, meaning
-     * that {@code source} and {@code destination} memory areas can overlap.
+     * 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>
-     *
-     * @param src source {@code Pointer}.
-     * @param srcPos starting position in the source memory.
-     * @param dstPos starting position in our memory area.
-     * @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 this} or {@code dst} is
-     *          {@code null}.
-     */
-    public void move(Pointer src, long srcPos, long dstPos, long length)
-        throws IndexOutOfBoundsException, IllegalArgumentException,
-               NullPointerException;
-
+     * @see #finalize()
+     * @throws Throwable the {@code Exception} raised by this method.
+     */
+    public final void free()
+        throws Throwable
+    {
+        cleanup0();
+    }
 
     /**
      * Returns a string representation of the Pointer.
@@ -166,7 +200,18 @@
      * @return a hexadecimal representation of the pointer.
      */
     @Override
-    public String toString();
+    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)";
+        }
+    }
 
 }
 

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Utils.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Utils.java?rev=887846&r1=887845&r2=887846&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Utils.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Utils.java
Mon Dec  7 06:34:01 2009
@@ -39,6 +39,7 @@
     private static long     timer                  = System.currentTimeMillis();
     private static Random   rnd                    = new Random(timer);
     private static File     tmpdir                 = null;
+    private static Object   lock                   = new Object();
 
     private static final char[] hc = {
                 '0', '1', '2', '3', '4', '5', '6', '7',
@@ -188,27 +189,34 @@
 
     public static File getTempPath()
     {
-        String [] try_path;
 
         if (tmpdir != null)
             return tmpdir;
-        tmpdir = checkTempDir(System.getProperty("java.io.tmpdir"));
-        if (tmpdir != null)
-            return tmpdir;
-        for (int i = 0; i < try_envs.length; i++) {
-            tmpdir = checkTempDir(System.getenv(try_envs[i]));
+
+        synchronized(lock) { 
             if (tmpdir != null)
                 return tmpdir;
-        }
-        if (SystemId.getSysname().equals("windows"))
-            try_path = win_trys;
-        else
-            try_path = psx_trys;
-
-        for (int i = 0; i < try_path.length; i++) {
-            tmpdir = checkTempDir(System.getenv(try_path[i]));
+            tmpdir = checkTempDir(System.getProperty("java.io.tmpdir"));
             if (tmpdir != null)
                 return tmpdir;
+
+            for (int i = 0; i < try_envs.length; i++) {
+                tmpdir = checkTempDir(System.getenv(try_envs[i]));
+                if (tmpdir != null)
+                    return tmpdir;
+            }
+
+            String [] try_path;
+            if (SystemId.getSysname().equals("windows"))
+                try_path = win_trys;
+            else
+                try_path = psx_trys;
+    
+            for (int i = 0; i < try_path.length; i++) {
+                tmpdir = checkTempDir(System.getenv(try_path[i]));
+                if (tmpdir != null)
+                    return tmpdir;
+            }
         }
         return null;
     }



Mime
View raw message