changeset 6617:2d12e848c02e

Merge
author lana
date Fri, 07 Jun 2013 09:39:46 -0700
parents 0710f082cdc2 3b589265048d
children 504928f651c7
files
diffstat 14 files changed, 836 insertions(+), 223 deletions(-) [+]
line wrap: on
line diff
--- a/make/common/Defs.gmk	Thu Jun 06 19:10:41 2013 -0700
+++ b/make/common/Defs.gmk	Fri Jun 07 09:39:46 2013 -0700
@@ -431,7 +431,12 @@
 # namely jni.h, jvm.h, and jni_utils.h, plus their platform-specific
 # relatives.
 #
-VPATH0.h =   $(PLATFORM_SRC)/javavm/export$(CLASSPATH_SEPARATOR)$(SHARE_SRC)/javavm/export
+ifeq ($(PLATFORM), macosx)
+  VPATH0.h =   $(PLATFORM_SRC_MACOS)/javavm/export$(CLASSPATH_SEPARATOR)$(SHARE_SRC)/javavm/export
+else
+  VPATH0.h =   $(PLATFORM_SRC)/javavm/export$(CLASSPATH_SEPARATOR)$(SHARE_SRC)/javavm/export
+endif
+
 ifdef OPENJDK
   VPATH.h = $(VPATH0.h)
 else
--- a/make/sun/jawt/Makefile	Thu Jun 06 19:10:41 2013 -0700
+++ b/make/sun/jawt/Makefile	Fri Jun 07 09:39:46 2013 -0700
@@ -30,6 +30,9 @@
 
 include $(BUILDDIR)/common/Defs.gmk
 
+# default to PLATFORM_SRC to copy export headers from
+PLATFORM_EXPORT_BASE = $(PLATFORM_SRC)
+
 #
 # Files
 #
@@ -37,6 +40,8 @@
 FILES_cpp = jawt.cpp
 else ifeq ($(PLATFORM), macosx) # PLATFORM
 FILES_objc = jawt.m
+# pick up the correct export headers for Mac OS X
+PLATFORM_EXPORT_BASE = $(PLATFORM_SRC_MACOS)
 else # PLATFORM
 FILES_c = jawt.c
 endif # PLATFORM
@@ -160,7 +165,7 @@
 #
 $(INCLUDEDIR)/%.h: $(SHARE_SRC)/javavm/export/%.h
 	$(install-file)
-$(PLATFORM_INCLUDE)/%.h: $(PLATFORM_SRC)/javavm/export/%.h
+$(PLATFORM_INCLUDE)/%.h: $(PLATFORM_EXPORT_BASE)/javavm/export/%.h
 	$(install-file)
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/macosx/javavm/export/jawt_md.h	Fri Jun 07 09:39:46 2013 -0700
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 1999, 2013 Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef _JAVASOFT_JAWT_MD_H_
+#define _JAVASOFT_JAWT_MD_H_
+
+/*
+ * To use jawt_X11DrawingSurfaceInfo you must define XAWT before including this header
+ * file. You must also have the X11 headers installed on your system.
+ */
+#ifdef XAWT
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Intrinsic.h>
+#endif // XAWT
+
+#include "jawt.h"
+
+#ifdef __OBJC__
+#import <QuartzCore/CALayer.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Mac OS X specific declarations for AWT native interface.
+ * See notes in jawt.h for an example of use.
+ */
+
+/*
+ * When calling JAWT_GetAWT with a JAWT version less than 1.7, you must pass this
+ * flag or you will not be able to get a valid drawing surface and JAWT_GetAWT will
+ * return false. This is to maintain compatibility with applications that used the
+ * interface with Java 6 which had multiple rendering models. This flag is not necessary
+ * when JAWT version 1.7 or greater is used as this is the only supported rendering mode.
+ *
+ * Example:
+ *   JAWT awt;
+ *   awt.version = JAWT_VERSION_1_4 | JAWT_MACOSX_USE_CALAYER;
+ *   jboolean success = JAWT_GetAWT(env, &awt);
+ */
+#define JAWT_MACOSX_USE_CALAYER 0x80000000
+
+/*
+ * When the native Cocoa toolkit is in use, the pointer stored in
+ * JAWT_DrawingSurfaceInfo->platformInfo points to a NSObject that conforms to the
+ * JAWT_SurfaceLayers protocol. Setting the layer property of this object will cause the
+ * specified layer to be overlaid on the Components rectangle. If the window the
+ * Component belongs to has a CALayer attached to it, this layer will be accessible via
+ * the windowLayer property.
+ */
+#ifdef __OBJC__
+@protocol JAWT_SurfaceLayers
+@property (readwrite, retain) CALayer *layer;
+@property (readonly) CALayer *windowLayer;
+@end
+#endif
+
+#ifdef XAWT
+/*
+ * X11-specific declarations for AWT native interface.
+ * See notes in jawt.h for an example of use.
+ *
+ * WARNING: This interface is deprecated and will be removed in a future release.
+ */
+typedef struct jawt_X11DrawingSurfaceInfo {
+    Drawable drawable;
+    Display* display;
+    VisualID visualID;
+    Colormap colormapID;
+    int depth;
+    /*
+     * Since 1.4
+     * Returns a pixel value from a set of RGB values.
+     * This is useful for paletted color (256 color) modes.
+     */
+    int (JNICALL *GetAWTColor)(JAWT_DrawingSurface* ds,
+        int r, int g, int b);
+} JAWT_X11DrawingSurfaceInfo;
+#endif // XAWT
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_JAVASOFT_JAWT_MD_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/macosx/javavm/export/jni_md.h	Fri Jun 07 09:39:46 2013 -0700
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 1996, 2000, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef _JAVASOFT_JNI_MD_H_
+#define _JAVASOFT_JNI_MD_H_
+
+#define JNIEXPORT
+#define JNIIMPORT
+#define JNICALL
+
+typedef int jint;
+#ifdef _LP64 /* 64-bit */
+typedef long jlong;
+#else
+typedef long long jlong;
+#endif
+typedef signed char jbyte;
+
+#endif /* !_JAVASOFT_JNI_MD_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/macosx/javavm/export/jvm_md.h	Fri Jun 07 09:39:46 2013 -0700
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef _JAVASOFT_JVM_MD_H_
+#define _JAVASOFT_JVM_MD_H_
+
+/*
+ * This file is currently collecting Mac OS X specific dregs for the
+ * JNI conversion, which should be sorted out later.
+ */
+
+#include <dirent.h>             /* For DIR */
+#include <sys/param.h>          /* For MAXPATHLEN */
+#include <unistd.h>             /* For F_OK, R_OK, W_OK */
+#include <stddef.h>             /* For ptrdiff_t */
+#include <stdint.h>             /* For uintptr_t */
+
+#define JNI_ONLOAD_SYMBOLS   {"JNI_OnLoad"}
+#define JNI_ONUNLOAD_SYMBOLS {"JNI_OnUnload"}
+
+#define JNI_LIB_PREFIX "lib"
+#define JNI_LIB_SUFFIX ".dylib"
+#define VERSIONED_JNI_LIB_NAME(NAME, VERSION) JNI_LIB_PREFIX NAME "." VERSION JNI_LIB_SUFFIX
+#define JNI_LIB_NAME(NAME) JNI_LIB_PREFIX NAME JNI_LIB_SUFFIX
+
+#define JVM_MAXPATHLEN MAXPATHLEN
+
+#define JVM_R_OK    R_OK
+#define JVM_W_OK    W_OK
+#define JVM_X_OK    X_OK
+#define JVM_F_OK    F_OK
+
+/*
+ * File I/O
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/signal.h>
+
+/* O Flags */
+
+#define JVM_O_RDONLY     O_RDONLY
+#define JVM_O_WRONLY     O_WRONLY
+#define JVM_O_RDWR       O_RDWR
+#define JVM_O_O_APPEND   O_APPEND
+#define JVM_O_EXCL       O_EXCL
+#define JVM_O_CREAT      O_CREAT
+#define JVM_O_DELETE     0x10000
+
+/* Signals */
+
+#define JVM_SIGINT     SIGINT
+#define JVM_SIGTERM    SIGTERM
+
+
+#endif /* !_JAVASOFT_JVM_MD_H_ */
--- a/src/macosx/native/sun/awt/AWTSurfaceLayers.h	Thu Jun 06 19:10:41 2013 -0700
+++ b/src/macosx/native/sun/awt/AWTSurfaceLayers.h	Fri Jun 07 09:39:46 2013 -0700
@@ -23,8 +23,7 @@
  * questions.
  */
 
-// REMIND: import <jawt_md.h>
-#import <JavaVM/jawt_md.h>
+#import <jawt_md.h>
 
 /*
  * The CALayer-based rendering model returns an object conforming
--- a/src/macosx/native/sun/awt/CMenuComponent.h	Thu Jun 06 19:10:41 2013 -0700
+++ b/src/macosx/native/sun/awt/CMenuComponent.h	Fri Jun 07 09:39:46 2013 -0700
@@ -24,7 +24,7 @@
  */
 
 #import <AppKit/AppKit.h>
-#import <JavaVM/jni.h>
+#import <jni.h>
 
 @interface CMenuComponent : NSObject {
 
--- a/src/macosx/native/sun/awt/jawt.m	Thu Jun 06 19:10:41 2013 -0700
+++ b/src/macosx/native/sun/awt/jawt.m	Fri Jun 07 09:39:46 2013 -0700
@@ -24,9 +24,7 @@
  */
 
 #import <jawt.h>
-
-// REMIND: import <jawt_md.h>
-#import <JavaVM/jawt_md.h>
+#import <jawt_md.h>
 
 #import "awt_DrawingSurface.h"
 
--- a/src/macosx/native/sun/font/CoreTextSupport.h	Thu Jun 06 19:10:41 2013 -0700
+++ b/src/macosx/native/sun/font/CoreTextSupport.h	Fri Jun 07 09:39:46 2013 -0700
@@ -24,7 +24,7 @@
  */
 
 #import <Cocoa/Cocoa.h>
-#import <JavaVM/jni.h>
+#import <jni.h>
 #import <JavaRuntimeSupport/JavaRuntimeSupport.h>
 
 #include "AWTFont.h"
--- a/src/share/classes/java/util/concurrent/FutureTask.java	Thu Jun 06 19:10:41 2013 -0700
+++ b/src/share/classes/java/util/concurrent/FutureTask.java	Fri Jun 07 09:39:46 2013 -0700
@@ -34,51 +34,111 @@
  */
 
 package java.util.concurrent;
-import java.util.concurrent.locks.*;
+import java.util.concurrent.locks.LockSupport;
 
 /**
  * A cancellable asynchronous computation.  This class provides a base
  * implementation of {@link Future}, with methods to start and cancel
  * a computation, query to see if the computation is complete, and
  * retrieve the result of the computation.  The result can only be
- * retrieved when the computation has completed; the <tt>get</tt>
- * method will block if the computation has not yet completed.  Once
+ * retrieved when the computation has completed; the {@code get}
+ * methods will block if the computation has not yet completed.  Once
  * the computation has completed, the computation cannot be restarted
- * or cancelled.
+ * or cancelled (unless the computation is invoked using
+ * {@link #runAndReset}).
  *
- * <p>A <tt>FutureTask</tt> can be used to wrap a {@link Callable} or
- * {@link java.lang.Runnable} object.  Because <tt>FutureTask</tt>
- * implements <tt>Runnable</tt>, a <tt>FutureTask</tt> can be
- * submitted to an {@link Executor} for execution.
+ * <p>A {@code FutureTask} can be used to wrap a {@link Callable} or
+ * {@link Runnable} object.  Because {@code FutureTask} implements
+ * {@code Runnable}, a {@code FutureTask} can be submitted to an
+ * {@link Executor} for execution.
  *
  * <p>In addition to serving as a standalone class, this class provides
- * <tt>protected</tt> functionality that may be useful when creating
+ * {@code protected} functionality that may be useful when creating
  * customized task classes.
  *
  * @since 1.5
  * @author Doug Lea
- * @param <V> The result type returned by this FutureTask's <tt>get</tt> method
+ * @param <V> The result type returned by this FutureTask's {@code get} methods
  */
 public class FutureTask<V> implements RunnableFuture<V> {
-    /** Synchronization control for FutureTask */
-    private final Sync sync;
+    /*
+     * Revision notes: This differs from previous versions of this
+     * class that relied on AbstractQueuedSynchronizer, mainly to
+     * avoid surprising users about retaining interrupt status during
+     * cancellation races. Sync control in the current design relies
+     * on a "state" field updated via CAS to track completion, along
+     * with a simple Treiber stack to hold waiting threads.
+     *
+     * Style note: As usual, we bypass overhead of using
+     * AtomicXFieldUpdaters and instead directly use Unsafe intrinsics.
+     */
 
     /**
-     * Creates a <tt>FutureTask</tt> that will, upon running, execute the
-     * given <tt>Callable</tt>.
+     * The run state of this task, initially NEW.  The run state
+     * transitions to a terminal state only in methods set,
+     * setException, and cancel.  During completion, state may take on
+     * transient values of COMPLETING (while outcome is being set) or
+     * INTERRUPTING (only while interrupting the runner to satisfy a
+     * cancel(true)). Transitions from these intermediate to final
+     * states use cheaper ordered/lazy writes because values are unique
+     * and cannot be further modified.
+     *
+     * Possible state transitions:
+     * NEW -> COMPLETING -> NORMAL
+     * NEW -> COMPLETING -> EXCEPTIONAL
+     * NEW -> CANCELLED
+     * NEW -> INTERRUPTING -> INTERRUPTED
+     */
+    private volatile int state;
+    private static final int NEW          = 0;
+    private static final int COMPLETING   = 1;
+    private static final int NORMAL       = 2;
+    private static final int EXCEPTIONAL  = 3;
+    private static final int CANCELLED    = 4;
+    private static final int INTERRUPTING = 5;
+    private static final int INTERRUPTED  = 6;
+
+    /** The underlying callable; nulled out after running */
+    private Callable<V> callable;
+    /** The result to return or exception to throw from get() */
+    private Object outcome; // non-volatile, protected by state reads/writes
+    /** The thread running the callable; CASed during run() */
+    private volatile Thread runner;
+    /** Treiber stack of waiting threads */
+    private volatile WaitNode waiters;
+
+    /**
+     * Returns result or throws exception for completed task.
+     *
+     * @param s completed state value
+     */
+    @SuppressWarnings("unchecked")
+    private V report(int s) throws ExecutionException {
+        Object x = outcome;
+        if (s == NORMAL)
+            return (V)x;
+        if (s >= CANCELLED)
+            throw new CancellationException();
+        throw new ExecutionException((Throwable)x);
+    }
+
+    /**
+     * Creates a {@code FutureTask} that will, upon running, execute the
+     * given {@code Callable}.
      *
      * @param  callable the callable task
-     * @throws NullPointerException if callable is null
+     * @throws NullPointerException if the callable is null
      */
     public FutureTask(Callable<V> callable) {
         if (callable == null)
             throw new NullPointerException();
-        sync = new Sync(callable);
+        this.callable = callable;
+        this.state = NEW;       // ensure visibility of callable
     }
 
     /**
-     * Creates a <tt>FutureTask</tt> that will, upon running, execute the
-     * given <tt>Runnable</tt>, and arrange that <tt>get</tt> will return the
+     * Creates a {@code FutureTask} that will, upon running, execute the
+     * given {@code Runnable}, and arrange that {@code get} will return the
      * given result on successful completion.
      *
      * @param runnable the runnable task
@@ -86,29 +146,46 @@
      * you don't need a particular result, consider using
      * constructions of the form:
      * {@code Future<?> f = new FutureTask<Void>(runnable, null)}
-     * @throws NullPointerException if runnable is null
+     * @throws NullPointerException if the runnable is null
      */
     public FutureTask(Runnable runnable, V result) {
-        sync = new Sync(Executors.callable(runnable, result));
+        this.callable = Executors.callable(runnable, result);
+        this.state = NEW;       // ensure visibility of callable
     }
 
     public boolean isCancelled() {
-        return sync.innerIsCancelled();
+        return state >= CANCELLED;
     }
 
     public boolean isDone() {
-        return sync.innerIsDone();
+        return state != NEW;
     }
 
     public boolean cancel(boolean mayInterruptIfRunning) {
-        return sync.innerCancel(mayInterruptIfRunning);
+        if (state != NEW)
+            return false;
+        if (mayInterruptIfRunning) {
+            if (!UNSAFE.compareAndSwapInt(this, stateOffset, NEW, INTERRUPTING))
+                return false;
+            Thread t = runner;
+            if (t != null)
+                t.interrupt();
+            UNSAFE.putOrderedInt(this, stateOffset, INTERRUPTED); // final state
+        }
+        else if (!UNSAFE.compareAndSwapInt(this, stateOffset, NEW, CANCELLED))
+            return false;
+        finishCompletion();
+        return true;
     }
 
     /**
      * @throws CancellationException {@inheritDoc}
      */
     public V get() throws InterruptedException, ExecutionException {
-        return sync.innerGet();
+        int s = state;
+        if (s <= COMPLETING)
+            s = awaitDone(false, 0L);
+        return report(s);
     }
 
     /**
@@ -116,12 +193,18 @@
      */
     public V get(long timeout, TimeUnit unit)
         throws InterruptedException, ExecutionException, TimeoutException {
-        return sync.innerGet(unit.toNanos(timeout));
+        if (unit == null)
+            throw new NullPointerException();
+        int s = state;
+        if (s <= COMPLETING &&
+            (s = awaitDone(true, unit.toNanos(timeout))) <= COMPLETING)
+            throw new TimeoutException();
+        return report(s);
     }
 
     /**
      * Protected method invoked when this task transitions to state
-     * <tt>isDone</tt> (whether normally or via cancellation). The
+     * {@code isDone} (whether normally or via cancellation). The
      * default implementation does nothing.  Subclasses may override
      * this method to invoke completion callbacks or perform
      * bookkeeping. Note that you can query status inside the
@@ -131,230 +214,269 @@
     protected void done() { }
 
     /**
-     * Sets the result of this Future to the given value unless
+     * Sets the result of this future to the given value unless
      * this future has already been set or has been cancelled.
-     * This method is invoked internally by the <tt>run</tt> method
+     *
+     * <p>This method is invoked internally by the {@link #run} method
      * upon successful completion of the computation.
+     *
      * @param v the value
      */
     protected void set(V v) {
-        sync.innerSet(v);
+        if (UNSAFE.compareAndSwapInt(this, stateOffset, NEW, COMPLETING)) {
+            outcome = v;
+            UNSAFE.putOrderedInt(this, stateOffset, NORMAL); // final state
+            finishCompletion();
+        }
     }
 
     /**
-     * Causes this future to report an <tt>ExecutionException</tt>
-     * with the given throwable as its cause, unless this Future has
+     * Causes this future to report an {@link ExecutionException}
+     * with the given throwable as its cause, unless this future has
      * already been set or has been cancelled.
-     * This method is invoked internally by the <tt>run</tt> method
+     *
+     * <p>This method is invoked internally by the {@link #run} method
      * upon failure of the computation.
+     *
      * @param t the cause of failure
      */
     protected void setException(Throwable t) {
-        sync.innerSetException(t);
+        if (UNSAFE.compareAndSwapInt(this, stateOffset, NEW, COMPLETING)) {
+            outcome = t;
+            UNSAFE.putOrderedInt(this, stateOffset, EXCEPTIONAL); // final state
+            finishCompletion();
+        }
     }
 
-    // The following (duplicated) doc comment can be removed once
-    //
-    // 6270645: Javadoc comments should be inherited from most derived
-    //          superinterface or superclass
-    // is fixed.
-    /**
-     * Sets this Future to the result of its computation
-     * unless it has been cancelled.
-     */
     public void run() {
-        sync.innerRun();
+        if (state != NEW ||
+            !UNSAFE.compareAndSwapObject(this, runnerOffset,
+                                         null, Thread.currentThread()))
+            return;
+        try {
+            Callable<V> c = callable;
+            if (c != null && state == NEW) {
+                V result;
+                boolean ran;
+                try {
+                    result = c.call();
+                    ran = true;
+                } catch (Throwable ex) {
+                    result = null;
+                    ran = false;
+                    setException(ex);
+                }
+                if (ran)
+                    set(result);
+            }
+        } finally {
+            // runner must be non-null until state is settled to
+            // prevent concurrent calls to run()
+            runner = null;
+            // state must be re-read after nulling runner to prevent
+            // leaked interrupts
+            int s = state;
+            if (s >= INTERRUPTING)
+                handlePossibleCancellationInterrupt(s);
+        }
     }
 
     /**
      * Executes the computation without setting its result, and then
-     * resets this Future to initial state, failing to do so if the
+     * resets this future to initial state, failing to do so if the
      * computation encounters an exception or is cancelled.  This is
      * designed for use with tasks that intrinsically execute more
      * than once.
+     *
      * @return true if successfully run and reset
      */
     protected boolean runAndReset() {
-        return sync.innerRunAndReset();
+        if (state != NEW ||
+            !UNSAFE.compareAndSwapObject(this, runnerOffset,
+                                         null, Thread.currentThread()))
+            return false;
+        boolean ran = false;
+        int s = state;
+        try {
+            Callable<V> c = callable;
+            if (c != null && s == NEW) {
+                try {
+                    c.call(); // don't set result
+                    ran = true;
+                } catch (Throwable ex) {
+                    setException(ex);
+                }
+            }
+        } finally {
+            // runner must be non-null until state is settled to
+            // prevent concurrent calls to run()
+            runner = null;
+            // state must be re-read after nulling runner to prevent
+            // leaked interrupts
+            s = state;
+            if (s >= INTERRUPTING)
+                handlePossibleCancellationInterrupt(s);
+        }
+        return ran && s == NEW;
     }
 
     /**
-     * Synchronization control for FutureTask. Note that this must be
-     * a non-static inner class in order to invoke the protected
-     * <tt>done</tt> method. For clarity, all inner class support
-     * methods are same as outer, prefixed with "inner".
-     *
-     * Uses AQS sync state to represent run status
+     * Ensures that any interrupt from a possible cancel(true) is only
+     * delivered to a task while in run or runAndReset.
      */
-    private final class Sync extends AbstractQueuedSynchronizer {
-        private static final long serialVersionUID = -7828117401763700385L;
+    private void handlePossibleCancellationInterrupt(int s) {
+        // It is possible for our interrupter to stall before getting a
+        // chance to interrupt us.  Let's spin-wait patiently.
+        if (s == INTERRUPTING)
+            while (state == INTERRUPTING)
+                Thread.yield(); // wait out pending interrupt
 
-        /** State value representing that task is ready to run */
-        private static final int READY     = 0;
-        /** State value representing that task is running */
-        private static final int RUNNING   = 1;
-        /** State value representing that task ran */
-        private static final int RAN       = 2;
-        /** State value representing that task was cancelled */
-        private static final int CANCELLED = 4;
+        // assert state == INTERRUPTED;
 
-        /** The underlying callable */
-        private final Callable<V> callable;
-        /** The result to return from get() */
-        private V result;
-        /** The exception to throw from get() */
-        private Throwable exception;
+        // We want to clear any interrupt we may have received from
+        // cancel(true).  However, it is permissible to use interrupts
+        // as an independent mechanism for a task to communicate with
+        // its caller, and there is no way to clear only the
+        // cancellation interrupt.
+        //
+        // Thread.interrupted();
+    }
 
-        /**
-         * The thread running task. When nulled after set/cancel, this
-         * indicates that the results are accessible.  Must be
-         * volatile, to ensure visibility upon completion.
-         */
-        private volatile Thread runner;
+    /**
+     * Simple linked list nodes to record waiting threads in a Treiber
+     * stack.  See other classes such as Phaser and SynchronousQueue
+     * for more detailed explanation.
+     */
+    static final class WaitNode {
+        volatile Thread thread;
+        volatile WaitNode next;
+        WaitNode() { thread = Thread.currentThread(); }
+    }
 
-        Sync(Callable<V> callable) {
-            this.callable = callable;
-        }
-
-        private boolean ranOrCancelled(int state) {
-            return (state & (RAN | CANCELLED)) != 0;
-        }
-
-        /**
-         * Implements AQS base acquire to succeed if ran or cancelled
-         */
-        protected int tryAcquireShared(int ignore) {
-            return innerIsDone() ? 1 : -1;
-        }
-
-        /**
-         * Implements AQS base release to always signal after setting
-         * final done status by nulling runner thread.
-         */
-        protected boolean tryReleaseShared(int ignore) {
-            runner = null;
-            return true;
-        }
-
-        boolean innerIsCancelled() {
-            return getState() == CANCELLED;
-        }
-
-        boolean innerIsDone() {
-            return ranOrCancelled(getState()) && runner == null;
-        }
-
-        V innerGet() throws InterruptedException, ExecutionException {
-            acquireSharedInterruptibly(0);
-            if (getState() == CANCELLED)
-                throw new CancellationException();
-            if (exception != null)
-                throw new ExecutionException(exception);
-            return result;
-        }
-
-        V innerGet(long nanosTimeout) throws InterruptedException, ExecutionException, TimeoutException {
-            if (!tryAcquireSharedNanos(0, nanosTimeout))
-                throw new TimeoutException();
-            if (getState() == CANCELLED)
-                throw new CancellationException();
-            if (exception != null)
-                throw new ExecutionException(exception);
-            return result;
-        }
-
-        void innerSet(V v) {
-            for (;;) {
-                int s = getState();
-                if (s == RAN)
-                    return;
-                if (s == CANCELLED) {
-                    // aggressively release to set runner to null,
-                    // in case we are racing with a cancel request
-                    // that will try to interrupt runner
-                    releaseShared(0);
-                    return;
+    /**
+     * Removes and signals all waiting threads, invokes done(), and
+     * nulls out callable.
+     */
+    private void finishCompletion() {
+        // assert state > COMPLETING;
+        for (WaitNode q; (q = waiters) != null;) {
+            if (UNSAFE.compareAndSwapObject(this, waitersOffset, q, null)) {
+                for (;;) {
+                    Thread t = q.thread;
+                    if (t != null) {
+                        q.thread = null;
+                        LockSupport.unpark(t);
+                    }
+                    WaitNode next = q.next;
+                    if (next == null)
+                        break;
+                    q.next = null; // unlink to help gc
+                    q = next;
                 }
-                if (compareAndSetState(s, RAN)) {
-                    result = v;
-                    releaseShared(0);
-                    done();
-                    return;
-                }
+                break;
             }
         }
 
-        void innerSetException(Throwable t) {
-            for (;;) {
-                int s = getState();
-                if (s == RAN)
-                    return;
-                if (s == CANCELLED) {
-                    // aggressively release to set runner to null,
-                    // in case we are racing with a cancel request
-                    // that will try to interrupt runner
-                    releaseShared(0);
-                    return;
+        done();
+
+        callable = null;        // to reduce footprint
+    }
+
+    /**
+     * Awaits completion or aborts on interrupt or timeout.
+     *
+     * @param timed true if use timed waits
+     * @param nanos time to wait, if timed
+     * @return state upon completion
+     */
+    private int awaitDone(boolean timed, long nanos)
+        throws InterruptedException {
+        final long deadline = timed ? System.nanoTime() + nanos : 0L;
+        WaitNode q = null;
+        boolean queued = false;
+        for (;;) {
+            if (Thread.interrupted()) {
+                removeWaiter(q);
+                throw new InterruptedException();
+            }
+
+            int s = state;
+            if (s > COMPLETING) {
+                if (q != null)
+                    q.thread = null;
+                return s;
+            }
+            else if (s == COMPLETING) // cannot time out yet
+                Thread.yield();
+            else if (q == null)
+                q = new WaitNode();
+            else if (!queued)
+                queued = UNSAFE.compareAndSwapObject(this, waitersOffset,
+                                                     q.next = waiters, q);
+            else if (timed) {
+                nanos = deadline - System.nanoTime();
+                if (nanos <= 0L) {
+                    removeWaiter(q);
+                    return state;
                 }
-                if (compareAndSetState(s, RAN)) {
-                    exception = t;
-                    releaseShared(0);
-                    done();
-                    return;
+                LockSupport.parkNanos(this, nanos);
+            }
+            else
+                LockSupport.park(this);
+        }
+    }
+
+    /**
+     * Tries to unlink a timed-out or interrupted wait node to avoid
+     * accumulating garbage.  Internal nodes are simply unspliced
+     * without CAS since it is harmless if they are traversed anyway
+     * by releasers.  To avoid effects of unsplicing from already
+     * removed nodes, the list is retraversed in case of an apparent
+     * race.  This is slow when there are a lot of nodes, but we don't
+     * expect lists to be long enough to outweigh higher-overhead
+     * schemes.
+     */
+    private void removeWaiter(WaitNode node) {
+        if (node != null) {
+            node.thread = null;
+            retry:
+            for (;;) {          // restart on removeWaiter race
+                for (WaitNode pred = null, q = waiters, s; q != null; q = s) {
+                    s = q.next;
+                    if (q.thread != null)
+                        pred = q;
+                    else if (pred != null) {
+                        pred.next = s;
+                        if (pred.thread == null) // check for race
+                            continue retry;
+                    }
+                    else if (!UNSAFE.compareAndSwapObject(this, waitersOffset,
+                                                          q, s))
+                        continue retry;
                 }
-            }
-        }
-
-        boolean innerCancel(boolean mayInterruptIfRunning) {
-            for (;;) {
-                int s = getState();
-                if (ranOrCancelled(s))
-                    return false;
-                if (compareAndSetState(s, CANCELLED))
-                    break;
-            }
-            if (mayInterruptIfRunning) {
-                Thread r = runner;
-                if (r != null)
-                    r.interrupt();
-            }
-            releaseShared(0);
-            done();
-            return true;
-        }
-
-        void innerRun() {
-            if (!compareAndSetState(READY, RUNNING))
-                return;
-
-            runner = Thread.currentThread();
-            if (getState() == RUNNING) { // recheck after setting thread
-                V result;
-                try {
-                    result = callable.call();
-                } catch (Throwable ex) {
-                    setException(ex);
-                    return;
-                }
-                set(result);
-            } else {
-                releaseShared(0); // cancel
-            }
-        }
-
-        boolean innerRunAndReset() {
-            if (!compareAndSetState(READY, RUNNING))
-                return false;
-            try {
-                runner = Thread.currentThread();
-                if (getState() == RUNNING)
-                    callable.call(); // don't set result
-                runner = null;
-                return compareAndSetState(RUNNING, READY);
-            } catch (Throwable ex) {
-                setException(ex);
-                return false;
+                break;
             }
         }
     }
+
+    // Unsafe mechanics
+    private static final sun.misc.Unsafe UNSAFE;
+    private static final long stateOffset;
+    private static final long runnerOffset;
+    private static final long waitersOffset;
+    static {
+        try {
+            UNSAFE = sun.misc.Unsafe.getUnsafe();
+            Class<?> k = FutureTask.class;
+            stateOffset = UNSAFE.objectFieldOffset
+                (k.getDeclaredField("state"));
+            runnerOffset = UNSAFE.objectFieldOffset
+                (k.getDeclaredField("runner"));
+            waitersOffset = UNSAFE.objectFieldOffset
+                (k.getDeclaredField("waiters"));
+        } catch (Exception e) {
+            throw new Error(e);
+        }
+    }
+
 }
--- a/src/share/javavm/export/jawt.h	Thu Jun 06 19:10:41 2013 -0700
+++ b/src/share/javavm/export/jawt.h	Fri Jun 07 09:39:46 2013 -0700
@@ -154,7 +154,9 @@
     /*
      * Pointer to the platform-specific information.  This can be safely
      * cast to a JAWT_Win32DrawingSurfaceInfo on Windows or a
-     * JAWT_X11DrawingSurfaceInfo on Solaris.  See jawt_md.h for details.
+     * JAWT_X11DrawingSurfaceInfo on Solaris. On Mac OS X, when using the
+     * native Cocoa toolkit this is a pointer to a NSObject that conforms
+     * to the JAWT_SurfaceLayers protocol. See jawt_md.h for details.
      */
     void* platformInfo;
     /* Cached pointer to the underlying drawing surface */
--- a/test/java/awt/Mixing/MixingInHwPanel.java	Thu Jun 06 19:10:41 2013 -0700
+++ b/test/java/awt/Mixing/MixingInHwPanel.java	Fri Jun 07 09:39:46 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,8 +22,8 @@
  */
 
 /*
-  @test %W% %E%
-  @bug 6829858
+  @test
+  @bug 6829858 7109977
   @summary Mixing should work inside heavyweight containers
   @author anthony.petrov@sun.com: area=awt.mixing
   @library ../regtesthelpers
@@ -104,7 +104,7 @@
 
         // And click the part of the button that has been previously hidden
         Point bLoc = button.getLocationOnScreen();
-        robot.mouseMove(bLoc.x + button.getWidth() - 6, bLoc.y + button.getHeight() / 2);
+        robot.mouseMove(bLoc.x + button.getWidth() - 15, bLoc.y + button.getHeight() / 2);
 
         Util.waitForIdle(robot);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/util/concurrent/FutureTask/DoneTimedGetLoops.java	Fri Jun 07 09:39:46 2013 -0700
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * Written by Martin Buchholz with assistance from members of JCP JSR-166
+ * Expert Group and released to the public domain, as explained at
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/*
+ * @test
+ * @run main DoneTimedGetLoops 300
+ * @summary isDone returning true guarantees that subsequent timed get
+ * will never throw TimeoutException.
+ */
+
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+
+@SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
+public class DoneTimedGetLoops {
+    final long testDurationMillisDefault = 10L * 1000L;
+    final long testDurationMillis;
+
+    static class PublicFutureTask extends FutureTask<Boolean> {
+        final static Runnable noop = new Runnable() { public void run() {} };
+        PublicFutureTask() { super(noop, null); }
+        public void set(Boolean v) { super.set(v); }
+        public void setException(Throwable t) { super.setException(t); }
+    }
+
+    DoneTimedGetLoops(String[] args) {
+        testDurationMillis = (args.length > 0) ?
+            Long.valueOf(args[0]) : testDurationMillisDefault;
+    }
+
+    void test(String[] args) throws Throwable {
+        final long testDurationNanos = testDurationMillis * 1000L * 1000L;
+        final long quittingTimeNanos = System.nanoTime() + testDurationNanos;
+        final long timeoutMillis = 10L * 1000L;
+
+        final AtomicReference<PublicFutureTask> normalRef
+            = new AtomicReference<PublicFutureTask>();
+        final AtomicReference<PublicFutureTask> abnormalRef
+            = new AtomicReference<PublicFutureTask>();
+
+        final Throwable throwable = new Throwable();
+
+        abstract class CheckedThread extends Thread {
+            CheckedThread(String name) {
+                super(name);
+                setDaemon(true);
+                start();
+            }
+            /** Polls for quitting time. */
+            protected boolean quittingTime() {
+                return System.nanoTime() - quittingTimeNanos > 0;
+            }
+            /** Polls occasionally for quitting time. */
+            protected boolean quittingTime(long i) {
+                return (i % 1024) == 0 && quittingTime();
+            }
+            abstract protected void realRun() throws Exception;
+            public void run() {
+                try { realRun(); } catch (Throwable t) { unexpected(t); }
+            }
+        }
+
+        Thread setter = new CheckedThread("setter") {
+            protected void realRun() {
+                while (! quittingTime()) {
+                    PublicFutureTask future = new PublicFutureTask();
+                    normalRef.set(future);
+                    future.set(Boolean.TRUE);
+                }}};
+
+        Thread setterException = new CheckedThread("setterException") {
+            protected void realRun() {
+                while (! quittingTime()) {
+                    PublicFutureTask future = new PublicFutureTask();
+                    abnormalRef.set(future);
+                    future.setException(throwable);
+                }}};
+
+        Thread doneTimedGetNormal = new CheckedThread("doneTimedGetNormal") {
+            protected void realRun() throws Exception {
+                while (! quittingTime()) {
+                    PublicFutureTask future = normalRef.get();
+                    if (future != null) {
+                        while (!future.isDone())
+                            ;
+                        check(future.get(0L, TimeUnit.HOURS) == Boolean.TRUE);
+                    }}}};
+
+        Thread doneTimedGetAbnormal = new CheckedThread("doneTimedGetAbnormal") {
+            protected void realRun() throws Exception {
+                while (! quittingTime()) {
+                    PublicFutureTask future = abnormalRef.get();
+                    if (future != null) {
+                        while (!future.isDone())
+                            ;
+                        try { future.get(0L, TimeUnit.HOURS); fail(); }
+                        catch (ExecutionException t) {
+                            check(t.getCause() == throwable);
+                        }
+                    }}}};
+
+        for (Thread thread : new Thread[] {
+                 setter,
+                 setterException,
+                 doneTimedGetNormal,
+                 doneTimedGetAbnormal }) {
+            thread.join(timeoutMillis + testDurationMillis);
+            if (thread.isAlive()) {
+                System.err.printf("Hung thread: %s%n", thread.getName());
+                failed++;
+                for (StackTraceElement e : thread.getStackTrace())
+                    System.err.println(e);
+                // Kludge alert
+                thread.stop();
+                thread.join(timeoutMillis);
+            }
+        }
+    }
+
+    //--------------------- Infrastructure ---------------------------
+    volatile int passed = 0, failed = 0;
+    void pass() {passed++;}
+    void fail() {failed++; Thread.dumpStack();}
+    void fail(String msg) {System.err.println(msg); fail();}
+    void unexpected(Throwable t) {failed++; t.printStackTrace();}
+    void check(boolean cond) {if (cond) pass(); else fail();}
+    void equal(Object x, Object y) {
+        if (x == null ? y == null : x.equals(y)) pass();
+        else fail(x + " not equal to " + y);}
+    public static void main(String[] args) throws Throwable {
+        new DoneTimedGetLoops(args).instanceMain(args);}
+    public void instanceMain(String[] args) throws Throwable {
+        try {test(args);} catch (Throwable t) {unexpected(t);}
+        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
+        if (failed > 0) throw new AssertionError("Some tests failed");}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/util/concurrent/FutureTask/ExplicitSet.java	Fri Jun 07 09:39:46 2013 -0700
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7132378
+ * @summary Race in FutureTask if used with explicit set ( not Runnable )
+ * @author Chris Hegarty
+ */
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.FutureTask;
+
+public class ExplicitSet {
+
+    static void realMain(String[] args) throws Throwable {
+        for (int i = 1; i <= 10000; i++) {
+            //System.out.print(".");
+            test();
+        }
+    }
+
+    static void test() throws Throwable {
+        final SettableTask task = new SettableTask();
+
+        Thread thread = new Thread() { public void run() {
+            try {
+                check(task.get() != null);
+            } catch (Exception e) { unexpected(e); }
+        }};
+        thread.start();
+
+        task.set(Boolean.TRUE);
+        thread.join(5000);
+    }
+
+    static class SettableTask extends FutureTask<Boolean> {
+        SettableTask() {
+            super(new Callable<Boolean>() {
+                    public Boolean call() {
+                        fail ("The task should never be run!");
+                        return null;
+                    };
+                });
+        }
+
+        @Override
+        public void set(Boolean b) {
+            super.set(b);
+        }
+    }
+
+    //--------------------- Infrastructure ---------------------------
+    static volatile int passed = 0, failed = 0;
+    static void pass() {passed++;}
+    static void fail() {failed++; Thread.dumpStack();}
+    static void fail(String msg) {System.out.println(msg); fail();}
+    static void unexpected(Throwable t) {failed++; t.printStackTrace();}
+    static void check(boolean cond) {if (cond) pass(); else fail();}
+    static void equal(Object x, Object y) {
+        if (x == null ? y == null : x.equals(y)) pass();
+        else fail(x + " not equal to " + y);}
+    public static void main(String[] args) throws Throwable {
+        try {realMain(args);} catch (Throwable t) {unexpected(t);}
+        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
+        if (failed > 0) throw new AssertionError("Some tests failed");}
+}