changeset 9728:6cdc679e3412

Merge
author lana
date Mon, 26 Aug 2013 22:18:48 -0700
parents c58e39bb5d62 9586ca82bd8b
children ca53110f1c74
files
diffstat 10 files changed, 151 insertions(+), 142 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/attach/VirtualMachine.java	Mon Aug 26 14:53:15 2013 -0700
+++ b/src/share/classes/com/sun/tools/attach/VirtualMachine.java	Mon Aug 26 22:18:48 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -59,7 +59,7 @@
  * {@link java.lang.instrument} for a detailed description on how these agents
  * are loaded and started). The {@link #loadAgentLibrary loadAgentLibrary} and
  * {@link #loadAgentPath loadAgentPath} methods are used to load agents that
- * are deployed in a dynamic library and make use of the <a
+ * are deployed either in a dynamic library or statically linked into the VM and make use of the <a
  * href="../../../../../../../../technotes/guides/jvmti/index.html">JVM Tools
  * Interface</a>. </p>
  *
@@ -298,25 +298,29 @@
      * <p> A <a href="../../../../../../../../technotes/guides/jvmti/index.html">JVM
      * TI</a> client is called an <i>agent</i>. It is developed in a native language.
      * A JVM TI agent is deployed in a platform specific manner but it is typically the
-     * platform equivalent of a dynamic library. This method causes the given agent
-     * library to be loaded into the target VM (if not already loaded).
+     * platform equivalent of a dynamic library. Alternatively, it may be statically linked into the VM.
+     * This method causes the given agent library to be loaded into the target
+     * VM (if not already loaded or if not statically linked into the VM).
      * It then causes the target VM to invoke the <code>Agent_OnAttach</code> function
+     * or, for a statically linked agent named 'L', the <code>Agent_OnAttach_L</code> function
      * as specified in the
      * <a href="../../../../../../../../technotes/guides/jvmti/index.html"> JVM Tools
-     * Interface</a> specification. Note that the <code>Agent_OnAttach</code>
+     * Interface</a> specification. Note that the <code>Agent_OnAttach[_L]</code>
      * function is invoked even if the agent library was loaded prior to invoking
      * this method.
      *
      * <p> The agent library provided is the name of the agent library. It is interpreted
      * in the target virtual machine in an implementation-dependent manner. Typically an
      * implementation will expand the library name into an operating system specific file
-     * name. For example, on UNIX systems, the name <tt>foo</tt> might be expanded to
-     * <tt>libfoo.so</tt>, and located using the search path specified by the
-     * <tt>LD_LIBRARY_PATH</tt> environment variable.</p>
+     * name. For example, on UNIX systems, the name <tt>L</tt> might be expanded to
+     * <tt>libL.so</tt>, and located using the search path specified by the
+     * <tt>LD_LIBRARY_PATH</tt> environment variable. If the agent named 'L' is
+     * statically linked into the VM then the VM must export a function named
+     * <code>Agent_OnAttach_L</code>.</p>
      *
-     * <p> If the <code>Agent_OnAttach</code> function in the agent library returns
+     * <p> If the <code>Agent_OnAttach[_L]</code> function in the agent library returns
      * an error then an {@link com.sun.tools.attach.AgentInitializationException} is
-     * thrown. The return value from the <code>Agent_OnAttach</code> can then be
+     * thrown. The return value from the <code>Agent_OnAttach[_L]</code> can then be
      * obtained by invoking the {@link
      * com.sun.tools.attach.AgentInitializationException#returnValue() returnValue}
      * method on the exception. </p>
@@ -325,15 +329,16 @@
      *          The name of the agent library.
      *
      * @param   options
-     *          The options to provide to the <code>Agent_OnAttach</code>
+     *          The options to provide to the <code>Agent_OnAttach[_L]</code>
      *          function (can be <code>null</code>).
      *
      * @throws  AgentLoadException
-     *          If the agent library does not exist, or cannot be loaded for
-     *          another reason.
+     *          If the agent library does not exist, the agent library is not
+     *          statically linked with the VM, or the agent library cannot be
+     *          loaded for another reason.
      *
      * @throws  AgentInitializationException
-     *          If the <code>Agent_OnAttach</code> function returns an error
+     *          If the <code>Agent_OnAttach[_L]</code> function returns an error.
      *
      * @throws  IOException
      *          If an I/O error occurs
@@ -359,11 +364,12 @@
      *          The name of the agent library.
      *
      * @throws  AgentLoadException
-     *          If the agent library does not exist, or cannot be loaded for
-     *          another reason.
+     *          If the agent library does not exist, the agent library is not
+     *          statically linked with the VM, or the agent library cannot be
+     *          loaded for another reason.
      *
      * @throws  AgentInitializationException
-     *          If the <code>Agent_OnAttach</code> function returns an error
+     *          If the <code>Agent_OnAttach[_L]</code> function returns an error.
      *
      * @throws  IOException
      *          If an I/O error occurs
@@ -383,12 +389,23 @@
      * <p> A <a href="../../../../../../../../technotes/guides/jvmti/index.html">JVM
      * TI</a> client is called an <i>agent</i>. It is developed in a native language.
      * A JVM TI agent is deployed in a platform specific manner but it is typically the
-     * platform equivalent of a dynamic library. This method causes the given agent
-     * library to be loaded into the target VM (if not already loaded).
-     * It then causes the target VM to invoke the <code>Agent_OnAttach</code> function
-     * as specified in the
+     * platform equivalent of a dynamic library. Alternatively, the native
+     * library specified by the agentPath parameter may be statically
+     * linked with the VM. The parsing of the agentPath parameter into
+     * a statically linked library name is done in a platform
+     * specific manner in the VM. For example, in UNIX, an agentPath parameter
+     * of <code>/a/b/libL.so</code> would name a library 'L'.
+     *
+     * See the JVM TI Specification for more details.
+     *
+     * This method causes the given agent library to be loaded into the target
+     * VM (if not already loaded or if not statically linked into the VM).
+     * It then causes the target VM to invoke the <code>Agent_OnAttach</code>
+     * function or, for a statically linked agent named 'L', the
+     * <code>Agent_OnAttach_L</code> function as specified in the
      * <a href="../../../../../../../../technotes/guides/jvmti/index.html"> JVM Tools
-     * Interface</a> specification. Note that the <code>Agent_OnAttach</code>
+     * Interface</a> specification.
+     * Note that the <code>Agent_OnAttach[_L]</code>
      * function is invoked even if the agent library was loaded prior to invoking
      * this method.
      *
@@ -396,9 +413,9 @@
      * agent library. Unlike {@link #loadAgentLibrary loadAgentLibrary}, the library name
      * is not expanded in the target virtual machine. </p>
      *
-     * <p> If the <code>Agent_OnAttach</code> function in the agent library returns
+     * <p> If the <code>Agent_OnAttach[_L]</code> function in the agent library returns
      * an error then an {@link com.sun.tools.attach.AgentInitializationException} is
-     * thrown. The return value from the <code>Agent_OnAttach</code> can then be
+     * thrown. The return value from the <code>Agent_OnAttach[_L]</code> can then be
      * obtained by invoking the {@link
      * com.sun.tools.attach.AgentInitializationException#returnValue() returnValue}
      * method on the exception. </p>
@@ -407,15 +424,16 @@
      *          The full path of the agent library.
      *
      * @param   options
-     *          The options to provide to the <code>Agent_OnAttach</code>
+     *          The options to provide to the <code>Agent_OnAttach[_L]</code>
      *          function (can be <code>null</code>).
      *
      * @throws  AgentLoadException
-     *          If the agent library does not exist, or cannot be loaded for
-     *          another reason.
+     *          If the agent library does not exist, the agent library is not
+     *          statically linked with the VM, or the agent library cannot be
+     *          loaded for another reason.
      *
      * @throws  AgentInitializationException
-     *          If the <code>Agent_OnAttach</code> function returns an error
+     *          If the <code>Agent_OnAttach[_L]</code> function returns an error.
      *
      * @throws  IOException
      *          If an I/O error occurs
@@ -441,11 +459,12 @@
      *          The full path to the agent library.
      *
      * @throws  AgentLoadException
-     *          If the agent library does not exist, or cannot be loaded for
-     *          another reason.
+     *          If the agent library does not exist, the agent library is not
+     *          statically linked with the VM, or the agent library cannot be
+     *          loaded for another reason.
      *
      * @throws  AgentInitializationException
-     *          If the <code>Agent_OnAttach</code> function returns an error
+     *          If the <code>Agent_OnAttach[_L]</code> function returns an error.
      *
      * @throws  IOException
      *          If an I/O error occurs
--- a/src/share/classes/java/util/stream/Collectors.java	Mon Aug 26 14:53:15 2013 -0700
+++ b/src/share/classes/java/util/stream/Collectors.java	Mon Aug 26 22:18:48 2013 -0700
@@ -137,6 +137,11 @@
         return (u,v) -> { throw new IllegalStateException(String.format("Duplicate key %s", u)); };
     }
 
+    @SuppressWarnings("unchecked")
+    private static <I, R> Function<I, R> castingIdentity() {
+        return i -> (R) i;
+    }
+
     /**
      * Simple implementation class for {@code Collector}.
      *
@@ -166,7 +171,7 @@
                       BiConsumer<A, T> accumulator,
                       BinaryOperator<A> combiner,
                       Set<Characteristics> characteristics) {
-            this(supplier, accumulator, combiner, i -> (R) i, characteristics);
+            this(supplier, accumulator, combiner, castingIdentity(), characteristics);
         }
 
         @Override
@@ -209,7 +214,7 @@
      */
     public static <T, C extends Collection<T>>
     Collector<T, ?, C> toCollection(Supplier<C> collectionFactory) {
-        return new CollectorImpl<>(collectionFactory, Collection::add,
+        return new CollectorImpl<>(collectionFactory, Collection<T>::add,
                                    (r1, r2) -> { r1.addAll(r2); return r1; },
                                    CH_ID);
     }
@@ -1046,30 +1051,23 @@
     public static <T, D, A>
     Collector<T, ?, Map<Boolean, D>> partitioningBy(Predicate<? super T> predicate,
                                                     Collector<? super T, A, D> downstream) {
-        @SuppressWarnings("unchecked")
-        BiConsumer<D, ? super T> downstreamAccumulator = (BiConsumer<D, ? super T>) downstream.accumulator();
-        BiConsumer<Map<Boolean, A>, T> accumulator = (result, t) -> {
-            Partition<D> asPartition = ((Partition<D>) result);
-            downstreamAccumulator.accept(predicate.test(t) ? asPartition.forTrue : asPartition.forFalse, t);
-        };
+        BiConsumer<A, ? super T> downstreamAccumulator = downstream.accumulator();
+        BiConsumer<Partition<A>, T> accumulator = (result, t) ->
+                downstreamAccumulator.accept(predicate.test(t) ? result.forTrue : result.forFalse, t);
         BinaryOperator<A> op = downstream.combiner();
-        BinaryOperator<Map<Boolean, A>> merger = (m1, m2) -> {
-            Partition<A> left = (Partition<A>) m1;
-            Partition<A> right = (Partition<A>) m2;
-            return new Partition<>(op.apply(left.forTrue, right.forTrue),
-                                   op.apply(left.forFalse, right.forFalse));
-        };
-        Supplier<Map<Boolean, A>> supplier = () -> new Partition<>(downstream.supplier().get(),
-                                                                   downstream.supplier().get());
+        BinaryOperator<Partition<A>> merger = (left, right) ->
+                new Partition<>(op.apply(left.forTrue, right.forTrue),
+                                op.apply(left.forFalse, right.forFalse));
+        Supplier<Partition<A>> supplier = () ->
+                new Partition<>(downstream.supplier().get(),
+                                downstream.supplier().get());
         if (downstream.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) {
             return new CollectorImpl<>(supplier, accumulator, merger, CH_ID);
         }
         else {
-            Function<Map<Boolean, A>, Map<Boolean, D>> finisher = (Map<Boolean, A> par) -> {
-                Partition<A> asAPartition = (Partition<A>) par;
-                return new Partition<>(downstream.finisher().apply(asAPartition.forTrue),
-                                       downstream.finisher().apply(asAPartition.forFalse));
-            };
+            Function<Partition<A>, Map<Boolean, D>> finisher = par ->
+                    new Partition<>(downstream.finisher().apply(par.forTrue),
+                                    downstream.finisher().apply(par.forFalse));
             return new CollectorImpl<>(supplier, accumulator, merger, finisher, CH_NOID);
         }
     }
--- a/src/share/classes/java/util/stream/DistinctOps.java	Mon Aug 26 14:53:15 2013 -0700
+++ b/src/share/classes/java/util/stream/DistinctOps.java	Mon Aug 26 22:18:48 2013 -0700
@@ -101,7 +101,7 @@
                 if (StreamOpFlag.DISTINCT.isKnown(flags)) {
                     return sink;
                 } else if (StreamOpFlag.SORTED.isKnown(flags)) {
-                    return new Sink.ChainedReference<T>(sink) {
+                    return new Sink.ChainedReference<T, T>(sink) {
                         boolean seenNull;
                         T lastSeen;
 
@@ -132,7 +132,7 @@
                         }
                     };
                 } else {
-                    return new Sink.ChainedReference<T>(sink) {
+                    return new Sink.ChainedReference<T, T>(sink) {
                         Set<T> seen;
 
                         @Override
--- a/src/share/classes/java/util/stream/DoublePipeline.java	Mon Aug 26 14:53:15 2013 -0700
+++ b/src/share/classes/java/util/stream/DoublePipeline.java	Mon Aug 26 22:18:48 2013 -0700
@@ -191,7 +191,7 @@
                                        StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
-                return new Sink.ChainedDouble(sink) {
+                return new Sink.ChainedDouble<Double>(sink) {
                     @Override
                     public void accept(double t) {
                         downstream.accept(mapper.applyAsDouble(t));
@@ -208,9 +208,8 @@
                                                             StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<Double> opWrapSink(int flags, Sink<U> sink) {
-                return new Sink.ChainedDouble(sink) {
+                return new Sink.ChainedDouble<U>(sink) {
                     @Override
-                    @SuppressWarnings("unchecked")
                     public void accept(double t) {
                         downstream.accept(mapper.apply(t));
                     }
@@ -226,7 +225,7 @@
                                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<Double> opWrapSink(int flags, Sink<Integer> sink) {
-                return new Sink.ChainedDouble(sink) {
+                return new Sink.ChainedDouble<Integer>(sink) {
                     @Override
                     public void accept(double t) {
                         downstream.accept(mapper.applyAsInt(t));
@@ -243,7 +242,7 @@
                                                     StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<Double> opWrapSink(int flags, Sink<Long> sink) {
-                return new Sink.ChainedDouble(sink) {
+                return new Sink.ChainedDouble<Long>(sink) {
                     @Override
                     public void accept(double t) {
                         downstream.accept(mapper.applyAsLong(t));
@@ -259,7 +258,7 @@
                                         StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
             @Override
             Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
-                return new Sink.ChainedDouble(sink) {
+                return new Sink.ChainedDouble<Double>(sink) {
                     @Override
                     public void begin(long size) {
                         downstream.begin(-1);
@@ -296,7 +295,7 @@
                                        StreamOpFlag.NOT_SIZED) {
             @Override
             Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
-                return new Sink.ChainedDouble(sink) {
+                return new Sink.ChainedDouble<Double>(sink) {
                     @Override
                     public void begin(long size) {
                         downstream.begin(-1);
@@ -319,7 +318,7 @@
                                        0) {
             @Override
             Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
-                return new Sink.ChainedDouble(sink) {
+                return new Sink.ChainedDouble<Double>(sink) {
                     @Override
                     public void accept(double t) {
                         consumer.accept(t);
--- a/src/share/classes/java/util/stream/IntPipeline.java	Mon Aug 26 14:53:15 2013 -0700
+++ b/src/share/classes/java/util/stream/IntPipeline.java	Mon Aug 26 22:18:48 2013 -0700
@@ -189,9 +189,8 @@
                                                      StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<Integer> opWrapSink(int flags, Sink<Long> sink) {
-                return new Sink.ChainedInt(sink) {
+                return new Sink.ChainedInt<Long>(sink) {
                     @Override
-                    @SuppressWarnings("unchecked")
                     public void accept(int t) {
                         downstream.accept((long) t);
                     }
@@ -206,9 +205,8 @@
                                                        StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<Integer> opWrapSink(int flags, Sink<Double> sink) {
-                return new Sink.ChainedInt(sink) {
+                return new Sink.ChainedInt<Double>(sink) {
                     @Override
-                    @SuppressWarnings("unchecked")
                     public void accept(int t) {
                         downstream.accept((double) t);
                     }
@@ -229,7 +227,7 @@
                                         StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
-                return new Sink.ChainedInt(sink) {
+                return new Sink.ChainedInt<Integer>(sink) {
                     @Override
                     public void accept(int t) {
                         downstream.accept(mapper.applyAsInt(t));
@@ -246,9 +244,8 @@
                                                              StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<Integer> opWrapSink(int flags, Sink<U> sink) {
-                return new Sink.ChainedInt(sink) {
+                return new Sink.ChainedInt<U>(sink) {
                     @Override
-                    @SuppressWarnings("unchecked")
                     public void accept(int t) {
                         downstream.accept(mapper.apply(t));
                     }
@@ -264,7 +261,7 @@
                                                      StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<Integer> opWrapSink(int flags, Sink<Long> sink) {
-                return new Sink.ChainedInt(sink) {
+                return new Sink.ChainedInt<Long>(sink) {
                     @Override
                     public void accept(int t) {
                         downstream.accept(mapper.applyAsLong(t));
@@ -281,7 +278,7 @@
                                                        StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<Integer> opWrapSink(int flags, Sink<Double> sink) {
-                return new Sink.ChainedInt(sink) {
+                return new Sink.ChainedInt<Double>(sink) {
                     @Override
                     public void accept(int t) {
                         downstream.accept(mapper.applyAsDouble(t));
@@ -297,7 +294,7 @@
                                         StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
             @Override
             Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
-                return new Sink.ChainedInt(sink) {
+                return new Sink.ChainedInt<Integer>(sink) {
                     @Override
                     public void begin(long size) {
                         downstream.begin(-1);
@@ -334,7 +331,7 @@
                                         StreamOpFlag.NOT_SIZED) {
             @Override
             Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
-                return new Sink.ChainedInt(sink) {
+                return new Sink.ChainedInt<Integer>(sink) {
                     @Override
                     public void begin(long size) {
                         downstream.begin(-1);
@@ -357,7 +354,7 @@
                                         0) {
             @Override
             Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
-                return new Sink.ChainedInt(sink) {
+                return new Sink.ChainedInt<Integer>(sink) {
                     @Override
                     public void accept(int t) {
                         consumer.accept(t);
--- a/src/share/classes/java/util/stream/LongPipeline.java	Mon Aug 26 14:53:15 2013 -0700
+++ b/src/share/classes/java/util/stream/LongPipeline.java	Mon Aug 26 22:18:48 2013 -0700
@@ -186,7 +186,7 @@
                                                     StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
-                return new Sink.ChainedLong(sink) {
+                return new Sink.ChainedLong<Double>(sink) {
                     @Override
                     public void accept(long t) {
                         downstream.accept((double) t);
@@ -208,9 +208,8 @@
                                      StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
-                return new Sink.ChainedLong(sink) {
+                return new Sink.ChainedLong<Long>(sink) {
                     @Override
-                    @SuppressWarnings("unchecked")
                     public void accept(long t) {
                         downstream.accept(mapper.applyAsLong(t));
                     }
@@ -226,9 +225,8 @@
                                                           StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<Long> opWrapSink(int flags, Sink<U> sink) {
-                return new Sink.ChainedLong(sink) {
+                return new Sink.ChainedLong<U>(sink) {
                     @Override
-                    @SuppressWarnings("unchecked")
                     public void accept(long t) {
                         downstream.accept(mapper.apply(t));
                     }
@@ -244,9 +242,8 @@
                                                  StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<Long> opWrapSink(int flags, Sink<Integer> sink) {
-                return new Sink.ChainedLong(sink) {
+                return new Sink.ChainedLong<Integer>(sink) {
                     @Override
-                    @SuppressWarnings("unchecked")
                     public void accept(long t) {
                         downstream.accept(mapper.applyAsInt(t));
                     }
@@ -262,7 +259,7 @@
                                                     StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<Long> opWrapSink(int flags, Sink<Double> sink) {
-                return new Sink.ChainedLong(sink) {
+                return new Sink.ChainedLong<Double>(sink) {
                     @Override
                     public void accept(long t) {
                         downstream.accept(mapper.applyAsDouble(t));
@@ -278,7 +275,7 @@
                                      StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
             @Override
             Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
-                return new Sink.ChainedLong(sink) {
+                return new Sink.ChainedLong<Long>(sink) {
                     @Override
                     public void begin(long size) {
                         downstream.begin(-1);
@@ -315,7 +312,7 @@
                                      StreamOpFlag.NOT_SIZED) {
             @Override
             Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
-                return new Sink.ChainedLong(sink) {
+                return new Sink.ChainedLong<Long>(sink) {
                     @Override
                     public void begin(long size) {
                         downstream.begin(-1);
@@ -338,7 +335,7 @@
                                      0) {
             @Override
             Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
-                return new Sink.ChainedLong(sink) {
+                return new Sink.ChainedLong<Long>(sink) {
                     @Override
                     public void accept(long t) {
                         consumer.accept(t);
--- a/src/share/classes/java/util/stream/ReferencePipeline.java	Mon Aug 26 14:53:15 2013 -0700
+++ b/src/share/classes/java/util/stream/ReferencePipeline.java	Mon Aug 26 22:18:48 2013 -0700
@@ -163,17 +163,16 @@
                                      StreamOpFlag.NOT_SIZED) {
             @Override
             Sink<P_OUT> opWrapSink(int flags, Sink<P_OUT> sink) {
-                return new Sink.ChainedReference<P_OUT>(sink) {
+                return new Sink.ChainedReference<P_OUT, P_OUT>(sink) {
                     @Override
                     public void begin(long size) {
                         downstream.begin(-1);
                     }
 
                     @Override
-                    @SuppressWarnings("unchecked")
                     public void accept(P_OUT u) {
                         if (predicate.test(u))
-                            downstream.accept((Object) u);
+                            downstream.accept(u);
                     }
                 };
             }
@@ -188,7 +187,7 @@
                                      StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<P_OUT> opWrapSink(int flags, Sink<R> sink) {
-                return new Sink.ChainedReference<P_OUT>(sink) {
+                return new Sink.ChainedReference<P_OUT, R>(sink) {
                     @Override
                     public void accept(P_OUT u) {
                         downstream.accept(mapper.apply(u));
@@ -205,7 +204,7 @@
                                               StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<P_OUT> opWrapSink(int flags, Sink<Integer> sink) {
-                return new Sink.ChainedReference<P_OUT>(sink) {
+                return new Sink.ChainedReference<P_OUT, Integer>(sink) {
                     @Override
                     public void accept(P_OUT u) {
                         downstream.accept(mapper.applyAsInt(u));
@@ -222,7 +221,7 @@
                                       StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<P_OUT> opWrapSink(int flags, Sink<Long> sink) {
-                return new Sink.ChainedReference<P_OUT>(sink) {
+                return new Sink.ChainedReference<P_OUT, Long>(sink) {
                     @Override
                     public void accept(P_OUT u) {
                         downstream.accept(mapper.applyAsLong(u));
@@ -239,7 +238,7 @@
                                         StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
             @Override
             Sink<P_OUT> opWrapSink(int flags, Sink<Double> sink) {
-                return new Sink.ChainedReference<P_OUT>(sink) {
+                return new Sink.ChainedReference<P_OUT, Double>(sink) {
                     @Override
                     public void accept(P_OUT u) {
                         downstream.accept(mapper.applyAsDouble(u));
@@ -257,14 +256,13 @@
                                      StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
             @Override
             Sink<P_OUT> opWrapSink(int flags, Sink<R> sink) {
-                return new Sink.ChainedReference<P_OUT>(sink) {
+                return new Sink.ChainedReference<P_OUT, R>(sink) {
                     @Override
                     public void begin(long size) {
                         downstream.begin(-1);
                     }
 
                     @Override
-                    @SuppressWarnings("unchecked")
                     public void accept(P_OUT u) {
                         // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                         Stream<? extends R> result = mapper.apply(u);
@@ -284,7 +282,7 @@
                                               StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
             @Override
             Sink<P_OUT> opWrapSink(int flags, Sink<Integer> sink) {
-                return new Sink.ChainedReference<P_OUT>(sink) {
+                return new Sink.ChainedReference<P_OUT, Integer>(sink) {
                     IntConsumer downstreamAsInt = downstream::accept;
                     @Override
                     public void begin(long size) {
@@ -311,7 +309,7 @@
                                                      StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
             @Override
             Sink<P_OUT> opWrapSink(int flags, Sink<Double> sink) {
-                return new Sink.ChainedReference<P_OUT>(sink) {
+                return new Sink.ChainedReference<P_OUT, Double>(sink) {
                     DoubleConsumer downstreamAsDouble = downstream::accept;
                     @Override
                     public void begin(long size) {
@@ -338,7 +336,7 @@
                                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
             @Override
             Sink<P_OUT> opWrapSink(int flags, Sink<Long> sink) {
-                return new Sink.ChainedReference<P_OUT>(sink) {
+                return new Sink.ChainedReference<P_OUT, Long>(sink) {
                     LongConsumer downstreamAsLong = downstream::accept;
                     @Override
                     public void begin(long size) {
@@ -364,9 +362,8 @@
                                      0) {
             @Override
             Sink<P_OUT> opWrapSink(int flags, Sink<P_OUT> sink) {
-                return new Sink.ChainedReference<P_OUT>(sink) {
+                return new Sink.ChainedReference<P_OUT, P_OUT>(sink) {
                     @Override
-                    @SuppressWarnings("unchecked")
                     public void accept(P_OUT u) {
                         tee.accept(u);
                         downstream.accept(u);
@@ -495,6 +492,7 @@
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     public final <R, A> R collect(Collector<? super P_OUT, A, ? extends R> collector) {
         A container;
         if (isParallel()
--- a/src/share/classes/java/util/stream/Sink.java	Mon Aug 26 14:53:15 2013 -0700
+++ b/src/share/classes/java/util/stream/Sink.java	Mon Aug 26 22:18:48 2013 -0700
@@ -241,11 +241,10 @@
      * implementation of the {@code accept()} method must call the correct
      * {@code accept()} method on the downstream {@code Sink}.
      */
-    static abstract class ChainedReference<T> implements Sink<T> {
-        @SuppressWarnings("rawtypes")
-        protected final Sink downstream;
+    static abstract class ChainedReference<T, E_OUT> implements Sink<T> {
+        protected final Sink<? super E_OUT> downstream;
 
-        public ChainedReference(Sink downstream) {
+        public ChainedReference(Sink<? super E_OUT> downstream) {
             this.downstream = Objects.requireNonNull(downstream);
         }
 
@@ -274,11 +273,10 @@
      * The implementation of the {@code accept()} method must call the correct
      * {@code accept()} method on the downstream {@code Sink}.
      */
-    static abstract class ChainedInt implements Sink.OfInt {
-        @SuppressWarnings("rawtypes")
-        protected final Sink downstream;
+    static abstract class ChainedInt<E_OUT> implements Sink.OfInt {
+        protected final Sink<? super E_OUT> downstream;
 
-        public ChainedInt(Sink downstream) {
+        public ChainedInt(Sink<? super E_OUT> downstream) {
             this.downstream = Objects.requireNonNull(downstream);
         }
 
@@ -307,11 +305,10 @@
      * The implementation of the {@code accept()} method must call the correct
      * {@code accept()} method on the downstream {@code Sink}.
      */
-    static abstract class ChainedLong implements Sink.OfLong {
-        @SuppressWarnings("rawtypes")
-        protected final Sink downstream;
+    static abstract class ChainedLong<E_OUT> implements Sink.OfLong {
+        protected final Sink<? super E_OUT> downstream;
 
-        public ChainedLong(Sink downstream) {
+        public ChainedLong(Sink<? super E_OUT> downstream) {
             this.downstream = Objects.requireNonNull(downstream);
         }
 
@@ -340,11 +337,10 @@
      * The implementation of the {@code accept()} method must call the correct
      * {@code accept()} method on the downstream {@code Sink}.
      */
-    static abstract class ChainedDouble implements Sink.OfDouble {
-        @SuppressWarnings("rawtypes")
-        protected final Sink downstream;
+    static abstract class ChainedDouble<E_OUT> implements Sink.OfDouble {
+        protected final Sink<? super E_OUT> downstream;
 
-        public ChainedDouble(Sink downstream) {
+        public ChainedDouble(Sink<? super E_OUT> downstream) {
             this.downstream = Objects.requireNonNull(downstream);
         }
 
--- a/src/share/classes/java/util/stream/SliceOps.java	Mon Aug 26 14:53:15 2013 -0700
+++ b/src/share/classes/java/util/stream/SliceOps.java	Mon Aug 26 22:18:48 2013 -0700
@@ -96,6 +96,11 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
+    private static <T> IntFunction<T[]> castingArray() {
+        return size -> (T[]) new Object[size];
+    }
+
     /**
      * Appends a "slice" operation to the provided stream.  The slice operation
      * may be may be skip-only, limit-only, or skip-and-limit.
@@ -107,12 +112,12 @@
      *        is to be imposed
      */
     public static <T> Stream<T> makeRef(AbstractPipeline<?, T, ?> upstream,
-                                       long skip, long limit) {
+                                        long skip, long limit) {
         if (skip < 0)
             throw new IllegalArgumentException("Skip must be non-negative: " + skip);
 
-        return new ReferencePipeline.StatefulOp<T,T>(upstream, StreamShape.REFERENCE,
-                                                     flags(limit)) {
+        return new ReferencePipeline.StatefulOp<T, T>(upstream, StreamShape.REFERENCE,
+                                                      flags(limit)) {
             Spliterator<T> unorderedSkipLimitSpliterator(Spliterator<T> s,
                                                          long skip, long limit, long sizeIfKnown) {
                 if (skip <= sizeIfKnown) {
@@ -146,7 +151,7 @@
                     //     cancellation will be more aggressive cancelling later tasks
                     //     if the target slice size has been reached from a given task,
                     //     cancellation should also clear local results if any
-                    return new SliceTask<>(this, helper, spliterator, i -> (T[]) new Object[i], skip, limit).
+                    return new SliceTask<>(this, helper, spliterator, castingArray(), skip, limit).
                             invoke().spliterator();
                 }
             }
@@ -182,7 +187,7 @@
 
             @Override
             Sink<T> opWrapSink(int flags, Sink<T> sink) {
-                return new Sink.ChainedReference<T>(sink) {
+                return new Sink.ChainedReference<T, T>(sink) {
                     long n = skip;
                     long m = limit >= 0 ? limit : Long.MAX_VALUE;
 
@@ -291,7 +296,7 @@
 
             @Override
             Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
-                return new Sink.ChainedInt(sink) {
+                return new Sink.ChainedInt<Integer>(sink) {
                     long n = skip;
                     long m = limit >= 0 ? limit : Long.MAX_VALUE;
 
@@ -400,7 +405,7 @@
 
             @Override
             Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
-                return new Sink.ChainedLong(sink) {
+                return new Sink.ChainedLong<Long>(sink) {
                     long n = skip;
                     long m = limit >= 0 ? limit : Long.MAX_VALUE;
 
@@ -509,7 +514,7 @@
 
             @Override
             Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
-                return new Sink.ChainedDouble(sink) {
+                return new Sink.ChainedDouble<Double>(sink) {
                     long n = skip;
                     long m = limit >= 0 ? limit : Long.MAX_VALUE;
 
@@ -560,13 +565,13 @@
 
         private volatile boolean completed;
 
-        SliceTask(AbstractPipeline<?, P_OUT, ?> op,
+        SliceTask(AbstractPipeline<P_OUT, P_OUT, ?> op,
                   PipelineHelper<P_OUT> helper,
                   Spliterator<P_IN> spliterator,
                   IntFunction<P_OUT[]> generator,
                   long offset, long size) {
             super(helper, spliterator);
-            this.op = (AbstractPipeline<P_OUT, P_OUT, ?>) op;
+            this.op = op;
             this.generator = generator;
             this.targetOffset = offset;
             this.targetSize = size;
--- a/src/share/classes/java/util/stream/SortedOps.java	Mon Aug 26 14:53:15 2013 -0700
+++ b/src/share/classes/java/util/stream/SortedOps.java	Mon Aug 26 22:18:48 2013 -0700
@@ -129,7 +129,7 @@
         }
 
         @Override
-        public Sink<T> opWrapSink(int flags, Sink sink) {
+        public Sink<T> opWrapSink(int flags, Sink<T> sink) {
             Objects.requireNonNull(sink);
 
             // If the input is already naturally sorted and this operation
@@ -280,12 +280,12 @@
     /**
      * {@link ForkJoinTask} for implementing sort on SIZED reference streams.
      */
-    private static final class SizedRefSortingSink<T> extends Sink.ChainedReference<T> {
+    private static final class SizedRefSortingSink<T> extends Sink.ChainedReference<T, T> {
         private final Comparator<? super T> comparator;
         private T[] array;
         private int offset;
 
-        SizedRefSortingSink(Sink<T> sink, Comparator<? super T> comparator) {
+        SizedRefSortingSink(Sink<? super T> sink, Comparator<? super T> comparator) {
             super(sink);
             this.comparator = comparator;
         }
@@ -320,11 +320,11 @@
     /**
      * {@link Sink} for implementing sort on reference streams.
      */
-    private static final class RefSortingSink<T> extends Sink.ChainedReference<T> {
+    private static final class RefSortingSink<T> extends Sink.ChainedReference<T, T> {
         private final Comparator<? super T> comparator;
         private ArrayList<T> list;
 
-        RefSortingSink(Sink<T> sink, Comparator<? super T> comparator) {
+        RefSortingSink(Sink<? super T> sink, Comparator<? super T> comparator) {
             super(sink);
             this.comparator = comparator;
         }
@@ -352,11 +352,11 @@
     /**
      * {@link Sink} for implementing sort on SIZED int streams.
      */
-    private static final class SizedIntSortingSink extends Sink.ChainedInt {
+    private static final class SizedIntSortingSink extends Sink.ChainedInt<Integer> {
         private int[] array;
         private int offset;
 
-        SizedIntSortingSink(Sink downstream) {
+        SizedIntSortingSink(Sink<? super Integer> downstream) {
             super(downstream);
         }
 
@@ -386,10 +386,10 @@
     /**
      * {@link Sink} for implementing sort on int streams.
      */
-    private static final class IntSortingSink extends Sink.ChainedInt {
+    private static final class IntSortingSink extends Sink.ChainedInt<Integer> {
         private SpinedBuffer.OfInt b;
 
-        IntSortingSink(Sink sink) {
+        IntSortingSink(Sink<? super Integer> sink) {
             super(sink);
         }
 
@@ -417,11 +417,11 @@
     /**
      * {@link Sink} for implementing sort on SIZED long streams.
      */
-    private static final class SizedLongSortingSink extends Sink.ChainedLong {
+    private static final class SizedLongSortingSink extends Sink.ChainedLong<Long> {
         private long[] array;
         private int offset;
 
-        SizedLongSortingSink(Sink downstream) {
+        SizedLongSortingSink(Sink<? super Long> downstream) {
             super(downstream);
         }
 
@@ -451,10 +451,10 @@
     /**
      * {@link Sink} for implementing sort on long streams.
      */
-    private static final class LongSortingSink extends Sink.ChainedLong {
+    private static final class LongSortingSink extends Sink.ChainedLong<Long> {
         private SpinedBuffer.OfLong b;
 
-        LongSortingSink(Sink sink) {
+        LongSortingSink(Sink<? super Long> sink) {
             super(sink);
         }
 
@@ -482,11 +482,11 @@
     /**
      * {@link Sink} for implementing sort on SIZED double streams.
      */
-    private static final class SizedDoubleSortingSink extends Sink.ChainedDouble {
+    private static final class SizedDoubleSortingSink extends Sink.ChainedDouble<Double> {
         private double[] array;
         private int offset;
 
-        SizedDoubleSortingSink(Sink downstream) {
+        SizedDoubleSortingSink(Sink<? super Double> downstream) {
             super(downstream);
         }
 
@@ -516,10 +516,10 @@
     /**
      * {@link Sink} for implementing sort on double streams.
      */
-    private static final class DoubleSortingSink extends Sink.ChainedDouble {
+    private static final class DoubleSortingSink extends Sink.ChainedDouble<Double> {
         private SpinedBuffer.OfDouble b;
 
-        DoubleSortingSink(Sink sink) {
+        DoubleSortingSink(Sink<? super Double> sink) {
             super(sink);
         }