harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r423372 - in /incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java: java/util/concurrent/ java/util/concurrent/atomic/ java/util/concurrent/locks/ org/apache/harmony/concurrent/ sun/ sun/misc/
Date Wed, 19 Jul 2006 05:18:06 GMT
Author: ndbeyer
Date: Tue Jul 18 22:18:05 2006
New Revision: 423372

URL: http://svn.apache.org/viewvc?rev=423372&view=rev
Log:
Restore code to original state from concurrency interest site's CVS repository and add a stub version of the sun.misc.Unsafe class.

Added:
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/sun/
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/sun/misc/
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/sun/misc/Unsafe.java   (with props)
Removed:
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/org/apache/harmony/concurrent/AtomicSupport.java
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/org/apache/harmony/concurrent/LocksSupport.java
Modified:
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/ConcurrentHashMap.java
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicBoolean.java
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicInteger.java
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicIntegerArray.java
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicLong.java
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicLongArray.java
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicLongFieldUpdater.java
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicReference.java
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicReferenceArray.java
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/locks/AbstractQueuedSynchronizer.java
    incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/locks/LockSupport.java

Modified: incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/ConcurrentHashMap.java
URL: http://svn.apache.org/viewvc/incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/ConcurrentHashMap.java?rev=423372&r1=423371&r2=423372&view=diff
==============================================================================
--- incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/ConcurrentHashMap.java (original)
+++ incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/ConcurrentHashMap.java Tue Jul 18 22:18:05 2006
@@ -1,18 +1,3 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed 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.
- */
-
 /*
  * Written by Doug Lea with assistance from members of JCP JSR-166
  * Expert Group and released to the public domain, as explained at
@@ -835,7 +820,8 @@
      * @param t Mappings to be stored in this map.
      */
     public void putAll(Map<? extends K, ? extends V> t) {
-        for (Map.Entry<? extends K, ? extends V> e : t.entrySet()) {
+        for (Iterator<? extends Map.Entry<? extends K, ? extends V>> it = (Iterator<? extends Map.Entry<? extends K, ? extends V>>) t.entrySet().iterator(); it.hasNext(); ) {
+            Entry<? extends K, ? extends V> e = it.next();
             put(e.getKey(), e.getValue());
         }
     }

Modified: incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicBoolean.java
URL: http://svn.apache.org/viewvc/incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicBoolean.java?rev=423372&r1=423371&r2=423372&view=diff
==============================================================================
--- incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicBoolean.java (original)
+++ incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicBoolean.java Tue Jul 18 22:18:05 2006
@@ -1,18 +1,3 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed 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.
- */
-
 /*
  * Written by Doug Lea with assistance from members of JCP JSR-166
  * Expert Group and released to the public domain, as explained at
@@ -20,9 +5,7 @@
  */
 
 package java.util.concurrent.atomic;
-import java.lang.reflect.Field;
-
-import org.apache.harmony.concurrent.AtomicSupport;
+import sun.misc.Unsafe;
 
 /**
  * A <tt>boolean</tt> value that may be updated atomically. See the
@@ -37,19 +20,18 @@
  */
 public class AtomicBoolean implements java.io.Serializable {
     private static final long serialVersionUID = 4654671469794556979L;
+    // setup to use Unsafe.compareAndSwapInt for updates
+    private static final Unsafe unsafe =  Unsafe.getUnsafe();
+    private static final long valueOffset;
 
-    private static final AtomicSupport SUPPORT = AtomicSupport.getInstance();
-    
-    private static final Field VALUE_FIELD;
     static {
-        try {
-            VALUE_FIELD = AtomicBoolean.class.getDeclaredField("value");
-        } catch (Exception ex) {
-            throw new AssertionError(ex);
-        }
+      try {
+        valueOffset = unsafe.objectFieldOffset
+            (AtomicBoolean.class.getDeclaredField("value"));
+      } catch (Exception ex) { throw new Error(ex); }
     }
 
-    private volatile boolean value;
+    private volatile int value;
 
     /**
      * Creates a new <tt>AtomicBoolean</tt> with the given initial value.
@@ -57,7 +39,7 @@
      * @param initialValue the initial value
      */
     public AtomicBoolean(boolean initialValue) {
-        value = initialValue;
+        value = initialValue ? 1 : 0;
     }
 
     /**
@@ -72,7 +54,7 @@
      * @return the current value
      */
     public final boolean get() {
-        return value;
+        return value != 0;
     }
 
     /**
@@ -88,7 +70,9 @@
      * @return true if successful
      */
     public final boolean compareAndSet(boolean expect, boolean update) {
-        return SUPPORT.compareAndSet(this, VALUE_FIELD, expect, update);
+        int e = expect ? 1 : 0;
+        int u = update ? 1 : 0;
+        return unsafe.compareAndSwapInt(this, valueOffset, e, u);
     }
 
     /**
@@ -100,7 +84,9 @@
      * @return true if successful.
      */
     public boolean weakCompareAndSet(boolean expect, boolean update) {
-        return SUPPORT.compareAndSet(this, VALUE_FIELD, expect, update);
+        int e = expect ? 1 : 0;
+        int u = update ? 1 : 0;
+        return unsafe.compareAndSwapInt(this, valueOffset, e, u);
     }
 
     /**
@@ -109,7 +95,7 @@
      * @param newValue the new value
      */
     public final void set(boolean newValue) {
-        value = newValue;
+        value = newValue ? 1 : 0;
     }
 
     /**

Modified: incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicInteger.java
URL: http://svn.apache.org/viewvc/incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicInteger.java?rev=423372&r1=423371&r2=423372&view=diff
==============================================================================
--- incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicInteger.java (original)
+++ incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicInteger.java Tue Jul 18 22:18:05 2006
@@ -1,18 +1,3 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed 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.
- */
-
 /*
  * Written by Doug Lea with assistance from members of JCP JSR-166
  * Expert Group and released to the public domain, as explained at
@@ -20,9 +5,7 @@
  */
 
 package java.util.concurrent.atomic;
-import java.lang.reflect.Field;
-
-import org.apache.harmony.concurrent.AtomicSupport;
+import sun.misc.Unsafe;
 
 /**
  * An <tt>int</tt> value that may be updated atomically. See the
@@ -41,15 +24,15 @@
 public class AtomicInteger extends Number implements java.io.Serializable { 
     private static final long serialVersionUID = 6214790243416807050L;
 
-    private static final AtomicSupport SUPPORT = AtomicSupport.getInstance();
-    
-    private static final Field VALUE_FIELD;
+    // setup to use Unsafe.compareAndSwapInt for updates
+    private static final Unsafe unsafe =  Unsafe.getUnsafe();
+    private static final long valueOffset;
+
     static {
-        try {
-            VALUE_FIELD = AtomicInteger.class.getDeclaredField("value");
-        } catch (Exception ex) {
-            throw new AssertionError(ex);
-        }
+      try {
+        valueOffset = unsafe.objectFieldOffset
+            (AtomicInteger.class.getDeclaredField("value"));
+      } catch(Exception ex) { throw new Error(ex); }
     }
 
     private volatile int value;
@@ -111,7 +94,7 @@
      * the actual value was not equal to the expected value.
      */
     public final boolean compareAndSet(int expect, int update) {
-      return SUPPORT.compareAndSet(this, VALUE_FIELD, expect, update);
+      return unsafe.compareAndSwapInt(this, valueOffset, expect, update);
     }
 
     /**
@@ -123,7 +106,7 @@
      * @return true if successful.
      */
     public final boolean weakCompareAndSet(int expect, int update) {
-        return SUPPORT.compareAndSet(this, VALUE_FIELD, expect, update);
+      return unsafe.compareAndSwapInt(this, valueOffset, expect, update);
     }
 
 

Modified: incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicIntegerArray.java
URL: http://svn.apache.org/viewvc/incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicIntegerArray.java?rev=423372&r1=423371&r2=423372&view=diff
==============================================================================
--- incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicIntegerArray.java (original)
+++ incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicIntegerArray.java Tue Jul 18 22:18:05 2006
@@ -1,18 +1,3 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed 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.
- */
-
 /*
  * Written by Doug Lea with assistance from members of JCP JSR-166
  * Expert Group and released to the public domain, as explained at
@@ -20,9 +5,8 @@
  */
 
 package java.util.concurrent.atomic;
-import java.util.Arrays;
-
-import org.apache.harmony.concurrent.AtomicSupport;
+import sun.misc.Unsafe;
+import java.util.*;
 
 /**
  * An <tt>int</tt> array in which elements may be updated atomically.
@@ -34,11 +18,19 @@
  */
 public class AtomicIntegerArray implements java.io.Serializable { 
     private static final long serialVersionUID = 2862133569453604235L;
-    
-    private static final AtomicSupport SUPPORT = AtomicSupport.getInstance();
 
+   // setup to use Unsafe.compareAndSwapInt for updates
+    private static final Unsafe unsafe =  Unsafe.getUnsafe();
+    private static final int base = unsafe.arrayBaseOffset(int[].class);
+    private static final int scale = unsafe.arrayIndexScale(int[].class);
     private final int[] array;
 
+    private long rawIndex(int i) {
+        if (i < 0 || i >= array.length)
+            throw new IndexOutOfBoundsException("index " + i);
+        return base + i * scale;
+    }
+
     /**
      * Create a new AtomicIntegerArray of given length.
      *
@@ -47,9 +39,8 @@
     public AtomicIntegerArray(int length) {
         array = new int[length];
         // must perform at least one volatile write to conform to JMM
-        if (length > 0) {
-            SUPPORT.volatileSet(array, 0, 0);
-        }
+        if (length > 0)
+            unsafe.putIntVolatile(array, rawIndex(0), 0);
     }
 
     /**
@@ -69,7 +60,7 @@
             for (int i = 0; i < last; ++i)
                 this.array[i] = array[i];
             // Do the last write as volatile
-            SUPPORT.volatileSet(this.array, last, array[last]);
+            unsafe.putIntVolatile(this.array, rawIndex(last), array[last]);
         }
     }
 
@@ -89,7 +80,7 @@
      * @return the current value
      */
     public final int get(int i) {
-        return SUPPORT.volatileGet(array, i);
+        return unsafe.getIntVolatile(array, rawIndex(i));
     }
  
     /**
@@ -99,7 +90,7 @@
      * @param newValue the new value
      */
     public final void set(int i, int newValue) {
-        SUPPORT.volatileSet(array, i, newValue);
+        unsafe.putIntVolatile(array, rawIndex(i), newValue);
     }
   
     /**
@@ -129,7 +120,8 @@
      * the actual value was not equal to the expected value.
      */
     public final boolean compareAndSet(int i, int expect, int update) {
-        return SUPPORT.compareAndSet(array, i, expect, update);
+        return unsafe.compareAndSwapInt(array, rawIndex(i), 
+                                        expect, update);
     }
 
     /**

Modified: incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java
URL: http://svn.apache.org/viewvc/incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java?rev=423372&r1=423371&r2=423372&view=diff
==============================================================================
--- incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java (original)
+++ incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java Tue Jul 18 22:18:05 2006
@@ -1,18 +1,3 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed 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.
- */
-
 /*
  * Written by Doug Lea with assistance from members of JCP JSR-166
  * Expert Group and released to the public domain, as explained at
@@ -20,10 +5,8 @@
  */
 
 package java.util.concurrent.atomic;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-
-import org.apache.harmony.concurrent.AtomicSupport;
+import sun.misc.Unsafe;
+import java.lang.reflect.*;
 
 /**
  * A reflection-based utility that enables atomic updates to
@@ -43,9 +26,6 @@
  * @param <T> The type of the object holding the updatable field
  */
 public abstract class  AtomicIntegerFieldUpdater<T>  {
-    
-    private static final AtomicSupport SUPPORT = AtomicSupport.getInstance();
-    
     /**
      * Creates an updater for objects with the given field.  The Class
      * argument is needed to check that reflective types and generic
@@ -223,8 +203,12 @@
         }
     }
 
+    /**
+     * Standard hotspot implementation using intrinsics
+     */
     private static class AtomicIntegerFieldUpdaterImpl<T> extends AtomicIntegerFieldUpdater<T> {
-        private final Field field;
+        private static final Unsafe unsafe =  Unsafe.getUnsafe();
+        private final long offset;
         private final Class<T> tclass;
 
         AtomicIntegerFieldUpdaterImpl(Class<T> tclass, String fieldName) {
@@ -243,33 +227,31 @@
                 throw new IllegalArgumentException("Must be volatile type");
          
             this.tclass = tclass;
-            this.field = field;
+            offset = unsafe.objectFieldOffset(field);
         }
 
         public boolean compareAndSet(T obj, int expect, int update) {
             if (!tclass.isInstance(obj))
                 throw new ClassCastException();
-            return SUPPORT.compareAndSet(obj, field, expect, update);
+            return unsafe.compareAndSwapInt(obj, offset, expect, update);
         }
 
         public boolean weakCompareAndSet(T obj, int expect, int update) {
             if (!tclass.isInstance(obj))
                 throw new ClassCastException();
-            return SUPPORT.compareAndSet(obj, field, expect, update);
+            return unsafe.compareAndSwapInt(obj, offset, expect, update);
         }
 
         public void set(T obj, int newValue) {
             if (!tclass.isInstance(obj))
                 throw new ClassCastException();
-            
-            SUPPORT.volatileSetInt(obj, field, newValue);
+            unsafe.putIntVolatile(obj, offset, newValue);
         }
 
         public final int get(T obj) {
             if (!tclass.isInstance(obj))
                 throw new ClassCastException();
-            
-            return SUPPORT.volatileGetInt(obj, field);
+            return unsafe.getIntVolatile(obj, offset);
         }
     }
 }

Modified: incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicLong.java
URL: http://svn.apache.org/viewvc/incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicLong.java?rev=423372&r1=423371&r2=423372&view=diff
==============================================================================
--- incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicLong.java (original)
+++ incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicLong.java Tue Jul 18 22:18:05 2006
@@ -1,18 +1,3 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed 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.
- */
-
 /*
  * Written by Doug Lea with assistance from members of JCP JSR-166
  * Expert Group and released to the public domain, as explained at
@@ -20,9 +5,7 @@
  */
 
 package java.util.concurrent.atomic;
-import java.lang.reflect.Field;
-
-import org.apache.harmony.concurrent.AtomicSupport;
+import sun.misc.Unsafe;
 
 /**
  * A <tt>long</tt> value that may be updated atomically.  See the
@@ -39,16 +22,30 @@
  */
 public class AtomicLong extends Number implements java.io.Serializable { 
     private static final long serialVersionUID = 1927816293512124184L;
-    
-    private static final AtomicSupport SUPPORT = AtomicSupport.getInstance();
 
-    private static final Field VALUE_FIELD;
+    // setup to use Unsafe.compareAndSwapLong for updates
+    private static final Unsafe unsafe =  Unsafe.getUnsafe();
+    private static final long valueOffset;
+
+    /**
+     * Record whether the underlying JVM supports lockless
+     * CompareAndSet for longs. While the unsafe.CompareAndSetLong
+     * method works in either case, some constructions should be
+     * handled at Java level to avoid locking user-visible locks.
+     */
+    static final boolean VM_SUPPORTS_LONG_CAS = VMSupportsCS8();
+
+    /**
+     * Returns whether underlying JVM supports lockless CompareAndSet
+     * for longs. Called only once and cached in VM_SUPPORTS_LONG_CAS.
+     */
+    private static native boolean VMSupportsCS8();
+
     static {
-        try {
-            VALUE_FIELD = AtomicLong.class.getDeclaredField("value");
-        } catch (Exception ex) {
-            throw new AssertionError(ex);
-        }
+      try {
+        valueOffset = unsafe.objectFieldOffset
+            (AtomicLong.class.getDeclaredField("value"));
+      } catch(Exception ex) { throw new Error(ex); }
     }
 
     private volatile long value;
@@ -109,7 +106,7 @@
      * the actual value was not equal to the expected value.
      */
     public final boolean compareAndSet(long expect, long update) {
-      return SUPPORT.compareAndSet(this, VALUE_FIELD, expect, update);
+      return unsafe.compareAndSwapLong(this, valueOffset, expect, update);
     }
 
     /**
@@ -121,7 +118,7 @@
      * @return true if successful.
      */
     public final boolean weakCompareAndSet(long expect, long update) {
-        return SUPPORT.compareAndSet(this, VALUE_FIELD, expect, update);
+      return unsafe.compareAndSwapLong(this, valueOffset, expect, update);
     }
   
     /**

Modified: incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicLongArray.java
URL: http://svn.apache.org/viewvc/incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicLongArray.java?rev=423372&r1=423371&r2=423372&view=diff
==============================================================================
--- incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicLongArray.java (original)
+++ incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicLongArray.java Tue Jul 18 22:18:05 2006
@@ -1,18 +1,3 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed 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.
- */
-
 /*
  * Written by Doug Lea with assistance from members of JCP JSR-166
  * Expert Group and released to the public domain, as explained at
@@ -20,9 +5,8 @@
  */
 
 package java.util.concurrent.atomic;
-import java.util.Arrays;
-
-import org.apache.harmony.concurrent.AtomicSupport;
+import sun.misc.Unsafe;
+import java.util.*;
 
 /**
  * A <tt>long</tt> array in which elements may be updated atomically.
@@ -33,11 +17,19 @@
  */
 public class AtomicLongArray implements java.io.Serializable { 
     private static final long serialVersionUID = -2308431214976778248L;
-    
-    private static final AtomicSupport SUPPORT = AtomicSupport.getInstance();
 
+    // setup to use Unsafe.compareAndSwapInt for updates
+    private static final Unsafe unsafe =  Unsafe.getUnsafe();
+    private static final int base = unsafe.arrayBaseOffset(long[].class);
+    private static final int scale = unsafe.arrayIndexScale(long[].class);
     private final long[] array;
 
+    private long rawIndex(int i) {
+        if (i < 0 || i >= array.length)
+            throw new IndexOutOfBoundsException("index " + i);
+        return base + i * scale;
+    }
+
     /**
      * Create a new AtomicLongArray of given length.
      * @param length the length of the array
@@ -45,9 +37,8 @@
     public AtomicLongArray(int length) {
         array = new long[length];
         // must perform at least one volatile write to conform to JMM
-        if (length > 0) {
-            SUPPORT.volatileSet(array, 0, 0);
-        }
+        if (length > 0) 
+            unsafe.putLongVolatile(array, rawIndex(0), 0);
     }
 
     /**
@@ -67,7 +58,7 @@
             for (int i = 0; i < last; ++i)
                 this.array[i] = array[i];
             // Do the last write as volatile
-            SUPPORT.volatileSet(this.array, last, array[last]);
+            unsafe.putLongVolatile(this.array, rawIndex(last), array[last]);
         }
     }
 
@@ -87,7 +78,7 @@
      * @return the current value
      */
     public final long get(int i) {
-        return SUPPORT.volatileGet(array, i);
+        return unsafe.getLongVolatile(array, rawIndex(i));
     }
  
     /**
@@ -97,7 +88,7 @@
      * @param newValue the new value
      */
     public final void set(int i, long newValue) {
-        SUPPORT.volatileSet(array, i, newValue);
+        unsafe.putLongVolatile(array, rawIndex(i), newValue);
     }
   
     /**
@@ -126,7 +117,8 @@
      * the actual value was not equal to the expected value.
      */
     public final boolean compareAndSet(int i, long expect, long update) {
-        return SUPPORT.compareAndSet(array, i, expect, update);
+        return unsafe.compareAndSwapLong(array, rawIndex(i), 
+                                         expect, update);
     }
 
     /**

Modified: incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicLongFieldUpdater.java
URL: http://svn.apache.org/viewvc/incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicLongFieldUpdater.java?rev=423372&r1=423371&r2=423372&view=diff
==============================================================================
--- incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicLongFieldUpdater.java (original)
+++ incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicLongFieldUpdater.java Tue Jul 18 22:18:05 2006
@@ -1,18 +1,3 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed 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.
- */
-
 /*
  * Written by Doug Lea with assistance from members of JCP JSR-166
  * Expert Group and released to the public domain, as explained at
@@ -20,10 +5,8 @@
  */
 
 package java.util.concurrent.atomic;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-
-import org.apache.harmony.concurrent.AtomicSupport;
+import sun.misc.Unsafe;
+import java.lang.reflect.*;
 
 /**
  * A reflection-based utility that enables atomic updates to
@@ -44,9 +27,6 @@
  * @param <T> The type of the object holding the updatable field
  */
 public abstract class  AtomicLongFieldUpdater<T>  {
-    
-    private static final AtomicSupport SUPPORT = AtomicSupport.getInstance();
-    
     /**
      * Creates an updater for objects with the given field.  The Class
      * argument is needed to check that reflective types and generic
@@ -60,7 +40,10 @@
      * exception if the class does not hold field or is the wrong type.
      */
     public static <U> AtomicLongFieldUpdater<U> newUpdater(Class<U> tclass, String fieldName) {
-        return new CASUpdater<U>(tclass, fieldName);
+        if (AtomicLong.VM_SUPPORTS_LONG_CAS)
+            return new CASUpdater<U>(tclass, fieldName);
+        else
+            return new LockedUpdater<U>(tclass, fieldName);
     }
 
     /**
@@ -225,7 +208,8 @@
     }
 
     private static class CASUpdater<T> extends AtomicLongFieldUpdater<T> {
-        private final Field field;
+        private static final Unsafe unsafe =  Unsafe.getUnsafe();
+        private final long offset;
         private final Class<T> tclass;
 
         CASUpdater(Class<T> tclass, String fieldName) {
@@ -244,33 +228,89 @@
                 throw new IllegalArgumentException("Must be volatile type");
             
             this.tclass = tclass;
-            this.field = field;
+            offset = unsafe.objectFieldOffset(field);
         }
 
         public boolean compareAndSet(T obj, long expect, long update) {
             if (!tclass.isInstance(obj))
                 throw new ClassCastException();
-            return SUPPORT.compareAndSet(obj, field, expect, update);
+            return unsafe.compareAndSwapLong(obj, offset, expect, update);
         }
 
         public boolean weakCompareAndSet(T obj, long expect, long update) {
             if (!tclass.isInstance(obj))
                 throw new ClassCastException();
-            return SUPPORT.compareAndSet(obj, field, expect, update);
+            return unsafe.compareAndSwapLong(obj, offset, expect, update);
         }
 
         public void set(T obj, long newValue) {
             if (!tclass.isInstance(obj))
                 throw new ClassCastException();
-            
-            SUPPORT.volatileSetLong(obj, field, newValue);
+            unsafe.putLongVolatile(obj, offset, newValue);
         }
 
         public long get(T obj) {
             if (!tclass.isInstance(obj))
                 throw new ClassCastException();
+            return unsafe.getLongVolatile(obj, offset);
+        }
+    }
+
+
+    private static class LockedUpdater<T> extends AtomicLongFieldUpdater<T> {
+        private static final Unsafe unsafe =  Unsafe.getUnsafe();
+        private final long offset;
+        private final Class<T> tclass;
+
+        LockedUpdater(Class<T> tclass, String fieldName) {
+            Field field = null;
+            try {
+                field = tclass.getDeclaredField(fieldName);
+            } catch(Exception ex) {
+                throw new RuntimeException(ex);
+            }
+            
+            Class fieldt = field.getType();
+            if (fieldt != long.class)
+                throw new IllegalArgumentException("Must be long type");
+            
+            if (!Modifier.isVolatile(field.getModifiers()))
+                throw new IllegalArgumentException("Must be volatile type");
             
-            return SUPPORT.volatileGetLong(obj, field);
+            this.tclass = tclass;
+            offset = unsafe.objectFieldOffset(field);
+        }
+
+        public boolean compareAndSet(T obj, long expect, long update) {
+            if (!tclass.isInstance(obj))
+                throw new ClassCastException();
+            synchronized(this) {
+                long v = unsafe.getLong(obj, offset);
+                if (v != expect) 
+                    return false;
+                unsafe.putLong(obj, offset, update);
+                return true;
+            }
+        }
+
+        public boolean weakCompareAndSet(T obj, long expect, long update) {
+            return compareAndSet(obj, expect, update);
+        }
+
+        public void set(T obj, long newValue) {
+            if (!tclass.isInstance(obj))
+                throw new ClassCastException();
+            synchronized(this) {
+                unsafe.putLong(obj, offset, newValue);
+            }
+        }
+
+        public long get(T obj) {
+            if (!tclass.isInstance(obj))
+                throw new ClassCastException();
+            synchronized(this) {
+                return unsafe.getLong(obj, offset);
+            }
         }
     }
 }

Modified: incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicReference.java
URL: http://svn.apache.org/viewvc/incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicReference.java?rev=423372&r1=423371&r2=423372&view=diff
==============================================================================
--- incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicReference.java (original)
+++ incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicReference.java Tue Jul 18 22:18:05 2006
@@ -1,18 +1,3 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed 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.
- */
-
 /*
  * Written by Doug Lea with assistance from members of JCP JSR-166
  * Expert Group and released to the public domain, as explained at
@@ -20,9 +5,7 @@
  */
 
 package java.util.concurrent.atomic;
-import java.lang.reflect.Field;
-
-import org.apache.harmony.concurrent.AtomicSupport;
+import sun.misc.Unsafe;
 
 /**
  * An object reference that may be updated atomically. See the {@link
@@ -34,17 +17,15 @@
  */
 public class AtomicReference<V>  implements java.io.Serializable { 
     private static final long serialVersionUID = -1848883965231344442L;
-    
-    private static final AtomicSupport SUPPORT = AtomicSupport.getInstance();
 
-    private static final Field VALUE_FIELD;
+    private static final Unsafe unsafe =  Unsafe.getUnsafe();
+    private static final long valueOffset;
 
     static {
-        try {
-            VALUE_FIELD = AtomicReference.class.getDeclaredField("value");
-        } catch (Exception ex) {
-            throw new AssertionError(ex);
-        }
+      try {
+        valueOffset = unsafe.objectFieldOffset
+            (AtomicReference.class.getDeclaredField("value"));
+      } catch(Exception ex) { throw new Error(ex); }
     }
 
     private volatile V value;
@@ -91,7 +72,7 @@
      * the actual value was not equal to the expected value.
      */
     public final boolean compareAndSet(V expect, V update) {
-      return SUPPORT.compareAndSet(this, VALUE_FIELD, expect, update);
+      return unsafe.compareAndSwapObject(this, valueOffset, expect, update);
     }
 
     /**
@@ -103,7 +84,7 @@
      * @return true if successful.
      */
     public final boolean weakCompareAndSet(V expect, V update) {
-        return SUPPORT.compareAndSet(this, VALUE_FIELD, expect, update);
+      return unsafe.compareAndSwapObject(this, valueOffset, expect, update);
     }
 
     /**

Modified: incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicReferenceArray.java
URL: http://svn.apache.org/viewvc/incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicReferenceArray.java?rev=423372&r1=423371&r2=423372&view=diff
==============================================================================
--- incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicReferenceArray.java (original)
+++ incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicReferenceArray.java Tue Jul 18 22:18:05 2006
@@ -1,18 +1,3 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed 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.
- */
-
 /*
  * Written by Doug Lea with assistance from members of JCP JSR-166
  * Expert Group and released to the public domain, as explained at
@@ -20,9 +5,8 @@
  */
 
 package java.util.concurrent.atomic;
-import java.util.Arrays;
-
-import org.apache.harmony.concurrent.AtomicSupport;
+import sun.misc.Unsafe;
+import java.util.*;
 
 /**
  * An array of object references in which elements may be updated
@@ -35,21 +19,27 @@
  */
 public class AtomicReferenceArray<E> implements java.io.Serializable { 
     private static final long serialVersionUID = -6209656149925076980L;
-    
-    private static final AtomicSupport SUPPORT = AtomicSupport.getInstance();
 
-    private final E[] array;
+    private static final Unsafe unsafe =  Unsafe.getUnsafe();
+    private static final int base = unsafe.arrayBaseOffset(Object[].class);
+    private static final int scale = unsafe.arrayIndexScale(Object[].class);
+    private final Object[] array;
+
+    private long rawIndex(int i) {
+        if (i < 0 || i >= array.length)
+            throw new IndexOutOfBoundsException("index " + i);
+        return base + i * scale;
+    }
 
     /**
      * Create a new AtomicReferenceArray of given length.
      * @param length the length of the array
      */
     public AtomicReferenceArray(int length) {
-        array = (E[]) new Object[length];
+        array = new Object[length];
         // must perform at least one volatile write to conform to JMM
-        if (length > 0) {
-            SUPPORT.volatileSet(array, 0, null);
-        }
+        if (length > 0) 
+            unsafe.putObjectVolatile(array, rawIndex(0), null);
     }
 
     /**
@@ -63,14 +53,14 @@
         if (array == null) 
             throw new NullPointerException();
         int length = array.length;
-        this.array = (E[]) new Object[length];
+        this.array = new Object[length];
         if (length > 0) {
             int last = length-1;
             for (int i = 0; i < last; ++i)
                 this.array[i] = array[i];
             // Do the last write as volatile
             E e = array[last];
-            SUPPORT.volatileSet(this.array, last, e);
+            unsafe.putObjectVolatile(this.array, rawIndex(last), e);
         }
     }
 
@@ -90,7 +80,7 @@
      * @return the current value
      */
     public final E get(int i) {
-        return (E)SUPPORT.volatileGet(array, i);
+        return (E) unsafe.getObjectVolatile(array, rawIndex(i));
     }
  
     /**
@@ -100,7 +90,7 @@
      * @param newValue the new value
      */
     public final void set(int i, E newValue) {
-        SUPPORT.volatileSet(array, i, newValue);
+        unsafe.putObjectVolatile(array, rawIndex(i), newValue);
     }
   
     /**
@@ -129,7 +119,8 @@
      * the actual value was not equal to the expected value.
      */
     public final boolean compareAndSet(int i, E expect, E update) {
-        return SUPPORT.compareAndSet(array, i, expect, update);
+        return unsafe.compareAndSwapObject(array, rawIndex(i), 
+                                         expect, update);
     }
 
     /**

Modified: incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
URL: http://svn.apache.org/viewvc/incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java?rev=423372&r1=423371&r2=423372&view=diff
==============================================================================
--- incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java (original)
+++ incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java Tue Jul 18 22:18:05 2006
@@ -1,18 +1,3 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed 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.
- */
-
 /*
  * Written by Doug Lea with assistance from members of JCP JSR-166
  * Expert Group and released to the public domain, as explained at
@@ -20,10 +5,8 @@
  */
 
 package java.util.concurrent.atomic;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-
-import org.apache.harmony.concurrent.AtomicSupport;
+import sun.misc.Unsafe;
+import java.lang.reflect.*;
 
 /**
  * A reflection-based utility that enables atomic updates to
@@ -63,8 +46,6 @@
  */
 public abstract class AtomicReferenceFieldUpdater<T, V>  {
 
-    private static final AtomicSupport SUPPORT = AtomicSupport.getInstance();
-    
     /**
      * Creates an updater for objects with the given field.  The Class
      * arguments are needed to check that reflective types and generic
@@ -154,7 +135,8 @@
      * Standard hotspot implementation using intrinsics
      */
     private static class AtomicReferenceFieldUpdaterImpl<T,V> extends AtomicReferenceFieldUpdater<T,V> {
-        private final Field field;
+        private static final Unsafe unsafe =  Unsafe.getUnsafe();
+        private final long offset;
         private final Class<T> tclass;
         private final Class<V> vclass;
 
@@ -176,7 +158,7 @@
 
             this.tclass = tclass;
             this.vclass = vclass;
-            this.field = field;
+            offset = unsafe.objectFieldOffset(field);
         }
         
 
@@ -184,7 +166,7 @@
             if (!tclass.isInstance(obj) ||
                 (update != null && !vclass.isInstance(update)))
                 throw new ClassCastException();
-            return SUPPORT.compareAndSet(obj, field, expect, update);
+            return unsafe.compareAndSwapObject(obj, offset, expect, update);
         }
 
         public boolean weakCompareAndSet(T obj, V expect, V update) {
@@ -192,7 +174,7 @@
             if (!tclass.isInstance(obj) ||
                 (update != null && !vclass.isInstance(update)))
                 throw new ClassCastException();
-            return SUPPORT.compareAndSet(obj, field, expect, update);
+            return unsafe.compareAndSwapObject(obj, offset, expect, update);
         }
 
 
@@ -200,15 +182,13 @@
             if (!tclass.isInstance(obj) ||
                 (newValue != null && !vclass.isInstance(newValue)))
                 throw new ClassCastException();
-            
-            SUPPORT.volatileSetObject(obj, field, newValue);
+            unsafe.putObjectVolatile(obj, offset, newValue);
         }
 
         public V get(T obj) {
             if (!tclass.isInstance(obj))
                 throw new ClassCastException();
-            
-            return (V)SUPPORT.volatileGetObject(obj, field);
+            return (V)unsafe.getObjectVolatile(obj, offset);
         }
     }
 }

Modified: incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/locks/AbstractQueuedSynchronizer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/locks/AbstractQueuedSynchronizer.java?rev=423372&r1=423371&r2=423372&view=diff
==============================================================================
--- incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/locks/AbstractQueuedSynchronizer.java (original)
+++ incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/locks/AbstractQueuedSynchronizer.java Tue Jul 18 22:18:05 2006
@@ -1,18 +1,3 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed 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.
- */
-
 /*
  * Written by Doug Lea with assistance from members of JCP JSR-166
  * Expert Group and released to the public domain, as explained at
@@ -20,12 +5,10 @@
  */
 
 package java.util.concurrent.locks;
-import java.lang.reflect.Field;
 import java.util.*;
 import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
-
-import org.apache.harmony.concurrent.AtomicSupport;
+import sun.misc.Unsafe;
 
 /**
  * Provides a framework for implementing blocking locks and related
@@ -265,8 +248,6 @@
  */
 public abstract class AbstractQueuedSynchronizer implements java.io.Serializable {
     private static final long serialVersionUID = 7373984972572414691L;
-    
-    private static final AtomicSupport SUPPORT = AtomicSupport.getInstance();
 
     /**
      * Creates a new <tt>AbstractQueuedSynchronizer</tt> instance
@@ -522,7 +503,7 @@
      */
     protected final boolean compareAndSetState(int expect, int update) {
         // See below for intrinsics setup to support this
-        return SUPPORT.compareAndSet(this, STATE_FIELD, expect, update);
+        return unsafe.compareAndSwapInt(this, stateOffset, expect, update);
     }
 
     // Queuing utilities
@@ -2002,33 +1983,38 @@
      * are at it, we do the same for other CASable fields (which could
      * otherwise be done with atomic field updaters).
      */
-
-    private static final Field STATE_FIELD;
-    private static final Field HEAD_FIELD;
-    private static final Field TAIL_FIELD;
-    private static final Field WAIT_STATUS_FIELD;
+    private static final Unsafe unsafe =  Unsafe.getUnsafe();
+    private static final long stateOffset;
+    private static final long headOffset;
+    private static final long tailOffset;
+    private static final long waitStatusOffset;
 
     static {
         try {
-            STATE_FIELD = AbstractQueuedSynchronizer.class.getDeclaredField("state");
-            HEAD_FIELD = AbstractQueuedSynchronizer.class.getDeclaredField("head");
-            TAIL_FIELD = AbstractQueuedSynchronizer.class.getDeclaredField("tail");
-            WAIT_STATUS_FIELD = Node.class.getDeclaredField("waitStatus");
-        } catch(Exception ex) { throw new AssertionError(ex); }
+            stateOffset = unsafe.objectFieldOffset
+                (AbstractQueuedSynchronizer.class.getDeclaredField("state"));
+            headOffset = unsafe.objectFieldOffset
+                (AbstractQueuedSynchronizer.class.getDeclaredField("head"));
+            tailOffset = unsafe.objectFieldOffset
+                (AbstractQueuedSynchronizer.class.getDeclaredField("tail"));
+            waitStatusOffset = unsafe.objectFieldOffset
+                (Node.class.getDeclaredField("waitStatus"));
+            
+        } catch(Exception ex) { throw new Error(ex); }
     }
 
     /**
      * CAS head field. Used only by enq
      */
     private final boolean compareAndSetHead(Node update) {
-        return SUPPORT.compareAndSet(this, HEAD_FIELD, null, update);
+        return unsafe.compareAndSwapObject(this, headOffset, null, update);
     }
     
     /**
      * CAS tail field. Used only by enq
      */
     private final boolean compareAndSetTail(Node expect, Node update) {
-        return SUPPORT.compareAndSet(this, TAIL_FIELD, expect, update);
+        return unsafe.compareAndSwapObject(this, tailOffset, expect, update);
     }
 
     /**
@@ -2037,7 +2023,8 @@
     private final static boolean compareAndSetWaitStatus(Node node, 
                                                          int expect, 
                                                          int update) {
-        return SUPPORT.compareAndSet(node, WAIT_STATUS_FIELD, expect, update);
+        return unsafe.compareAndSwapInt(node, waitStatusOffset, 
+                                        expect, update);
     }
 
 }

Modified: incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/locks/LockSupport.java
URL: http://svn.apache.org/viewvc/incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/locks/LockSupport.java?rev=423372&r1=423371&r2=423372&view=diff
==============================================================================
--- incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/locks/LockSupport.java (original)
+++ incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/java/util/concurrent/locks/LockSupport.java Tue Jul 18 22:18:05 2006
@@ -1,18 +1,3 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed 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.
- */
-
 /*
  * Written by Doug Lea with assistance from members of JCP JSR-166
  * Expert Group and released to the public domain, as explained at
@@ -20,8 +5,8 @@
  */
 
 package java.util.concurrent.locks;
-
-import org.apache.harmony.concurrent.LocksSupport;
+import java.util.concurrent.*;
+import sun.misc.Unsafe;
 
 
 /**
@@ -91,7 +76,8 @@
 public class LockSupport {
     private LockSupport() {} // Cannot be instantiated.
 
-    private static final LocksSupport SUPPORT = LocksSupport.getInstance();
+    // Hotspot implementation via intrinsics API
+    private static final Unsafe unsafe =  Unsafe.getUnsafe();
 
     /**
      * Make available the permit for the given thread, if it
@@ -105,7 +91,7 @@
      */
     public static void unpark(Thread thread) {
         if (thread != null)
-            SUPPORT.unpark(thread);
+            unsafe.unpark(thread);
     }
 
     /**
@@ -128,7 +114,7 @@
      * for example, the interrupt status of the thread upon return.
      */
     public static void park() {
-        SUPPORT.parkNanos(0L);
+        unsafe.park(false, 0L);
     }
 
     /**
@@ -156,7 +142,7 @@
      */
     public static void parkNanos(long nanos) {
         if (nanos > 0)
-            SUPPORT.parkNanos(nanos);   
+            unsafe.park(false, nanos);   
     }
 
     /**
@@ -184,7 +170,7 @@
      * wait until
      */
     public static void parkUntil(long deadline) {
-        SUPPORT.parkUntil(deadline);   
+        unsafe.park(true, deadline);   
     }
 
 }

Added: incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/sun/misc/Unsafe.java
URL: http://svn.apache.org/viewvc/incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/sun/misc/Unsafe.java?rev=423372&view=auto
==============================================================================
--- incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/sun/misc/Unsafe.java (added)
+++ incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/sun/misc/Unsafe.java Tue Jul 18 22:18:05 2006
@@ -0,0 +1,274 @@
+package sun.misc;
+
+import java.lang.reflect.Field;
+
+/**
+ * <p>The Unsafe service.</p>
+ *
+ */
+public class Unsafe {
+
+    /**
+     * <p>
+     * Retrieves an instance of this service.
+     * </p>
+     * 
+     * @return An instance of Unsafe.
+     */
+    public static Unsafe getUnsafe() {
+        return null;
+    }
+
+    /**
+     * <p>
+     * Retrieves the offset value of the {@link Field} for use by other methods
+     * in this class.
+     * </p>
+     * 
+     * @param field The {@link Field} to retrieve the offset for.
+     * @return The offset value.
+     */
+    public long objectFieldOffset(Field field) {
+        return 0L;
+    }
+
+    /**
+     * <p>
+     * Compares and swaps the value of an int-typed field on an Object instance.
+     * </p>
+     * 
+     * @param object The instance containing the field.
+     * @param fieldOffset The offset value of the field.
+     * @param expected The expected value of the field.
+     * @param update The new value to write to the field.
+     * @return <code>true</code> if the field was updated, <code>false</code>
+     *         otherwise.
+     */
+    public boolean compareAndSwapInt(Object object, long fieldOffset, int expected, int update) {
+        return false;
+    }
+
+    /**
+     * <p>
+     * Compares and swaps the value of a long-typed field on an Object instance.
+     * </p>
+     * 
+     * @param object The instance containing the field.
+     * @param fieldOffset The offset value of the field.
+     * @param expected The expected value of the field.
+     * @param update The new value to write to the field.
+     * @return <code>true</code> if the field was updated, <code>false</code>
+     *         otherwise.
+     */
+    public boolean compareAndSwapLong(Object object, long fieldOffset, long expected,
+            long update) {
+        return false;
+    }
+
+    /**
+     * <p>
+     * Compares and swaps the value of an Object-typed field on an Object
+     * instance.
+     * </p>
+     * 
+     * @param object The instance containing the field.
+     * @param fieldOffset The offset value of the field.
+     * @param expected The expected value of the field.
+     * @param update The new value to write to the field.
+     * @return <code>true</code> if the field was updated, <code>false</code>
+     *         otherwise.
+     */
+    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 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 = unsafe.arrayBaseOffset(int[].class);
+     * 
+     * int scale = unsafe.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 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>
+     * 
+     * @param object The instance containing the field to write to.
+     * @param fieldOffset The offset of the field to write to.
+     * @param newValue The value to write.
+     */
+    public void putIntVolatile(Object object, long fieldOffset, int newValue) {
+        return;
+    }
+
+    /**
+     * <p>
+     * Reads an int value from an Object's field as though it were declared
+     * <code>volatile</code>.
+     * </p>
+     * 
+     * @param object The instance containing the field to read from.
+     * @param fieldOffset The offset of the field to read from.
+     * @return The value that was read.
+     */
+    public int getIntVolatile(Object object, long fieldOffset) {
+        return 0;
+    }
+
+    /**
+     * <p>
+     * Writes a long value to an Object's field as though it were declared
+     * <code>volatile</code>.
+     * </p>
+     * 
+     * @param object The instance containing the field to write to.
+     * @param fieldOffset The offset of the field to write to.
+     * @param newValue The value to write.
+     */
+    public void putLongVolatile(Object object, long fieldOffset, long newValue) {
+        return;
+    }
+
+    /**
+     * <p>
+     * Reads a long value from an Object's field as though it were declared
+     * <code>volatile</code>.
+     * </p>
+     * 
+     * @param object The instance containing the field to read from.
+     * @param fieldOffset The offset of the field to read from.
+     * @return The value that was read.
+     */
+    public long getLongVolatile(Object object, long fieldOffset) {
+        return 0;
+    }
+
+    /**
+     * <p>
+     * Writes an Object reference value to an Object's field as though it were
+     * declared <code>volatile</code>.
+     * </p>
+     * 
+     * @param object The instance containing the field to write to.
+     * @param fieldOffset The offset of the field to write to.
+     * @param newValue The value to write.
+     */
+    public void putObjectVolatile(Object object, long fieldOffset, Object newValue) {
+        return;
+    }
+
+    /**
+     * <p>
+     * Writes an int value to an Object's field as though it were declared
+     * <code>volatile</code>.
+     * </p>
+     * 
+     * @param object The instance containing the field to write to.
+     * @param fieldOffset The offset of the field to write to.
+     * @param newValue The value to write.
+     */
+    public Object getObjectVolatile(Object object, long fieldOffset) {
+        return null;
+    }
+
+    /**
+     * <p>
+     * Writes a long value to an Object's field.
+     * </p>
+     * 
+     * @param object The instance containing the field to write to.
+     * @param fieldOffset The offset of the field to write to.
+     * @param newValue The value to write.
+     */
+    public void putLong(Object object, long fieldOffset, long newValue) {
+        return;
+    }
+
+    /**
+     * <p>
+     * Reads a long value from an Object's field.
+     * </p>
+     * 
+     * @param object The instance containing the field to read from.
+     * @param fieldOffset The offset of the field to read from.
+     * @return The value that was read.
+     */
+    public long getLong(Object object, long fieldOffset) {
+        return 0L;
+    }
+
+    /**
+     * <p>
+     * Unparks the {@link Thread} that's passed.
+     * </p>
+     * 
+     * @param thread The {@link Thread} to unpark.
+     */
+    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.
+     * </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()}.
+     */
+    public void park(boolean timestamp, long nanosOrTimestamp) {
+
+    }
+}

Propchange: incubator/harmony/standard/sandbox/juc-proposal/concurrent/src/main/java/sun/misc/Unsafe.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message