harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r449462 - in /incubator/harmony/enhanced/classlib/trunk/modules: luni-kernel/src/main/java/org/apache/harmony/kernel/vm/ suncompat/META-INF/ suncompat/src/main/java/sun/misc/
Date Sun, 24 Sep 2006 19:14:55 GMT
Author: ndbeyer
Date: Sun Sep 24 12:14:55 2006
New Revision: 449462

URL: http://svn.apache.org/viewvc?view=rev&rev=449462
Log:
Rework Objects and Threads interfaces; implement sun.misc.Unsafe in terms of Threads and Objects.

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni-kernel/src/main/java/org/apache/harmony/kernel/vm/Objects.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni-kernel/src/main/java/org/apache/harmony/kernel/vm/Threads.java
    incubator/harmony/enhanced/classlib/trunk/modules/suncompat/META-INF/MANIFEST.MF
    incubator/harmony/enhanced/classlib/trunk/modules/suncompat/src/main/java/sun/misc/Unsafe.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni-kernel/src/main/java/org/apache/harmony/kernel/vm/Objects.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni-kernel/src/main/java/org/apache/harmony/kernel/vm/Objects.java?view=diff&rev=449462&r1=449461&r2=449462
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni-kernel/src/main/java/org/apache/harmony/kernel/vm/Objects.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni-kernel/src/main/java/org/apache/harmony/kernel/vm/Objects.java
Sun Sep 24 12:14:55 2006
@@ -16,6 +16,8 @@
 package org.apache.harmony.kernel.vm;
 
 import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 /**
  * <p>
@@ -23,9 +25,30 @@
  * </p>
  */
 public class Objects {
+    private static final Objects INSTANCE = new Objects();
 
     /**
      * <p>
+     * Retrieves an instance of the Objects service.
+     * </p>
+     * 
+     * @return An instance of Objects.
+     */
+    public static Objects getInstance() {
+        // TODO add class loader check
+        return AccessController.doPrivileged(new PrivilegedAction<Objects>() {
+            public Objects run() {
+                return INSTANCE;
+            }
+        });
+    }
+    
+    private Objects() {
+        super();
+    }
+    
+    /**
+     * <p>
      * Retrieves the offset value of the {@link Field} for use by other methods
      * in this class.
      * </p>
@@ -33,10 +56,68 @@
      * @param field The {@link Field} to retrieve the offset for.
      * @return The offset value.
      */
-    public static long objectFieldOffset(Field field) {
+    public  long getFieldOffset(Field field) {
         return 0L;
     }
 
+
+    /**
+     * <p>
+     * Retrieves the base offset for the array Class given. The Class passed
+     * MUST me an array type, such that the method {@link Class#isArray()}
+     * returns <code>true</code>. For example, <code>int[].class</code>.
+     * </p>
+     * 
+     * @param clazz The array Class object.
+     * @return The base offset value.
+     * @throws NullPointerException if <code>clazz</code> is <code>null</code>.
+     * @throws IllegalArgumentException if <code>clazz</code> is not an array
type.
+     */
+    public  int getArrayBaseOffset(Class<?> clazz) {
+        if (!clazz.isArray()) {
+            throw new IllegalArgumentException();
+        }
+        return 0;
+    }
+
+    /**
+     * <p>
+     * Retrieves the array index scale for the array Class given. The index
+     * scale is the value used to determine the offset of a particular element
+     * in the array given the array's base offset and an index. The following
+     * code snippet illustrates the usage.
+     * </p>
+     * 
+     * <pre>
+     * int base = Objects.getArrayBaseOffset(int[].class);
+     * 
+     * int scale = Objects.getArrayIndexScale(int[].class);
+     * 
+     * int elementIdx = 1;
+     * 
+     * int[] array = { 0, 1, 2 };
+     * 
+     * long offsetForIdx = base + (elementIdx * scale);
+     * </pre>
+     * 
+     * <p>
+     * The Class passed MUST me an array type, such that the method
+     * {@link Class#isArray()} returns <code>true</code>. For example,
+     * <code>int[].class</code>.
+     * </p>
+     * 
+     * @param clazz The array Class object.
+     * @return The index scale value.
+     * @throws NullPointerException if <code>clazz</code> is <code>null</code>.
+     * @throws IllegalArgumentException if <code>clazz</code> is not an array
type.
+     */
+    public  int getArrayIndexScale(Class<?> clazz) {
+        if (!clazz.isArray()) {
+            throw new IllegalArgumentException();
+        }
+        return 0;
+    }
+    
     /**
      * <p>
      * Compares and swaps the value of an int-typed field on an Object instance.
@@ -49,7 +130,7 @@
      * @return <code>true</code> if the field was updated, <code>false</code>
      *         otherwise.
      */
-    public static boolean compareAndSwapInt(Object object, long fieldOffset, int expected,
+    public  boolean compareAndSwapInt(Object object, long fieldOffset, int expected,
             int update) {
         return false;
     }
@@ -66,7 +147,7 @@
      * @return <code>true</code> if the field was updated, <code>false</code>
      *         otherwise.
      */
-    public static boolean compareAndSwapLong(Object object, long fieldOffset, long expected,
+    public  boolean compareAndSwapLong(Object object, long fieldOffset, long expected,
             long update) {
         return false;
     }
@@ -84,60 +165,13 @@
      * @return <code>true</code> if the field was updated, <code>false</code>
      *         otherwise.
      */
-    public static boolean compareAndSwapObject(Object object, long fieldOffset,
+    public  boolean compareAndSwapObject(Object object, long fieldOffset,
             Object expected, Object update) {
         return false;
     }
 
     /**
      * <p>
-     * Retrieves the base offset for the array Class given. The Class passed
-     * MUST me any array type, such that the method {@link Class#isArray()}
-     * returns <code>true</code>. For example, <code>int[].class</code>.
-     * </p>
-     * 
-     * @param clazz The array Class object.
-     * @return The base offset value.
-     */
-    public static int arrayBaseOffset(Class<?> clazz) {
-        return 0;
-    }
-
-    /**
-     * <p>
-     * Retrieves the array index scale for the array Class given. The index
-     * scale is the value used to determine the offset of a particular element
-     * in the array given the array's base offset and an index. The following
-     * code snippet illustrates the usage.
-     * </p>
-     * 
-     * <pre>
-     * int base = Objects.arrayBaseOffset(int[].class);
-     * 
-     * int scale = Objects.arrayIndexScale(int[].class);
-     * 
-     * int elementIdx = 1;
-     * 
-     * int[] array = { 0, 1, 2 };
-     * 
-     * long offsetForIdx = base + (elementIdx * scale);
-     * </pre>
-     * 
-     * <p>
-     * The Class passed MUST me any array type, such that the method
-     * {@link Class#isArray()} returns <code>true</code>. For example,
-     * <code>int[].class</code>.
-     * </p>
-     * 
-     * @param clazz The array Class object.
-     * @return The index scale value.
-     */
-    public static int arrayIndexScale(Class<?> clazz) {
-        return 0;
-    }
-
-    /**
-     * <p>
      * Writes an int value to an Object's field as though it were declared
      * <code>volatile</code>.
      * </p>
@@ -146,7 +180,7 @@
      * @param fieldOffset The offset of the field to write to.
      * @param newValue The value to write.
      */
-    public static void putIntVolatile(Object object, long fieldOffset, int newValue) {
+    public  void putIntVolatile(Object object, long fieldOffset, int newValue) {
         return;
     }
 
@@ -160,7 +194,7 @@
      * @param fieldOffset The offset of the field to read from.
      * @return The value that was read.
      */
-    public static int getIntVolatile(Object object, long fieldOffset) {
+    public  int getIntVolatile(Object object, long fieldOffset) {
         return 0;
     }
 
@@ -174,7 +208,7 @@
      * @param fieldOffset The offset of the field to write to.
      * @param newValue The value to write.
      */
-    public static void putLongVolatile(Object object, long fieldOffset, long newValue) {
+    public  void putLongVolatile(Object object, long fieldOffset, long newValue) {
         return;
     }
 
@@ -188,7 +222,7 @@
      * @param fieldOffset The offset of the field to read from.
      * @return The value that was read.
      */
-    public static long getLongVolatile(Object object, long fieldOffset) {
+    public  long getLongVolatile(Object object, long fieldOffset) {
         return 0;
     }
 
@@ -202,7 +236,7 @@
      * @param fieldOffset The offset of the field to write to.
      * @param newValue The value to write.
      */
-    public static void putObjectVolatile(Object object, long fieldOffset, Object newValue)
{
+    public  void putObjectVolatile(Object object, long fieldOffset, Object newValue) {
         return;
     }
 
@@ -216,7 +250,7 @@
      * @param fieldOffset The offset of the field to write to.
      * @param newValue The value to write.
      */
-    public static Object getObjectVolatile(Object object, long fieldOffset) {
+    public  Object getObjectVolatile(Object object, long fieldOffset) {
         return null;
     }
 
@@ -229,7 +263,7 @@
      * @param fieldOffset The offset of the field to write to.
      * @param newValue The value to write.
      */
-    public static void putLong(Object object, long fieldOffset, long newValue) {
+    public  void putLong(Object object, long fieldOffset, long newValue) {
         return;
     }
 
@@ -242,10 +276,7 @@
      * @param fieldOffset The offset of the field to read from.
      * @return The value that was read.
      */
-    public static long getLong(Object object, long fieldOffset) {
+    public  long getLong(Object object, long fieldOffset) {
         return 0L;
-    }
-
-    private Objects() {
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni-kernel/src/main/java/org/apache/harmony/kernel/vm/Threads.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni-kernel/src/main/java/org/apache/harmony/kernel/vm/Threads.java?view=diff&rev=449462&r1=449461&r2=449462
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni-kernel/src/main/java/org/apache/harmony/kernel/vm/Threads.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni-kernel/src/main/java/org/apache/harmony/kernel/vm/Threads.java
Sun Sep 24 12:14:55 2006
@@ -15,12 +15,38 @@
 
 package org.apache.harmony.kernel.vm;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
 /**
  * <p>
  * This class must be implemented by the VM to support the Threading subsystem.
  * </p>
  */
 public class Threads {
+    
+    private static final Threads INSTANCE = new Threads();
+
+    /**
+     * <p>
+     * Retrieves an instance of the Threads service.
+     * </p>
+     * 
+     * @return An instance of Threads.
+     */
+    public static Threads getInstance() {
+        // TODO add class loader check
+        return AccessController.doPrivileged(new PrivilegedAction<Threads>() {
+            public Threads run() {
+                return INSTANCE;
+            }
+        });
+    }
+    
+    private Threads() {
+        super();
+    }
+    
     /**
      * <p>
      * Unparks the {@link Thread} that's passed.
@@ -28,31 +54,31 @@
      * 
      * @param thread The {@link Thread} to unpark.
      */
-    public static void unpark(Thread thread) {
+    public void unpark(Thread thread) {
         return;
     }
-
+    
     /**
      * <p>
-     * Parks the {@link Thread#currentThread() current thread} either for a set
-     * number of nanoseconds or until a future point in time.
+     * Park the {@link Thread#currentThread() current thread} for the specified
+     * number of nanoseconds.
      * </p>
      * 
-     * @param timestamp If <code>true</code> <code>nanosOrTimestamp</code>
-     *        should be consider as a timestamp based on
-     *        {@link System#currentTimeMillis()}. If <code>false</code>,
-     *        then <code>nanosOrTimestamp</code> should be considered as a
-     *        relative number of nanoseconds from when this method was called;
-     *        the value <code>0L</code> can be used in conjunction with this
-     *        to indicate that time is not a factor when parking the thread.
-     * @param nanosOrTimestamp Either a relative number of nanoseconds or a
-     *        timestamp in milliseconds as defined by
-     *        {@link System#currentTimeMillis()}.
+     * @param nanoseconds The number of nanoseconds to park the current thread.
      */
-    public static void park(boolean timestamp, long nanosOrTimestamp) {
+    public void parkFor(long nanoseconds) {
 
     }
 
-    private Threads() {
+    /**
+     * <p>
+     * Park the {@link Thread#currentThread() current thread} until the
+     * specified time, as defined by {@link System#currentTimeMillis()}.
+     * </p>
+     * 
+     * @param time The absolute time to park the current thread until.
+     */
+    public void parkUntil(long time) {
+
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/suncompat/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/suncompat/META-INF/MANIFEST.MF?view=diff&rev=449462&r1=449461&r2=449462
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/suncompat/META-INF/MANIFEST.MF (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/suncompat/META-INF/MANIFEST.MF Sun Sep
24 12:14:55 2006
@@ -7,7 +7,9 @@
 Eclipse-JREBundle: true
 Import-Package: java.io,
  java.lang,
+ java.lang.reflect,
  java.security,
+ org.apache.harmony.kernel.vm,
  org.apache.harmony.luni.util,
  org.apache.harmony.xnet.provider.jsse;hy_usage=suncompat
 Export-Package: com.sun.net.ssl.internal.ssl,

Modified: incubator/harmony/enhanced/classlib/trunk/modules/suncompat/src/main/java/sun/misc/Unsafe.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/suncompat/src/main/java/sun/misc/Unsafe.java?view=diff&rev=449462&r1=449461&r2=449462
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/suncompat/src/main/java/sun/misc/Unsafe.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/suncompat/src/main/java/sun/misc/Unsafe.java
Sun Sep 24 12:14:55 2006
@@ -1,6 +1,11 @@
 package sun.misc;
 
 import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.apache.harmony.kernel.vm.Objects;
+import org.apache.harmony.kernel.vm.Threads;
 
 /**
  * <p>The Unsafe service.</p>
@@ -8,6 +13,8 @@
  */
 public class Unsafe {
 
+    private static final Unsafe INSTANCE = new Unsafe();
+    
     /**
      * <p>
      * Retrieves an instance of this service.
@@ -16,7 +23,19 @@
      * @return An instance of Unsafe.
      */
     public static Unsafe getUnsafe() {
-        return null;
+        return AccessController.doPrivileged(new PrivilegedAction<Unsafe>() {
+            public Unsafe run() {
+                return INSTANCE;
+            }
+        });
+    }
+    
+    private Objects objects;
+    private Threads threads;
+    
+    private Unsafe() {
+        super();
+        this.objects = Objects.getInstance();
     }
 
     /**
@@ -29,7 +48,7 @@
      * @return The offset value.
      */
     public long objectFieldOffset(Field field) {
-        return 0L;
+        return objects.getFieldOffset(field);
     }
 
     /**
@@ -45,7 +64,7 @@
      *         otherwise.
      */
     public boolean compareAndSwapInt(Object object, long fieldOffset, int expected, int update)
{
-        return false;
+        return objects.compareAndSwapInt(object, fieldOffset, expected, update);
     }
 
     /**
@@ -62,7 +81,7 @@
      */
     public boolean compareAndSwapLong(Object object, long fieldOffset, long expected,
             long update) {
-        return false;
+        return objects.compareAndSwapLong(object, fieldOffset, expected, update);
     }
 
     /**
@@ -80,7 +99,7 @@
      */
     public boolean compareAndSwapObject(Object object, long fieldOffset, Object expected,
             Object update) {
-        return false;
+        return objects.compareAndSwapObject(object, fieldOffset, expected, update);
     }
 
     /**
@@ -94,7 +113,7 @@
      * @return The base offset value.
      */
     public int arrayBaseOffset(Class<?> clazz) {
-        return 0;
+        return objects.getArrayBaseOffset(clazz);
     }
 
     /**
@@ -127,7 +146,7 @@
      * @return The index scale value.
      */
     public int arrayIndexScale(Class<?> clazz) {
-        return 0;
+        return objects.getArrayIndexScale(clazz);
     }
 
     /**
@@ -141,7 +160,7 @@
      * @param newValue The value to write.
      */
     public void putIntVolatile(Object object, long fieldOffset, int newValue) {
-        return;
+        objects.putIntVolatile(object, fieldOffset, newValue);
     }
 
     /**
@@ -155,7 +174,7 @@
      * @return The value that was read.
      */
     public int getIntVolatile(Object object, long fieldOffset) {
-        return 0;
+        return objects.getIntVolatile(object, fieldOffset);
     }
 
     /**
@@ -169,7 +188,7 @@
      * @param newValue The value to write.
      */
     public void putLongVolatile(Object object, long fieldOffset, long newValue) {
-        return;
+        objects.putLongVolatile(object, fieldOffset, newValue);
     }
 
     /**
@@ -183,7 +202,7 @@
      * @return The value that was read.
      */
     public long getLongVolatile(Object object, long fieldOffset) {
-        return 0;
+        return objects.getLongVolatile(object, fieldOffset);
     }
 
     /**
@@ -197,7 +216,7 @@
      * @param newValue The value to write.
      */
     public void putObjectVolatile(Object object, long fieldOffset, Object newValue) {
-        return;
+        objects.putObjectVolatile(object, fieldOffset, newValue);
     }
 
     /**
@@ -211,7 +230,7 @@
      * @param newValue The value to write.
      */
     public Object getObjectVolatile(Object object, long fieldOffset) {
-        return null;
+        return objects.getObjectVolatile(object, fieldOffset);
     }
 
     /**
@@ -224,7 +243,7 @@
      * @param newValue The value to write.
      */
     public void putLong(Object object, long fieldOffset, long newValue) {
-        return;
+        objects.putLong(object, fieldOffset, newValue);
     }
 
     /**
@@ -237,7 +256,7 @@
      * @return The value that was read.
      */
     public long getLong(Object object, long fieldOffset) {
-        return 0L;
+        return objects.getLong(object, fieldOffset);
     }
 
     /**
@@ -248,7 +267,7 @@
      * @param thread The {@link Thread} to unpark.
      */
     public void unpark(Thread thread) {
-        return;
+        threads.unpark(thread);
     }
 
     /**
@@ -269,6 +288,10 @@
      *        {@link System#currentTimeMillis()}.
      */
     public void park(boolean timestamp, long nanosOrTimestamp) {
-
+        if (timestamp) {
+            threads.parkFor(nanosOrTimestamp);
+        } else {
+            threads.parkUntil(nanosOrTimestamp);
+        }
     }
 }



Mime
View raw message