changeset 7742:1e7d8b107fc4

Merge
author lana
date Mon, 12 Jan 2015 14:31:51 -0800
parents f3be45662150 c50717143e6d
children f8b3811337b7
files
diffstat 15 files changed, 233 insertions(+), 81 deletions(-) [+]
line wrap: on
line diff
--- a/make/java/zip/Makefile	Tue Jan 06 13:32:22 2015 -0800
+++ b/make/java/zip/Makefile	Mon Jan 12 14:31:51 2015 -0800
@@ -68,6 +68,16 @@
     FILES_reorder += reorder-$(ARCH)
   endif
 endif
+
+#
+# Use mapfile unconditionally (even with fastdebug).
+# JDK's internal zlib is incompatible with stock zlib, because the
+# size of struct z_stream has been changed, so internal zlib
+# implementation must not be allowed to leak outside of libzip.so,
+# else you get hard to debug failures with fastdebug jdk when user
+# native code includes stock zlib.
+#
+FILES_m = mapfile-vers
 include $(BUILDDIR)/common/Mapfile-vers.gmk
 include $(BUILDDIR)/common/Library.gmk
 
--- a/src/share/classes/sun/nio/ch/FileChannelImpl.java	Tue Jan 06 13:32:22 2015 -0800
+++ b/src/share/classes/sun/nio/ch/FileChannelImpl.java	Mon Jan 12 14:31:51 2015 -0800
@@ -397,30 +397,13 @@
     //
     private static volatile boolean fileSupported = true;
 
-    private long transferToDirectly(long position, int icount,
-                                    WritableByteChannel target)
+    private long transferToDirectlyInternal(long position, int icount,
+                                            WritableByteChannel target,
+                                            FileDescriptor targetFD)
         throws IOException
     {
-        if (!transferSupported)
-            return IOStatus.UNSUPPORTED;
-
-        FileDescriptor targetFD = null;
-        if (target instanceof FileChannelImpl) {
-            if (!fileSupported)
-                return IOStatus.UNSUPPORTED_CASE;
-            targetFD = ((FileChannelImpl)target).fd;
-        } else if (target instanceof SelChImpl) {
-            // Direct transfer to pipe causes EINVAL on some configurations
-            if ((target instanceof SinkChannelImpl) && !pipeSupported)
-                return IOStatus.UNSUPPORTED_CASE;
-            targetFD = ((SelChImpl)target).getFD();
-        }
-        if (targetFD == null)
-            return IOStatus.UNSUPPORTED;
-        int thisFDVal = IOUtil.fdVal(fd);
-        int targetFDVal = IOUtil.fdVal(targetFD);
-        if (thisFDVal == targetFDVal) // Not supported on some configurations
-            return IOStatus.UNSUPPORTED;
+        assert !nd.transferToDirectlyNeedsPositionLock() ||
+               Thread.holdsLock(positionLock);
 
         long n = -1;
         int ti = -1;
@@ -430,7 +413,7 @@
             if (!isOpen())
                 return -1;
             do {
-                n = transferTo0(thisFDVal, position, icount, targetFDVal);
+                n = transferTo0(fd, position, icount, targetFD);
             } while ((n == IOStatus.INTERRUPTED) && isOpen());
             if (n == IOStatus.UNSUPPORTED_CASE) {
                 if (target instanceof SinkChannelImpl)
@@ -451,6 +434,54 @@
         }
     }
 
+    private long transferToDirectly(long position, int icount,
+                                    WritableByteChannel target)
+        throws IOException
+    {
+        if (!transferSupported)
+            return IOStatus.UNSUPPORTED;
+
+        FileDescriptor targetFD = null;
+        if (target instanceof FileChannelImpl) {
+            if (!fileSupported)
+                return IOStatus.UNSUPPORTED_CASE;
+            targetFD = ((FileChannelImpl)target).fd;
+        } else if (target instanceof SelChImpl) {
+            // Direct transfer to pipe causes EINVAL on some configurations
+            if ((target instanceof SinkChannelImpl) && !pipeSupported)
+                return IOStatus.UNSUPPORTED_CASE;
+
+            // Platform-specific restrictions. Now there is only one:
+            // Direct transfer to non-blocking channel could be forbidden
+            SelectableChannel sc = (SelectableChannel)target;
+            if (!nd.canTransferToDirectly(sc))
+                return IOStatus.UNSUPPORTED_CASE;
+
+            targetFD = ((SelChImpl)target).getFD();
+        }
+
+        if (targetFD == null)
+            return IOStatus.UNSUPPORTED;
+        int thisFDVal = IOUtil.fdVal(fd);
+        int targetFDVal = IOUtil.fdVal(targetFD);
+        if (thisFDVal == targetFDVal) // Not supported on some configurations
+            return IOStatus.UNSUPPORTED;
+
+        if (nd.transferToDirectlyNeedsPositionLock()) {
+            synchronized (positionLock) {
+                long pos = position();
+                try {
+                    return transferToDirectlyInternal(position, icount,
+                                                      target, targetFD);
+                } finally {
+                    position(pos);
+                }
+            }
+        } else {
+            return transferToDirectlyInternal(position, icount, target, targetFD);
+        }
+    }
+
     // Maximum size to map when using a mapped buffer
     private static final long MAPPED_TRANSFER_SIZE = 8L*1024L*1024L;
 
@@ -1157,7 +1188,8 @@
     private static native int unmap0(long address, long length);
 
     // Transfers from src to dst, or returns -2 if kernel can't do that
-    private native long transferTo0(int src, long position, long count, int dst);
+    private native long transferTo0(FileDescriptor src, long position,
+                                    long count, FileDescriptor dst);
 
     // Sets or reports this file's position
     // If offset is -1, the current position is returned
--- a/src/share/classes/sun/nio/ch/FileDispatcher.java	Tue Jan 06 13:32:22 2015 -0800
+++ b/src/share/classes/sun/nio/ch/FileDispatcher.java	Mon Jan 12 14:31:51 2015 -0800
@@ -25,7 +25,9 @@
 
 package sun.nio.ch;
 
-import java.io.*;
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.nio.channels.SelectableChannel;
 
 abstract class FileDispatcher extends NativeDispatcher {
 
@@ -53,4 +55,8 @@
      */
     abstract FileDescriptor duplicateForMapping(FileDescriptor fd)
         throws IOException;
+
+    abstract boolean canTransferToDirectly(SelectableChannel sc);
+
+    abstract boolean transferToDirectlyNeedsPositionLock();
 }
--- a/src/share/classes/sun/reflect/generics/repository/ClassRepository.java	Tue Jan 06 13:32:22 2015 -0800
+++ b/src/share/classes/sun/reflect/generics/repository/ClassRepository.java	Mon Jan 12 14:31:51 2015 -0800
@@ -40,8 +40,11 @@
  */
 public class ClassRepository extends GenericDeclRepository<ClassSignature> {
 
-    private volatile Type superclass; // caches the generic superclass info
-    private volatile Type[] superInterfaces; // caches the generic superinterface info
+    /** The generic superclass info.  Lazily initialized. */
+    private volatile Type superclass;
+
+    /** The generic superinterface info.  Lazily initialized. */
+    private volatile Type[] superInterfaces;
 
  // private, to enforce use of static factory
     private ClassRepository(String rawSig, GenericsFactory f) {
@@ -77,7 +80,7 @@
  * with which the repository was created.
  */
 
-    public Type getSuperclass(){
+    public Type getSuperclass() {
         Type superclass = this.superclass;
         if (superclass == null) { // lazily initialize superclass
             Reifier r = getReifier(); // obtain visitor
@@ -86,25 +89,24 @@
             // extract result from visitor and cache it
             superclass = r.getResult();
             this.superclass = superclass;
-            }
+        }
         return superclass; // return cached result
     }
 
-    public Type[] getSuperInterfaces(){
+    public Type[] getSuperInterfaces() {
         Type[] superInterfaces = this.superInterfaces;
         if (superInterfaces == null) { // lazily initialize super interfaces
             // first, extract super interface subtree(s) from AST
             TypeTree[] ts  = getTree().getSuperInterfaces();
             // create array to store reified subtree(s)
-            Type[] sis = new Type[ts.length];
+            superInterfaces = new Type[ts.length];
             // reify all subtrees
             for (int i = 0; i < ts.length; i++) {
                 Reifier r = getReifier(); // obtain visitor
                 ts[i].accept(r);// reify subtree
                 // extract result from visitor and store it
-                sis[i] = r.getResult();
+                superInterfaces[i] = r.getResult();
             }
-            superInterfaces = sis; // cache overall result
             this.superInterfaces = superInterfaces;
         }
         return superInterfaces.clone(); // return cached result
--- a/src/share/classes/sun/reflect/generics/repository/GenericDeclRepository.java	Tue Jan 06 13:32:22 2015 -0800
+++ b/src/share/classes/sun/reflect/generics/repository/GenericDeclRepository.java	Mon Jan 12 14:31:51 2015 -0800
@@ -42,7 +42,8 @@
 public abstract class GenericDeclRepository<S extends Signature>
     extends AbstractRepository<S> {
 
-    private volatile TypeVariable[] typeParams; // caches the formal type parameters
+    /** The formal type parameters.  Lazily initialized. */
+    private volatile TypeVariable[] typeParams;
 
     protected GenericDeclRepository(String rawSig, GenericsFactory f) {
         super(rawSig, f);
@@ -55,8 +56,7 @@
  * If the corresponding field is non-null, it is returned.
  * If not, it is created lazily. This is done by selecting the appropriate
  * part of the tree and transforming it into a reflective object
- * using a visitor.
- * a visitor, which is created by feeding it the factory
+ * using a visitor, which is created by feeding it the factory
  * with which the repository was created.
  */
 
@@ -64,22 +64,21 @@
      * Return the formal type parameters of this generic declaration.
      * @return the formal type parameters of this generic declaration
      */
-    public TypeVariable/*<?>*/[] getTypeParameters(){
+    public TypeVariable/*<?>*/[] getTypeParameters() {
         TypeVariable[] typeParams = this.typeParams;
         if (typeParams == null) { // lazily initialize type parameters
             // first, extract type parameter subtree(s) from AST
             FormalTypeParameter[] ftps = getTree().getFormalTypeParameters();
             // create array to store reified subtree(s)
-            TypeVariable[] tps = new TypeVariable[ftps.length];
+            typeParams = new TypeVariable[ftps.length];
             // reify all subtrees
             for (int i = 0; i < ftps.length; i++) {
                 Reifier r = getReifier(); // obtain visitor
                 ftps[i].accept(r); // reify subtree
                 // extract result from visitor and store it
-                tps[i] = (TypeVariable<?>) r.getResult();
+                typeParams[i] = (TypeVariable) r.getResult();
             }
-            typeParams = tps; // cache overall result
-            this.typeParams = typeParams;
+            this.typeParams = typeParams; // cache overall result
         }
         return typeParams.clone(); // return cached result
     }
--- a/src/share/classes/sun/reflect/generics/scope/AbstractScope.java	Tue Jan 06 13:32:22 2015 -0800
+++ b/src/share/classes/sun/reflect/generics/scope/AbstractScope.java	Mon Jan 12 14:31:51 2015 -0800
@@ -42,7 +42,9 @@
     implements Scope {
 
     private final D recvr; // the declaration whose scope this instance represents
-    private volatile Scope enclosingScope; // the enclosing scope of this scope
+
+    /** The enclosing scope of this scope.  Lazily initialized. */
+    private volatile Scope enclosingScope;
 
     /**
      * Constructor. Takes a reflective object whose scope the newly
--- a/src/share/native/java/util/zip/Deflater.c	Tue Jan 06 13:32:22 2015 -0800
+++ b/src/share/native/java/util/zip/Deflater.c	Mon Jan 12 14:31:51 2015 -0800
@@ -68,10 +68,11 @@
         JNU_ThrowOutOfMemoryError(env, 0);
         return jlong_zero;
     } else {
-        char *msg;
-        switch (deflateInit2(strm, level, Z_DEFLATED,
-                             nowrap ? -MAX_WBITS : MAX_WBITS,
-                             DEF_MEM_LEVEL, strategy)) {
+        const char *msg;
+        int ret = deflateInit2(strm, level, Z_DEFLATED,
+                               nowrap ? -MAX_WBITS : MAX_WBITS,
+                               DEF_MEM_LEVEL, strategy);
+        switch (ret) {
           case Z_OK:
             return ptr_to_jlong(strm);
           case Z_MEM_ERROR:
@@ -83,7 +84,11 @@
             JNU_ThrowIllegalArgumentException(env, 0);
             return jlong_zero;
           default:
-            msg = strm->msg;
+            msg = ((strm->msg != NULL) ? strm->msg :
+                   (ret == Z_VERSION_ERROR) ?
+                   "zlib returned Z_VERSION_ERROR: "
+                   "compile time and runtime zlib implementations differ" :
+                   "unknown error initializing zlib library");
             free(strm);
             JNU_ThrowInternalError(env, msg);
             return jlong_zero;
--- a/src/share/native/java/util/zip/Inflater.c	Tue Jan 06 13:32:22 2015 -0800
+++ b/src/share/native/java/util/zip/Inflater.c	Mon Jan 12 14:31:51 2015 -0800
@@ -27,6 +27,7 @@
  * Native method support for java.util.zip.Inflater
  */
 
+#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -60,12 +61,13 @@
 {
     z_stream *strm = calloc(1, sizeof(z_stream));
 
-    if (strm == 0) {
+    if (strm == NULL) {
         JNU_ThrowOutOfMemoryError(env, 0);
         return jlong_zero;
     } else {
-        char *msg;
-        switch (inflateInit2(strm, nowrap ? -MAX_WBITS : MAX_WBITS)) {
+        const char *msg;
+        int ret = inflateInit2(strm, nowrap ? -MAX_WBITS : MAX_WBITS);
+        switch (ret) {
           case Z_OK:
             return ptr_to_jlong(strm);
           case Z_MEM_ERROR:
@@ -73,7 +75,13 @@
             JNU_ThrowOutOfMemoryError(env, 0);
             return jlong_zero;
           default:
-            msg = strm->msg;
+            msg = ((strm->msg != NULL) ? strm->msg :
+                   (ret == Z_VERSION_ERROR) ?
+                   "zlib returned Z_VERSION_ERROR: "
+                   "compile time and runtime zlib implementations differ" :
+                   (ret == Z_STREAM_ERROR) ?
+                   "inflateInit2 returned Z_STREAM_ERROR" :
+                   "unknown error initializing zlib library");
             free(strm);
             JNU_ThrowInternalError(env, msg);
             return jlong_zero;
--- a/src/solaris/classes/sun/awt/X11/XErrorHandlerUtil.java	Tue Jan 06 13:32:22 2015 -0800
+++ b/src/solaris/classes/sun/awt/X11/XErrorHandlerUtil.java	Mon Jan 12 14:31:51 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, 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
@@ -97,6 +97,7 @@
      * @param handler the synthetic error handler to set
      */
     public static void WITH_XERROR_HANDLER(XErrorHandler handler) {
+        XSync();
         saved_error = null;
         current_error_handler = handler;
     }
@@ -105,15 +106,9 @@
      * Unsets a current synthetic error handler. Must be called with the acquired AWT lock.
      */
     public static void RESTORE_XERROR_HANDLER() {
-        RESTORE_XERROR_HANDLER(true);
-    }
-
-    private static void RESTORE_XERROR_HANDLER(boolean doXSync) {
-        if (doXSync) {
-            // Wait until all requests are processed by the X server
-            // and only then uninstall the error handler.
-            XSync();
-        }
+        // Wait until all requests are processed by the X server
+        // and only then uninstall the error handler.
+        XSync();
         current_error_handler = null;
     }
 
--- a/src/solaris/classes/sun/nio/ch/FileDispatcherImpl.java	Tue Jan 06 13:32:22 2015 -0800
+++ b/src/solaris/classes/sun/nio/ch/FileDispatcherImpl.java	Mon Jan 12 14:31:51 2015 -0800
@@ -25,10 +25,10 @@
 
 package sun.nio.ch;
 
-import java.io.*;
+import java.io.FileDescriptor;
+import java.io.IOException;
 
-class FileDispatcherImpl extends FileDispatcher
-{
+class FileDispatcherImpl extends FileDispatcher {
 
     static {
         Util.load();
@@ -108,6 +108,14 @@
         return new FileDescriptor();
     }
 
+    boolean canTransferToDirectly(java.nio.channels.SelectableChannel sc) {
+        return true;
+    }
+
+    boolean transferToDirectlyNeedsPositionLock() {
+        return false;
+    }
+
     // -- Native methods --
 
     static native int read0(FileDescriptor fd, long address, int len)
--- a/src/solaris/native/sun/nio/ch/FileChannelImpl.c	Tue Jan 06 13:32:22 2015 -0800
+++ b/src/solaris/native/sun/nio/ch/FileChannelImpl.c	Mon Jan 12 14:31:51 2015 -0800
@@ -152,10 +152,13 @@
 
 JNIEXPORT jlong JNICALL
 Java_sun_nio_ch_FileChannelImpl_transferTo0(JNIEnv *env, jobject this,
-                                            jint srcFD,
+                                            jobject srcFDO,
                                             jlong position, jlong count,
-                                            jint dstFD)
+                                            jobject dstFDO)
 {
+    jint srcFD = fdval(env, srcFDO);
+    jint dstFD = fdval(env, dstFDO);
+
 #if defined(__linux__)
     off64_t offset = (off64_t)position;
     jlong n = sendfile64(dstFD, srcFD, &offset, (size_t)count);
--- a/src/windows/classes/sun/nio/ch/FileDispatcherImpl.java	Tue Jan 06 13:32:22 2015 -0800
+++ b/src/windows/classes/sun/nio/ch/FileDispatcherImpl.java	Mon Jan 12 14:31:51 2015 -0800
@@ -25,15 +25,16 @@
 
 package sun.nio.ch;
 
-import java.io.*;
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.security.PrivilegedAction;
 import sun.misc.SharedSecrets;
 import sun.misc.JavaIOFileDescriptorAccess;
 
-class FileDispatcherImpl extends FileDispatcher
-{
-    static {
-        Util.load();
-    }
+class FileDispatcherImpl extends FileDispatcher {
+
+    // set to true if fast file transmission (TransmitFile) is enabled
+    private static final boolean fastFileTransfer;
 
     /**
      * Indicates if the dispatcher should first advance the file position
@@ -120,6 +121,36 @@
         return result;
     }
 
+    boolean canTransferToDirectly(java.nio.channels.SelectableChannel sc) {
+        return fastFileTransfer && sc.isBlocking();
+    }
+
+    boolean transferToDirectlyNeedsPositionLock() {
+        return true;
+    }
+
+    static boolean isFastFileTransferRequested() {
+        String fileTransferProp = java.security.AccessController.doPrivileged(
+            new PrivilegedAction<String>() {
+                @Override
+                public String run() {
+                    return System.getProperty("jdk.nio.enableFastFileTransfer");
+                }
+            });
+        boolean enable;
+        if ("".equals(fileTransferProp)) {
+            enable = true;
+        } else {
+            enable = Boolean.parseBoolean(fileTransferProp);
+        }
+        return enable;
+    }
+
+    static {
+        Util.load();
+        fastFileTransfer = isFastFileTransferRequested();
+    }
+
     //-- Native methods
 
     static native int read0(FileDescriptor fd, long address, int len)
--- a/src/windows/native/sun/nio/ch/FileChannelImpl.c	Tue Jan 06 13:32:22 2015 -0800
+++ b/src/windows/native/sun/nio/ch/FileChannelImpl.c	Mon Jan 12 14:31:51 2015 -0800
@@ -31,6 +31,11 @@
 #include "nio.h"
 #include "nio_util.h"
 #include "sun_nio_ch_FileChannelImpl.h"
+#include "java_lang_Integer.h"
+
+#include <winsock2.h>
+#include <Mswsock.h>
+#pragma comment(lib, "Mswsock.lib")
 
 static jfieldID chan_fd; /* id for jobject 'fd' in java.io.FileChannel */
 
@@ -174,9 +179,42 @@
 
 JNIEXPORT jlong JNICALL
 Java_sun_nio_ch_FileChannelImpl_transferTo0(JNIEnv *env, jobject this,
-                                            jint srcFD,
+                                            jobject srcFD,
                                             jlong position, jlong count,
-                                            jint dstFD)
+                                            jobject dstFD)
 {
-    return IOS_UNSUPPORTED;
+    const int PACKET_SIZE = 524288;
+
+    HANDLE src = (HANDLE)(handleval(env, srcFD));
+    SOCKET dst = (SOCKET)(fdval(env, dstFD));
+    DWORD chunkSize = (count > java_lang_Integer_MAX_VALUE) ?
+        java_lang_Integer_MAX_VALUE : (DWORD)count;
+    BOOL result = 0;
+
+    jlong pos = Java_sun_nio_ch_FileChannelImpl_position0(env, this, srcFD, position);
+    if (pos == IOS_THROWN) {
+        return IOS_THROWN;
+    }
+
+    result = TransmitFile(
+        dst,
+        src,
+        chunkSize,
+        PACKET_SIZE,
+        NULL,
+        NULL,
+        TF_USE_KERNEL_APC
+    );
+    if (!result) {
+        int error = WSAGetLastError();
+        if (WSAEINVAL == error && count >= 0) {
+            return IOS_UNSUPPORTED_CASE;
+        }
+        if (WSAENOTSOCK == error) {
+            return IOS_UNSUPPORTED_CASE;
+        }
+        JNU_ThrowIOExceptionWithLastError(env, "transfer failed");
+        return IOS_THROWN;
+    }
+    return chunkSize;
 }
--- a/test/java/lang/reflect/Method/GenericStringTest.java	Tue Jan 06 13:32:22 2015 -0800
+++ b/test/java/lang/reflect/Method/GenericStringTest.java	Mon Jan 12 14:31:51 2015 -0800
@@ -47,10 +47,18 @@
                 if (egs != null) {
                     String actual = method.toGenericString();
                     System.out.println(actual);
-                    if (! egs.value().equals(actual)) {
-                        failures++;
-                        System.err.printf("ERROR: Expected ''%s''; got ''%s''.\n",
-                                          egs.value(), actual);
+                    if (method.isBridge()) {
+                        if (! egs.bridgeValue().equals(actual)) {
+                            failures++;
+                            System.err.printf("ERROR: Expected ''%s''; got ''%s''.\n",
+                                              egs.value(), actual);
+                        }
+                    } else {
+                        if (! egs.value().equals(actual)) {
+                            failures++;
+                            System.err.printf("ERROR: Expected ''%s''; got ''%s''.\n",
+                                              egs.value(), actual);
+                        }
                     }
                 }
 
@@ -116,7 +124,8 @@
 
 class Roebling implements Comparable<Roebling> {
     @ExpectedGenericString(
-   "public int Roebling.compareTo(Roebling)")
+    value="public int Roebling.compareTo(Roebling)",
+    bridgeValue="public int Roebling.compareTo(java.lang.Object)")
     public int compareTo(Roebling r) {
         throw new IllegalArgumentException();
     }
@@ -132,9 +141,11 @@
 @Retention(RetentionPolicy.RUNTIME)
 @interface ExpectedGenericString {
     String value();
+    String bridgeValue() default "";
 }
 
 @Retention(RetentionPolicy.RUNTIME)
 @interface ExpectedString {
     String value();
 }
+
--- a/test/java/nio/channels/FileChannel/TransferToChannel.java	Tue Jan 06 13:32:22 2015 -0800
+++ b/test/java/nio/channels/FileChannel/TransferToChannel.java	Mon Jan 12 14:31:51 2015 -0800
@@ -22,8 +22,10 @@
  */
 
 /* @test
- * @bug 4652496
+ * @bug 4652496 8064407 8068507
  * @summary Test transferTo with different target channels
+ * @run main TransferToChannel
+ * @run main/othervm -Djdk.nio.enableFastFileTransfer TransferToChannel
  */
 
 import java.nio.channels.FileChannel;