From c278cc80e9fe9f75d5dcd943b9e3438416bf969f Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Fri, 5 Dec 2014 17:36:18 -0800 Subject: [PATCH 01/12] 8066638: Suppress deprecation warnings in jdk.crypto module 8066641: Suppress deprecation warnings in jdk.naming module Reviewed-by: wetmore, xuelei, valeriep, lancea --- .../share/classes/sun/security/pkcs11/P11Key.java | 3 ++- .../share/classes/sun/security/pkcs11/P11RSACipher.java | 4 +++- .../share/classes/sun/security/pkcs11/P11Signature.java | 2 ++ .../sun/security/pkcs11/P11TlsKeyMaterialGenerator.java | 5 ++++- .../sun/security/pkcs11/P11TlsMasterSecretGenerator.java | 4 +++- .../classes/sun/security/pkcs11/P11TlsPrfGenerator.java | 4 +++- .../security/pkcs11/P11TlsRsaPremasterSecretGenerator.java | 4 +++- .../classes/com/sun/jndi/rmi/registry/RegistryContext.java | 4 +++- 8 files changed, 23 insertions(+), 7 deletions(-) diff --git a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11Key.java b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11Key.java index 235c1488a44..652bf0cbd92 100644 --- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11Key.java +++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11Key.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -445,6 +445,7 @@ abstract class P11Key implements Key, Length { } } + @SuppressWarnings("deprecation") private static class P11TlsMasterSecretKey extends P11SecretKey implements TlsMasterSecret { private static final long serialVersionUID = -1318560923770573441L; diff --git a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11RSACipher.java b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11RSACipher.java index 253b8913a82..bc65e2f2424 100644 --- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11RSACipher.java +++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11RSACipher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -169,6 +169,7 @@ final class P11RSACipher extends CipherSpi { } // see JCE spec + @SuppressWarnings("deprecation") protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { @@ -461,6 +462,7 @@ final class P11RSACipher extends CipherSpi { } // see JCE spec + @SuppressWarnings("deprecation") protected Key engineUnwrap(byte[] wrappedKey, String algorithm, int type) throws InvalidKeyException, NoSuchAlgorithmException { diff --git a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11Signature.java b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11Signature.java index 1bac22ca62c..e5f498ffc71 100644 --- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11Signature.java +++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11Signature.java @@ -765,12 +765,14 @@ final class P11Signature extends SignatureSpi { } // see JCA spec + @SuppressWarnings("deprecation") protected void engineSetParameter(String param, Object value) throws InvalidParameterException { throw new UnsupportedOperationException("setParameter() not supported"); } // see JCA spec + @SuppressWarnings("deprecation") protected Object engineGetParameter(String param) throws InvalidParameterException { throw new UnsupportedOperationException("getParameter() not supported"); diff --git a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsKeyMaterialGenerator.java b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsKeyMaterialGenerator.java index babebabf008..c054f312c55 100644 --- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsKeyMaterialGenerator.java +++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsKeyMaterialGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -62,6 +62,7 @@ public final class P11TlsKeyMaterialGenerator extends KeyGeneratorSpi { private long mechanism; // parameter spec + @SuppressWarnings("deprecation") private TlsKeyMaterialParameterSpec spec; // master secret as a P11Key @@ -82,6 +83,7 @@ public final class P11TlsKeyMaterialGenerator extends KeyGeneratorSpi { throw new InvalidParameterException(MSG); } + @SuppressWarnings("deprecation") protected void engineInit(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException { if (params instanceof TlsKeyMaterialParameterSpec == false) { @@ -107,6 +109,7 @@ public final class P11TlsKeyMaterialGenerator extends KeyGeneratorSpi { throw new InvalidParameterException(MSG); } + @SuppressWarnings("deprecation") protected SecretKey engineGenerateKey() { if (spec == null) { throw new IllegalStateException diff --git a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsMasterSecretGenerator.java b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsMasterSecretGenerator.java index ef30daf41fc..73a2ac2e890 100644 --- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsMasterSecretGenerator.java +++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsMasterSecretGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -57,6 +57,7 @@ public final class P11TlsMasterSecretGenerator extends KeyGeneratorSpi { // mechanism id private long mechanism; + @SuppressWarnings("deprecation") private TlsMasterSecretParameterSpec spec; private P11Key p11Key; @@ -74,6 +75,7 @@ public final class P11TlsMasterSecretGenerator extends KeyGeneratorSpi { throw new InvalidParameterException(MSG); } + @SuppressWarnings("deprecation") protected void engineInit(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException { if (params instanceof TlsMasterSecretParameterSpec == false) { diff --git a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsPrfGenerator.java b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsPrfGenerator.java index 86bee16a72f..739f66965d4 100644 --- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsPrfGenerator.java +++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsPrfGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -63,6 +63,7 @@ final class P11TlsPrfGenerator extends KeyGeneratorSpi { // mechanism id private final long mechanism; + @SuppressWarnings("deprecation") private TlsPrfParameterSpec spec; private P11Key p11Key; @@ -79,6 +80,7 @@ final class P11TlsPrfGenerator extends KeyGeneratorSpi { throw new InvalidParameterException(MSG); } + @SuppressWarnings("deprecation") protected void engineInit(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException { if (params instanceof TlsPrfParameterSpec == false) { diff --git a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsRsaPremasterSecretGenerator.java b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsRsaPremasterSecretGenerator.java index 21c853794bc..40d3a634ce5 100644 --- a/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsRsaPremasterSecretGenerator.java +++ b/jdk/src/jdk.crypto.pkcs11/share/classes/sun/security/pkcs11/P11TlsRsaPremasterSecretGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -57,6 +57,7 @@ final class P11TlsRsaPremasterSecretGenerator extends KeyGeneratorSpi { // mechanism id private long mechanism; + @SuppressWarnings("deprecation") private TlsRsaPremasterSecretParameterSpec spec; P11TlsRsaPremasterSecretGenerator(Token token, String algorithm, long mechanism) @@ -71,6 +72,7 @@ final class P11TlsRsaPremasterSecretGenerator extends KeyGeneratorSpi { throw new InvalidParameterException(MSG); } + @SuppressWarnings("deprecation") protected void engineInit(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException { if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) { diff --git a/jdk/src/jdk.naming.rmi/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java b/jdk/src/jdk.naming.rmi/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java index a6de4af5cd8..cf3de07fe79 100644 --- a/jdk/src/jdk.naming.rmi/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java +++ b/jdk/src/jdk.naming.rmi/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -353,6 +353,7 @@ public class RegistryContext implements Context, Referenceable { /** * Wrap a RemoteException inside a NamingException. */ + @SuppressWarnings("deprecation") public static NamingException wrapRemoteException(RemoteException re) { NamingException ne; @@ -413,6 +414,7 @@ public class RegistryContext implements Context, Referenceable { * Attempts to install a security manager if none is currently in * place. */ + @SuppressWarnings("deprecation") private static void installSecurityMgr() { try { From 9eafb6c406bc3f4d68ef116e69029898d0f56cca Mon Sep 17 00:00:00 2001 From: Kirk Shoop Date: Sun, 7 Dec 2014 07:10:29 +0000 Subject: [PATCH 02/12] 8064407: (fc) FileChannel transferTo should use TransmitFile on Windows Co-authored-by: Valeriy Kopylov Reviewed-by: alanb --- .../classes/sun/nio/ch/FileChannelImpl.java | 81 +++++++++++++------ .../classes/sun/nio/ch/FileDispatcher.java | 8 +- .../sun/nio/ch/FileDispatcherImpl.java | 14 +++- .../unix/native/libnio/ch/FileChannelImpl.c | 7 +- .../sun/nio/ch/FileDispatcherImpl.java | 46 +++++++++-- .../native/libnio/ch/FileChannelImpl.c | 43 +++++++++- .../FileChannel/TransferToChannel.java | 2 + 7 files changed, 160 insertions(+), 41 deletions(-) diff --git a/jdk/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java b/jdk/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java index 2c3102feadd..8f18d44d63e 100644 --- a/jdk/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java +++ b/jdk/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java @@ -38,6 +38,7 @@ import java.nio.channels.NonReadableChannelException; import java.nio.channels.NonWritableChannelException; import java.nio.channels.OverlappingFileLockException; import java.nio.channels.ReadableByteChannel; +import java.nio.channels.SelectableChannel; import java.nio.channels.WritableByteChannel; import java.security.AccessController; import java.util.ArrayList; @@ -404,30 +405,13 @@ public class FileChannelImpl // 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; @@ -437,7 +421,7 @@ public class FileChannelImpl 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) @@ -458,6 +442,54 @@ public class FileChannelImpl } } + 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; @@ -1173,7 +1205,8 @@ public class FileChannelImpl 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 diff --git a/jdk/src/java.base/share/classes/sun/nio/ch/FileDispatcher.java b/jdk/src/java.base/share/classes/sun/nio/ch/FileDispatcher.java index 6e5df225080..5e9f82fc037 100644 --- a/jdk/src/java.base/share/classes/sun/nio/ch/FileDispatcher.java +++ b/jdk/src/java.base/share/classes/sun/nio/ch/FileDispatcher.java @@ -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 class FileDispatcher extends NativeDispatcher { */ abstract FileDescriptor duplicateForMapping(FileDescriptor fd) throws IOException; + + abstract boolean canTransferToDirectly(SelectableChannel sc); + + abstract boolean transferToDirectlyNeedsPositionLock(); } diff --git a/jdk/src/java.base/unix/classes/sun/nio/ch/FileDispatcherImpl.java b/jdk/src/java.base/unix/classes/sun/nio/ch/FileDispatcherImpl.java index c6c85f7fac9..9d960e2d2e0 100644 --- a/jdk/src/java.base/unix/classes/sun/nio/ch/FileDispatcherImpl.java +++ b/jdk/src/java.base/unix/classes/sun/nio/ch/FileDispatcherImpl.java @@ -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 { IOUtil.load(); @@ -104,6 +104,14 @@ class FileDispatcherImpl extends FileDispatcher 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) diff --git a/jdk/src/java.base/unix/native/libnio/ch/FileChannelImpl.c b/jdk/src/java.base/unix/native/libnio/ch/FileChannelImpl.c index 895289067d6..d8face71c37 100644 --- a/jdk/src/java.base/unix/native/libnio/ch/FileChannelImpl.c +++ b/jdk/src/java.base/unix/native/libnio/ch/FileChannelImpl.c @@ -154,10 +154,13 @@ Java_sun_nio_ch_FileChannelImpl_close0(JNIEnv *env, jobject this, jobject fdo) 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); diff --git a/jdk/src/java.base/windows/classes/sun/nio/ch/FileDispatcherImpl.java b/jdk/src/java.base/windows/classes/sun/nio/ch/FileDispatcherImpl.java index 19997d0c1ec..c767a34cc08 100644 --- a/jdk/src/java.base/windows/classes/sun/nio/ch/FileDispatcherImpl.java +++ b/jdk/src/java.base/windows/classes/sun/nio/ch/FileDispatcherImpl.java @@ -25,21 +25,21 @@ 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 -{ +class FileDispatcherImpl extends FileDispatcher { + private static final JavaIOFileDescriptorAccess fdAccess = SharedSecrets.getJavaIOFileDescriptorAccess(); - static { - IOUtil.load(); - } + // set to true if fast file transmission (TransmitFile) is enabled + private static final boolean fastFileTransfer; - FileDispatcherImpl() { - } + FileDispatcherImpl() { } @Override boolean needsPositionLock() { @@ -110,6 +110,36 @@ class FileDispatcherImpl extends FileDispatcher 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() { + @Override + public String run() { + return System.getProperty("jdk.net.enableFastFileTransfer"); + } + }); + boolean enable; + if ("".equals(fileTransferProp)) { + enable = true; + } else { + enable = Boolean.parseBoolean(fileTransferProp); + } + return enable; + } + + static { + IOUtil.load(); + fastFileTransfer = isFastFileTransferRequested(); + } + //-- Native methods static native int read0(FileDescriptor fd, long address, int len) diff --git a/jdk/src/java.base/windows/native/libnio/ch/FileChannelImpl.c b/jdk/src/java.base/windows/native/libnio/ch/FileChannelImpl.c index 0c03958aa33..2e0a6ca0fd9 100644 --- a/jdk/src/java.base/windows/native/libnio/ch/FileChannelImpl.c +++ b/jdk/src/java.base/windows/native/libnio/ch/FileChannelImpl.c @@ -31,6 +31,10 @@ #include "nio.h" #include "nio_util.h" #include "sun_nio_ch_FileChannelImpl.h" +#include "java_lang_Integer.h" + +#include +#pragma comment(lib, "Mswsock.lib") static jfieldID chan_fd; /* id for jobject 'fd' in java.io.FileChannel */ @@ -175,9 +179,42 @@ Java_sun_nio_ch_FileChannelImpl_close0(JNIEnv *env, jobject this, jobject fdo) 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; } diff --git a/jdk/test/java/nio/channels/FileChannel/TransferToChannel.java b/jdk/test/java/nio/channels/FileChannel/TransferToChannel.java index 05069d296dc..2aa1b4bd2cc 100644 --- a/jdk/test/java/nio/channels/FileChannel/TransferToChannel.java +++ b/jdk/test/java/nio/channels/FileChannel/TransferToChannel.java @@ -24,6 +24,8 @@ /* @test * @bug 4652496 * @summary Test transferTo with different target channels + * @run main TransferToChannel + * @run main/othervm -Djdk.net.enableFastFileTransfer TransferToChannel */ import java.nio.channels.FileChannel; From 918fac5a5270f1761de02d480c701a30b01fec94 Mon Sep 17 00:00:00 2001 From: Neil Toda Date: Mon, 10 Nov 2014 08:43:27 -0800 Subject: [PATCH 03/12] 8058407: Remove Multiple JRE support in the Java launcher Reviewed-by: alanb, darcy, ksrini --- .../macosx/native/libjli/java_md_macosx.c | 7 +- .../java.base/share/native/libjli/emessages.h | 8 +- jdk/src/java.base/share/native/libjli/java.c | 143 ++---- jdk/src/java.base/share/native/libjli/java.h | 4 +- .../share/native/libjli/parse_manifest.c | 17 +- .../share/native/libjli/version_comp.c | 357 --------------- .../share/native/libjli/version_comp.h | 37 -- .../java.base/unix/native/libjli/java_md.h | 7 +- .../unix/native/libjli/java_md_common.c | 196 +------- .../unix/native/libjli/java_md_solinux.c | 7 +- .../java.base/windows/native/libjli/java_md.c | 417 +----------------- .../java.base/windows/native/libjli/java_md.h | 5 +- jdk/test/tools/launcher/Arrrghs.java | 19 +- jdk/test/tools/launcher/MultipleJRE.sh | 227 +++++----- 14 files changed, 156 insertions(+), 1295 deletions(-) delete mode 100644 jdk/src/java.base/share/native/libjli/version_comp.c delete mode 100644 jdk/src/java.base/share/native/libjli/version_comp.h diff --git a/jdk/src/java.base/macosx/native/libjli/java_md_macosx.c b/jdk/src/java.base/macosx/native/libjli/java_md_macosx.c index 4fa1e4b2855..802d8742dee 100644 --- a/jdk/src/java.base/macosx/native/libjli/java_md_macosx.c +++ b/jdk/src/java.base/macosx/native/libjli/java_md_macosx.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 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 @@ -38,7 +38,6 @@ #include #include "manifest_info.h" -#include "version_comp.h" /* Support Cocoa event loop on the main thread */ #include @@ -104,10 +103,6 @@ struct NSAppArgs { * (incoming argv) * | * \|/ - * SelectVersion - * (selects the JRE version, note: not data model) - * | - * \|/ * CreateExecutionEnvironment * (determines desired data model) * | diff --git a/jdk/src/java.base/share/native/libjli/emessages.h b/jdk/src/java.base/share/native/libjli/emessages.h index e390c71b49b..961ff7be3f7 100644 --- a/jdk/src/java.base/share/native/libjli/emessages.h +++ b/jdk/src/java.base/share/native/libjli/emessages.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -72,9 +72,6 @@ #define CFG_ERROR8 "Error: missing `%s' JVM at `%s'.\nPlease install or use the JRE or JDK that contains these missing components." #define CFG_ERROR9 "Error: could not determine JVM type." - -#define SPC_ERROR1 "Error: Syntax error in version specification \"%s\"" - #define JRE_ERROR1 "Error: Could not find Java SE Runtime Environment." #define JRE_ERROR2 "Error: This Java instance does not support a %d-bit JVM.\nPlease install the desired version." #define JRE_ERROR3 "Error: Improper value at line %d." @@ -89,6 +86,9 @@ #define JRE_ERROR12 "Error: Exec of %s failed" #define JRE_ERROR13 "Error: String processing operation failed" +#define SPC_ERROR1 "Error: Specifying an alternate JDK/JRE version is no longer supported.\n The use of the flag '-version:' is no longer valid.\n Please download and execute the appropriate version." +#define SPC_ERROR2 "Error: Specifying an alternate JDK/JRE is no longer supported.\n The related flags -jre-restrict-search | -jre-no-restrict-search are also no longer valid." + #define DLL_ERROR1 "Error: dl failure on line %d" #define DLL_ERROR2 "Error: failed %s, because %s" #define DLL_ERROR3 "Error: could not find executable %s" diff --git a/jdk/src/java.base/share/native/libjli/java.c b/jdk/src/java.base/share/native/libjli/java.c index c71f4c26fab..becd6cbf749 100644 --- a/jdk/src/java.base/share/native/libjli/java.c +++ b/jdk/src/java.base/share/native/libjli/java.c @@ -216,21 +216,14 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */ } /* - * Make sure the specified version of the JRE is running. + * SelectVersion() has several responsibilities: * - * There are three things to note about the SelectVersion() routine: - * 1) If the version running isn't correct, this routine doesn't - * return (either the correct version has been exec'd or an error - * was issued). - * 2) Argc and Argv in this scope are *not* altered by this routine. - * It is the responsibility of subsequent code to ignore the - * arguments handled by this routine. - * 3) As a side-effect, the variable "main_class" is guaranteed to - * be set (if it should ever be set). This isn't exactly the - * poster child for structured programming, but it is a small - * price to pay for not processing a jar file operand twice. - * (Note: This side effect has been disabled. See comment on - * bugid 5030265 below.) + * 1) Disallow specification of another JRE. With 1.9, another + * version of the JRE cannot be invoked. + * 2) Allow for a JRE version to invoke JDK 1.9 or later. Since + * all mJRE directives have been stripped from the request but + * the pre 1.9 JRE [ 1.6 thru 1.8 ], it is as if 1.9+ has been + * invoked from the command line. */ SelectVersion(argc, argv, &main_class); @@ -829,8 +822,6 @@ static void SelectVersion(int argc, char **argv, char **main_class) { char *arg; - char **new_argv; - char **new_argp; char *operand; char *version = NULL; char *jre = NULL; @@ -849,6 +840,17 @@ SelectVersion(int argc, char **argv, char **main_class) * with the value passed through the environment (if any) and * simply return. */ + + /* + * This environmental variable can be set by mJRE capable JREs + * [ 1.5 thru 1.8 ]. All other aspects of mJRE processing have been + * stripped by those JREs. This environmental variable allows 1.9+ + * JREs to be started by these mJRE capable JREs. + * Note that mJRE directives in the jar manifest file would have been + * ignored for a JRE started by another JRE... + * .. skipped for JRE 1.5 and beyond. + * .. not even checked for pre 1.5. + */ if ((env_in = getenv(ENV_ENTRY)) != NULL) { if (*env_in != '\0') *main_class = JLI_StringDup(env_in); @@ -857,41 +859,26 @@ SelectVersion(int argc, char **argv, char **main_class) /* * Scan through the arguments for options relevant to multiple JRE - * support. For reference, the command line syntax is defined as: + * support. Multiple JRE support existed in JRE versions 1.5 thru 1.8. * - * SYNOPSIS - * java [options] class [argument...] - * - * java [options] -jar file.jar [argument...] - * - * As the scan is performed, make a copy of the argument list with - * the version specification options (new to 1.5) removed, so that - * a version less than 1.5 can be exec'd. - * - * Note that due to the syntax of the native Windows interface - * CreateProcess(), processing similar to the following exists in - * the Windows platform specific routine ExecJRE (in java_md.c). - * Changes here should be reproduced there. + * This capability is no longer available with JRE versions 1.9 and later. + * These command line options are reported as errors. */ - new_argv = JLI_MemAlloc((argc + 1) * sizeof(char*)); - new_argv[0] = argv[0]; - new_argp = &new_argv[1]; argc--; argv++; while ((arg = *argv) != 0 && *arg == '-') { if (JLI_StrCCmp(arg, "-version:") == 0) { - version = arg + 9; + JLI_ReportErrorMessage(SPC_ERROR1); } else if (JLI_StrCmp(arg, "-jre-restrict-search") == 0) { - restrict_search = 1; - } else if (JLI_StrCmp(arg, "-no-jre-restrict-search") == 0) { - restrict_search = 0; + JLI_ReportErrorMessage(SPC_ERROR2); + } else if (JLI_StrCmp(arg, "-jre-no-restrict-search") == 0) { + JLI_ReportErrorMessage(SPC_ERROR2); } else { if (JLI_StrCmp(arg, "-jar") == 0) jarflag = 1; /* deal with "unfortunate" classpath syntax */ if ((JLI_StrCmp(arg, "-classpath") == 0 || JLI_StrCmp(arg, "-cp") == 0) && (argc >= 2)) { - *new_argp++ = arg; argc--; argv++; arg = *argv; @@ -908,7 +895,6 @@ SelectVersion(int argc, char **argv, char **main_class) } else if (JLI_StrCCmp(arg, "-splash:") == 0) { splash_file_name = arg+8; } - *new_argp++ = arg; } argc--; argv++; @@ -917,11 +903,8 @@ SelectVersion(int argc, char **argv, char **main_class) operand = NULL; } else { argc--; - *new_argp++ = operand = *argv++; + operand = *argv++; } - while (argc-- > 0) /* Copy over [argument...] */ - *new_argp++ = *argv++; - *new_argp = NULL; /* * If there is a jar file, read the manifest. If the jarfile can't be @@ -974,14 +957,6 @@ SelectVersion(int argc, char **argv, char **main_class) putenv(splash_jar_entry); } - /* - * The JRE-Version and JRE-Restrict-Search values (if any) from the - * manifest are overwritten by any specified on the command line. - */ - if (version != NULL) - info.jre_version = version; - if (restrict_search != -1) - info.jre_restrict_search = restrict_search; /* * "Valid" returns (other than unrecoverable errors) follow. Set @@ -990,72 +965,11 @@ SelectVersion(int argc, char **argv, char **main_class) if (info.main_class != NULL) *main_class = JLI_StringDup(info.main_class); - /* - * If no version selection information is found either on the command - * line or in the manifest, simply return. - */ if (info.jre_version == NULL) { JLI_FreeManifest(); - JLI_MemFree(new_argv); return; } - /* - * Check for correct syntax of the version specification (JSR 56). - */ - if (!JLI_ValidVersionString(info.jre_version)) { - JLI_ReportErrorMessage(SPC_ERROR1, info.jre_version); - exit(1); - } - - /* - * Find the appropriate JVM on the system. Just to be as forgiving as - * possible, if the standard algorithms don't locate an appropriate - * jre, check to see if the one running will satisfy the requirements. - * This can happen on systems which haven't been set-up for multiple - * JRE support. - */ - jre = LocateJRE(&info); - JLI_TraceLauncher("JRE-Version = %s, JRE-Restrict-Search = %s Selected = %s\n", - (info.jre_version?info.jre_version:"null"), - (info.jre_restrict_search?"true":"false"), (jre?jre:"null")); - - if (jre == NULL) { - if (JLI_AcceptableRelease(GetFullVersion(), info.jre_version)) { - JLI_FreeManifest(); - JLI_MemFree(new_argv); - return; - } else { - JLI_ReportErrorMessage(CFG_ERROR4, info.jre_version); - exit(1); - } - } - - /* - * If I'm not the chosen one, exec the chosen one. Returning from - * ExecJRE indicates that I am indeed the chosen one. - * - * The private environment variable _JAVA_VERSION_SET is used to - * prevent the chosen one from re-reading the manifest file and - * using the values found within to override the (potential) command - * line flags stripped from argv (because the target may not - * understand them). Passing the MainClass value is an optimization - * to avoid locating, expanding and parsing the manifest extra - * times. - */ - if (info.main_class != NULL) { - if (JLI_StrLen(info.main_class) <= MAXNAMELEN) { - (void)JLI_StrCat(env_entry, info.main_class); - } else { - JLI_ReportErrorMessage(CLS_ERROR5, MAXNAMELEN); - exit(1); - } - } - (void)putenv(env_entry); - ExecJRE(jre, new_argv); - JLI_FreeManifest(); - JLI_MemFree(new_argv); - return; } /* @@ -1154,10 +1068,7 @@ ParseArguments(int *pargc, char ***pargv, JLI_StrCmp(arg, "-noasyncgc") == 0) { /* No longer supported */ JLI_ReportErrorMessage(ARG_WARN, arg); - } else if (JLI_StrCCmp(arg, "-version:") == 0 || - JLI_StrCmp(arg, "-no-jre-restrict-search") == 0 || - JLI_StrCmp(arg, "-jre-restrict-search") == 0 || - JLI_StrCCmp(arg, "-splash:") == 0) { + } else if (JLI_StrCCmp(arg, "-splash:") == 0) { ; /* Ignore machine independent options already handled */ } else if (ProcessPlatformOption(arg)) { ; /* Processing of platform dependent options */ diff --git a/jdk/src/java.base/share/native/libjli/java.h b/jdk/src/java.base/share/native/libjli/java.h index 83e97e60d9c..615b16cd9c3 100644 --- a/jdk/src/java.base/share/native/libjli/java.h +++ b/jdk/src/java.base/share/native/libjli/java.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -40,9 +40,7 @@ #include "emessages.h" #include "java_md.h" #include "jli_util.h" - #include "manifest_info.h" -#include "version_comp.h" #include "wildcard.h" #include "splashscreen.h" diff --git a/jdk/src/java.base/share/native/libjli/parse_manifest.c b/jdk/src/java.base/share/native/libjli/parse_manifest.c index c17249c0b30..a8e17b89b25 100644 --- a/jdk/src/java.base/share/native/libjli/parse_manifest.c +++ b/jdk/src/java.base/share/native/libjli/parse_manifest.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -588,15 +588,16 @@ JLI_ParseManifest(char *jarfile, manifest_info *info) } lp = manifest; while ((rc = parse_nv_pair(&lp, &name, &value)) > 0) { - if (JLI_StrCaseCmp(name, "Manifest-Version") == 0) + if (JLI_StrCaseCmp(name, "Manifest-Version") == 0) { info->manifest_version = value; - else if (JLI_StrCaseCmp(name, "Main-Class") == 0) + } else if (JLI_StrCaseCmp(name, "Main-Class") == 0) { info->main_class = value; - else if (JLI_StrCaseCmp(name, "JRE-Version") == 0) - info->jre_version = value; - else if (JLI_StrCaseCmp(name, "JRE-Restrict-Search") == 0) { - if (JLI_StrCaseCmp(value, "true") == 0) - info->jre_restrict_search = 1; + } else if (JLI_StrCaseCmp(name, "JRE-Version") == 0) { + /* + * Manifest specification overridden by command line option + * so we will silently override there with no specification. + */ + info->jre_version = 0; } else if (JLI_StrCaseCmp(name, "Splashscreen-Image") == 0) { info->splashscreen_image_file_name = value; } diff --git a/jdk/src/java.base/share/native/libjli/version_comp.c b/jdk/src/java.base/share/native/libjli/version_comp.c deleted file mode 100644 index fc20ba94e9a..00000000000 --- a/jdk/src/java.base/share/native/libjli/version_comp.c +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (c) 2003, 2006, 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. - */ - -#include -#include -#include -#include -#include "jni.h" -#include "jli_util.h" -#include "version_comp.h" - -/* - * A collection of useful strings. One should think of these as #define - * entries, but actual strings can be more efficient (with many compilers). - */ -static const char *separators = ".-_"; -static const char *zero_string = "0"; - -/* - * Validate a string as parsable as a "Java int". If so parsable, - * return true (non-zero) and store the numeric value at the address - * passed in as "value"; otherwise return false (zero). - * - * Note that the maximum allowable value is 2147483647 as defined by - * the "Java Language Specification" which precludes the use of native - * conversion routines which may have other limits. - * - * Also note that we don't have to worry about the alternate maximum - * allowable value of 2147483648 because it is only allowed after - * the unary negation operator and this grammar doesn't have one - * of those. - * - * Finally, note that a value which exceeds the maximum jint value will - * return false (zero). This results in the otherwise purely numeric - * string being compared as a string of characters (as per the spec.) - */ -static int -isjavaint(const char *s, jint *value) -{ - jlong sum = 0; - jint digit; - while (*s != '\0') - if (isdigit(*s)) { - digit = (jint)((int)(*s++) - (int)('0')); - sum = (sum * 10) + digit; - if (sum > 2147483647) - return (0); /* Overflows jint (but not jlong) */ - } else - return (0); - *value = (jint)sum; - return (1); -} - -/* - * Modeled after strcmp(), compare two strings (as in the grammar defined - * in Appendix A of JSR 56). If both strings can be interpreted as - * Java ints, do a numeric comparison, else it is strcmp(). - */ -static int -comp_string(const char *s1, const char *s2) -{ - jint v1, v2; - if (isjavaint(s1, &v1) && isjavaint(s2, &v2)) - return ((int)(v1 - v2)); - else - return (JLI_StrCmp(s1, s2)); -} - -/* - * Modeled after strcmp(), compare two version-ids for a Prefix - * Match as defined in JSR 56. - */ -int -JLI_PrefixVersionId(const char *id1, char *id2) -{ - char *s1 = JLI_StringDup(id1); - char *s2 = JLI_StringDup(id2); - char *m1 = s1; - char *m2 = s2; - char *end1 = NULL; - char *end2 = NULL; - int res = 0; - - do { - - if ((s1 != NULL) && ((end1 = JLI_StrPBrk(s1, ".-_")) != NULL)) - *end1 = '\0'; - if ((s2 != NULL) && ((end2 = JLI_StrPBrk(s2, ".-_")) != NULL)) - *end2 = '\0'; - - res = comp_string(s1, s2); - - if (end1 != NULL) - s1 = end1 + 1; - else - s1 = NULL; - if (end2 != NULL) - s2 = end2 + 1; - else - s2 = NULL; - - } while (res == 0 && ((s1 != NULL) && (s2 != NULL))); - - JLI_MemFree(m1); - JLI_MemFree(m2); - return (res); -} - -/* - * Modeled after strcmp(), compare two version-ids for an Exact - * Match as defined in JSR 56. - */ -int -JLI_ExactVersionId(const char *id1, char *id2) -{ - char *s1 = JLI_StringDup(id1); - char *s2 = JLI_StringDup(id2); - char *m1 = s1; - char *m2 = s2; - char *end1 = NULL; - char *end2 = NULL; - int res = 0; - - do { - - if ((s1 != NULL) && ((end1 = JLI_StrPBrk(s1, separators)) != NULL)) - *end1 = '\0'; - if ((s2 != NULL) && ((end2 = JLI_StrPBrk(s2, separators)) != NULL)) - *end2 = '\0'; - - if ((s1 != NULL) && (s2 == NULL)) - res = comp_string(s1, zero_string); - else if ((s1 == NULL) && (s2 != NULL)) - res = comp_string(zero_string, s2); - else - res = comp_string(s1, s2); - - if (end1 != NULL) - s1 = end1 + 1; - else - s1 = NULL; - if (end2 != NULL) - s2 = end2 + 1; - else - s2 = NULL; - - } while (res == 0 && ((s1 != NULL) || (s2 != NULL))); - - JLI_MemFree(m1); - JLI_MemFree(m2); - return (res); -} - -/* - * Return true if this simple-element (as defined in JSR 56) forms - * an acceptable match. - * - * JSR 56 is modified by the Java Web Start Developer Guide - * where it is stated "... Java Web Start will not consider an installed - * non-FCS (i.e., milestone) JRE as a match. ... a JRE from Sun - * Microsystems, Inc., is by convention a non-FCS (milestone) JRE - * if there is a dash (-) in the version string." - * - * An undocumented caveat to the above is that an exact match with a - * hyphen is accepted as a development extension. - * - * These modifications are addressed by the specific comparisons - * for releases with hyphens. - */ -static int -acceptable_simple_element(const char *release, char *simple_element) -{ - char *modifier; - modifier = simple_element + JLI_StrLen(simple_element) - 1; - if (*modifier == '*') { - *modifier = '\0'; - if (JLI_StrChr(release, '-')) - return ((JLI_StrCmp(release, simple_element) == 0)?1:0); - return ((JLI_PrefixVersionId(release, simple_element) == 0)?1:0); - } else if (*modifier == '+') { - *modifier = '\0'; - if (JLI_StrChr(release, '-')) - return ((JLI_StrCmp(release, simple_element) == 0)?1:0); - return ((JLI_ExactVersionId(release, simple_element) >= 0)?1:0); - } else { - return ((JLI_ExactVersionId(release, simple_element) == 0)?1:0); - } -} - -/* - * Return true if this element (as defined in JSR 56) forms - * an acceptable match. An element is the intersection (and) - * of multiple simple-elements. - */ -static int -acceptable_element(const char *release, char *element) -{ - char *end; - do { - if ((end = JLI_StrChr(element, '&')) != NULL) - *end = '\0'; - if (!acceptable_simple_element(release, element)) - return (0); - if (end != NULL) - element = end + 1; - } while (end != NULL); - return (1); -} - -/* - * Checks if release is acceptable by the specification version-string. - * Return true if this version-string (as defined in JSR 56) forms - * an acceptable match. A version-string is the union (or) of multiple - * elements. - */ -int -JLI_AcceptableRelease(const char *release, char *version_string) -{ - char *vs; - char *m1; - char *end; - m1 = vs = JLI_StringDup(version_string); - do { - if ((end = JLI_StrChr(vs, ' ')) != NULL) - *end = '\0'; - if (acceptable_element(release, vs)) { - JLI_MemFree(m1); - return (1); - } - if (end != NULL) - vs = end + 1; - } while (end != NULL); - JLI_MemFree(m1); - return (0); -} - -/* - * Return true if this is a valid simple-element (as defined in JSR 56). - * - * The official grammar for a simple-element is: - * - * simple-element ::= version-id | version-id modifier - * modifier ::= '+' | '*' - * version-id ::= string ( separator string )* - * string ::= char ( char )* - * char ::= Any ASCII character except a space, an - * ampersand, a separator or a modifier - * separator ::= '.' | '-' | '_' - * - * However, for efficiency, it is time to abandon the top down parser - * implementation. After deleting the potential trailing modifier, we - * are left with a version-id. - * - * Note that a valid version-id has three simple properties: - * - * 1) Doesn't contain a space, an ampersand or a modifier. - * - * 2) Doesn't begin or end with a separator. - * - * 3) Doesn't contain two adjacent separators. - * - * Any other line noise constitutes a valid version-id. - */ -static int -valid_simple_element(char *simple_element) -{ - char *last; - size_t len; - - if ((simple_element == NULL) || ((len = JLI_StrLen(simple_element)) == 0)) - return (0); - last = simple_element + len - 1; - if (*last == '*' || *last == '+') { - if (--len == 0) - return (0); - *last-- = '\0'; - } - if (JLI_StrPBrk(simple_element, " &+*") != NULL) /* Property #1 */ - return (0); - if ((JLI_StrChr(".-_", *simple_element) != NULL) || /* Property #2 */ - (JLI_StrChr(".-_", *last) != NULL)) - return (0); - for (; simple_element != last; simple_element++) /* Property #3 */ - if ((JLI_StrChr(".-_", *simple_element) != NULL) && - (JLI_StrChr(".-_", *(simple_element + 1)) != NULL)) - return (0); - return (1); -} - -/* - * Return true if this is a valid element (as defined in JSR 56). - * An element is the intersection (and) of multiple simple-elements. - */ -static int -valid_element(char *element) -{ - char *end; - if ((element == NULL) || (JLI_StrLen(element) == 0)) - return (0); - do { - if ((end = JLI_StrChr(element, '&')) != NULL) - *end = '\0'; - if (!valid_simple_element(element)) - return (0); - if (end != NULL) - element = end + 1; - } while (end != NULL); - return (1); -} - -/* - * Validates a version string by the extended JSR 56 grammar. - */ -int -JLI_ValidVersionString(char *version_string) -{ - char *vs; - char *m1; - char *end; - if ((version_string == NULL) || (JLI_StrLen(version_string) == 0)) - return (0); - m1 = vs = JLI_StringDup(version_string); - do { - if ((end = JLI_StrChr(vs, ' ')) != NULL) - *end = '\0'; - if (!valid_element(vs)) { - JLI_MemFree(m1); - return (0); - } - if (end != NULL) - vs = end + 1; - } while (end != NULL); - JLI_MemFree(m1); - return (1); -} diff --git a/jdk/src/java.base/share/native/libjli/version_comp.h b/jdk/src/java.base/share/native/libjli/version_comp.h deleted file mode 100644 index 397e831b7d5..00000000000 --- a/jdk/src/java.base/share/native/libjli/version_comp.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2003, 2005, 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 _VERSION_COMP_H -#define _VERSION_COMP_H - -/* - * Function prototypes. - */ -int JLI_ExactVersionId(const char *id1, char *id2); -int JLI_PrefixVersionId(const char *id1, char *id2); -int JLI_AcceptableRelease(const char *release, char *version_string); -int JLI_ValidVersionString(char *version_string); - -#endif /* _VERSION_COMP_H */ diff --git a/jdk/src/java.base/unix/native/libjli/java_md.h b/jdk/src/java.base/unix/native/libjli/java_md.h index ec0615c1320..212ae0a2732 100644 --- a/jdk/src/java.base/unix/native/libjli/java_md.h +++ b/jdk/src/java.base/unix/native/libjli/java_md.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -43,11 +43,6 @@ #define MAXNAMELEN PATH_MAX #endif -/* - * Common function prototypes and sundries. - */ -char *LocateJRE(manifest_info *info); -void ExecJRE(char *jre, char **argv); int UnsetEnv(char *name); char *FindExecName(char *program); const char *SetExecname(char **argv); diff --git a/jdk/src/java.base/unix/native/libjli/java_md_common.c b/jdk/src/java.base/unix/native/libjli/java_md_common.c index fb446db739a..27d5a2ddcaa 100644 --- a/jdk/src/java.base/unix/native/libjli/java_md_common.c +++ b/jdk/src/java.base/unix/native/libjli/java_md_common.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 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 @@ -190,200 +190,6 @@ CheckSanity(char *path, char *dir) return ((access(buffer, X_OK) == 0) ? 1 : 0); } -/* - * Determine if there is an acceptable JRE in the directory dirname. - * Upon locating the "best" one, return a fully qualified path to - * it. "Best" is defined as the most advanced JRE meeting the - * constraints contained in the manifest_info. If no JRE in this - * directory meets the constraints, return NULL. - * - * Note that we don't check for errors in reading the directory - * (which would be done by checking errno). This is because it - * doesn't matter if we get an error reading the directory, or - * we just don't find anything interesting in the directory. We - * just return NULL in either case. - * - * The historical names of j2sdk and j2re were changed to jdk and - * jre respecively as part of the 1.5 rebranding effort. Since the - * former names are legacy on Linux, they must be recognized for - * all time. Fortunately, this is a minor cost. - */ -static char -*ProcessDir(manifest_info *info, char *dirname) -{ - DIR *dirp; - struct dirent *dp; - char *best = NULL; - int offset; - int best_offset = 0; - char *ret_str = NULL; - char buffer[PATH_MAX]; - - if ((dirp = opendir(dirname)) == NULL) - return (NULL); - - do { - if ((dp = readdir(dirp)) != NULL) { - offset = 0; - if ((JLI_StrNCmp(dp->d_name, "jre", 3) == 0) || - (JLI_StrNCmp(dp->d_name, "jdk", 3) == 0)) - offset = 3; - else if (JLI_StrNCmp(dp->d_name, "j2re", 4) == 0) - offset = 4; - else if (JLI_StrNCmp(dp->d_name, "j2sdk", 5) == 0) - offset = 5; - if (offset > 0) { - if ((JLI_AcceptableRelease(dp->d_name + offset, - info->jre_version)) && CheckSanity(dirname, dp->d_name)) - if ((best == NULL) || (JLI_ExactVersionId( - dp->d_name + offset, best + best_offset) > 0)) { - if (best != NULL) - JLI_MemFree(best); - best = JLI_StringDup(dp->d_name); - best_offset = offset; - } - } - } - } while (dp != NULL); - (void) closedir(dirp); - if (best == NULL) - return (NULL); - else { - ret_str = JLI_MemAlloc(JLI_StrLen(dirname) + JLI_StrLen(best) + 2); - sprintf(ret_str, "%s/%s", dirname, best); - JLI_MemFree(best); - return (ret_str); - } -} - -/* - * This is the global entry point. It examines the host for the optimal - * JRE to be used by scanning a set of directories. The set of directories - * is platform dependent and can be overridden by the environment - * variable JAVA_VERSION_PATH. - * - * This routine itself simply determines the set of appropriate - * directories before passing control onto ProcessDir(). - */ -char* -LocateJRE(manifest_info* info) -{ - char *path; - char *home; - char *target = NULL; - char *dp; - char *cp; - - /* - * Start by getting JAVA_VERSION_PATH - */ - if (info->jre_restrict_search) { - path = JLI_StringDup(system_dir); - } else if ((path = getenv("JAVA_VERSION_PATH")) != NULL) { - path = JLI_StringDup(path); - } else { - if ((home = getenv("HOME")) != NULL) { - path = (char *)JLI_MemAlloc(JLI_StrLen(home) + \ - JLI_StrLen(system_dir) + JLI_StrLen(user_dir) + 2); - sprintf(path, "%s%s:%s", home, user_dir, system_dir); - } else { - path = JLI_StringDup(system_dir); - } - } - - /* - * Step through each directory on the path. Terminate the scan with - * the first directory with an acceptable JRE. - */ - cp = dp = path; - while (dp != NULL) { - cp = JLI_StrChr(dp, (int)':'); - if (cp != NULL) - *cp = '\0'; - if ((target = ProcessDir(info, dp)) != NULL) - break; - dp = cp; - if (dp != NULL) - dp++; - } - JLI_MemFree(path); - return (target); -} - -/* - * Given a path to a jre to execute, this routine checks if this process - * is indeed that jre. If not, it exec's that jre. - * - * We want to actually check the paths rather than just the version string - * built into the executable, so that given version specification (and - * JAVA_VERSION_PATH) will yield the exact same Java environment, regardless - * of the version of the arbitrary launcher we start with. - */ -void -ExecJRE(char *jre, char **argv) -{ - char wanted[PATH_MAX]; - const char* progname = GetProgramName(); - const char* execname = NULL; - - /* - * Resolve the real path to the directory containing the selected JRE. - */ - if (realpath(jre, wanted) == NULL) { - JLI_ReportErrorMessage(JRE_ERROR9, jre); - exit(1); - } - - /* - * Resolve the real path to the currently running launcher. - */ - SetExecname(argv); - execname = GetExecName(); - if (execname == NULL) { - JLI_ReportErrorMessage(JRE_ERROR10); - exit(1); - } - - /* - * If the path to the selected JRE directory is a match to the initial - * portion of the path to the currently executing JRE, we have a winner! - * If so, just return. - */ - if (JLI_StrNCmp(wanted, execname, JLI_StrLen(wanted)) == 0) - return; /* I am the droid you were looking for */ - - - /* - * This should never happen (because of the selection code in SelectJRE), - * but check for "impossibly" long path names just because buffer overruns - * can be so deadly. - */ - if (JLI_StrLen(wanted) + JLI_StrLen(progname) + 6 > PATH_MAX) { - JLI_ReportErrorMessage(JRE_ERROR11); - exit(1); - } - - /* - * Construct the path and exec it. - */ - (void)JLI_StrCat(JLI_StrCat(wanted, "/bin/"), progname); - argv[0] = JLI_StringDup(progname); - if (JLI_IsTraceLauncher()) { - int i; - printf("ReExec Command: %s (%s)\n", wanted, argv[0]); - printf("ReExec Args:"); - for (i = 1; argv[i] != NULL; i++) - printf(" %s", argv[i]); - printf("\n"); - } - JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n"); - (void)fflush(stdout); - (void)fflush(stderr); - execv(wanted, argv); - JLI_ReportErrorMessageSys(JRE_ERROR12, wanted); - exit(1); -} - /* * "Borrowed" from Solaris 10 where the unsetenv() function is being added * to libc thanks to SUSv3 (Standard Unix Specification, version 3). As diff --git a/jdk/src/java.base/unix/native/libjli/java_md_solinux.c b/jdk/src/java.base/unix/native/libjli/java_md_solinux.c index 05f7a4d8112..77a36890a25 100644 --- a/jdk/src/java.base/unix/native/libjli/java_md_solinux.c +++ b/jdk/src/java.base/unix/native/libjli/java_md_solinux.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -36,7 +36,6 @@ #include #include #include "manifest_info.h" -#include "version_comp.h" #define JVM_DLL "libjvm.so" @@ -100,10 +99,6 @@ * (incoming argv) * | * \|/ - * SelectVersion - * (selects the JRE version, note: not data model) - * | - * \|/ * CreateExecutionEnvironment * (determines desired data model) * | diff --git a/jdk/src/java.base/windows/native/libjli/java_md.c b/jdk/src/java.base/windows/native/libjli/java_md.c index 10fe6ce4a65..81b1c263821 100644 --- a/jdk/src/java.base/windows/native/libjli/java_md.c +++ b/jdk/src/java.base/windows/native/libjli/java_md.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -37,7 +37,6 @@ #include #include "java.h" -#include "version_comp.h" #define JVM_DLL "jvm.dll" #define JAVA_DLL "java.dll" @@ -674,420 +673,6 @@ ServerClassMachine() { return (GetErgoPolicy() == ALWAYS_SERVER_CLASS) ? JNI_TRUE : JNI_FALSE; } -/* - * Determine if there is an acceptable JRE in the registry directory top_key. - * Upon locating the "best" one, return a fully qualified path to it. - * "Best" is defined as the most advanced JRE meeting the constraints - * contained in the manifest_info. If no JRE in this directory meets the - * constraints, return NULL. - * - * It doesn't matter if we get an error reading the registry, or we just - * don't find anything interesting in the directory. We just return NULL - * in either case. - */ -static char * -ProcessDir(manifest_info* info, HKEY top_key) { - DWORD index = 0; - HKEY ver_key; - char name[MAXNAMELEN]; - int len; - char *best = NULL; - - /* - * Enumerate "/SOFTWARE/JavaSoft/Java Runtime Environment" - * searching for the best available version. - */ - while (RegEnumKey(top_key, index, name, MAXNAMELEN) == ERROR_SUCCESS) { - index++; - if (JLI_AcceptableRelease(name, info->jre_version)) - if ((best == NULL) || (JLI_ExactVersionId(name, best) > 0)) { - if (best != NULL) - JLI_MemFree(best); - best = JLI_StringDup(name); - } - } - - /* - * Extract "JavaHome" from the "best" registry directory and return - * that path. If no appropriate version was located, or there is an - * error in extracting the "JavaHome" string, return null. - */ - if (best == NULL) - return (NULL); - else { - if (RegOpenKeyEx(top_key, best, 0, KEY_READ, &ver_key) - != ERROR_SUCCESS) { - JLI_MemFree(best); - if (ver_key != NULL) - RegCloseKey(ver_key); - return (NULL); - } - JLI_MemFree(best); - len = MAXNAMELEN; - if (RegQueryValueEx(ver_key, "JavaHome", NULL, NULL, (LPBYTE)name, &len) - != ERROR_SUCCESS) { - if (ver_key != NULL) - RegCloseKey(ver_key); - return (NULL); - } - if (ver_key != NULL) - RegCloseKey(ver_key); - return (JLI_StringDup(name)); - } -} - -/* - * This is the global entry point. It examines the host for the optimal - * JRE to be used by scanning a set of registry entries. This set of entries - * is hardwired on Windows as "Software\JavaSoft\Java Runtime Environment" - * under the set of roots "{ HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE }". - * - * This routine simply opens each of these registry directories before passing - * control onto ProcessDir(). - */ -char * -LocateJRE(manifest_info* info) { - HKEY key = NULL; - char *path; - int key_index; - HKEY root_keys[2] = { HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE }; - - for (key_index = 0; key_index <= 1; key_index++) { - if (RegOpenKeyEx(root_keys[key_index], JRE_KEY, 0, KEY_READ, &key) - == ERROR_SUCCESS) - if ((path = ProcessDir(info, key)) != NULL) { - if (key != NULL) - RegCloseKey(key); - return (path); - } - if (key != NULL) - RegCloseKey(key); - } - return NULL; -} - -/* - * Local helper routine to isolate a single token (option or argument) - * from the command line. - * - * This routine accepts a pointer to a character pointer. The first - * token (as defined by MSDN command-line argument syntax) is isolated - * from that string. - * - * Upon return, the input character pointer pointed to by the parameter s - * is updated to point to the remainding, unscanned, portion of the string, - * or to a null character if the entire string has been consummed. - * - * This function returns a pointer to a null-terminated string which - * contains the isolated first token, or to the null character if no - * token could be isolated. - * - * Note the side effect of modifying the input string s by the insertion - * of a null character, making it two strings. - * - * See "Parsing C Command-Line Arguments" in the MSDN Library for the - * parsing rule details. The rule summary from that specification is: - * - * * Arguments are delimited by white space, which is either a space or a tab. - * - * * A string surrounded by double quotation marks is interpreted as a single - * argument, regardless of white space contained within. A quoted string can - * be embedded in an argument. Note that the caret (^) is not recognized as - * an escape character or delimiter. - * - * * A double quotation mark preceded by a backslash, \", is interpreted as a - * literal double quotation mark ("). - * - * * Backslashes are interpreted literally, unless they immediately precede a - * double quotation mark. - * - * * If an even number of backslashes is followed by a double quotation mark, - * then one backslash (\) is placed in the argv array for every pair of - * backslashes (\\), and the double quotation mark (") is interpreted as a - * string delimiter. - * - * * If an odd number of backslashes is followed by a double quotation mark, - * then one backslash (\) is placed in the argv array for every pair of - * backslashes (\\) and the double quotation mark is interpreted as an - * escape sequence by the remaining backslash, causing a literal double - * quotation mark (") to be placed in argv. - */ -static char* -nextarg(char** s) { - char *p = *s; - char *head; - int slashes = 0; - int inquote = 0; - - /* - * Strip leading whitespace, which MSDN defines as only space or tab. - * (Hence, no locale specific "isspace" here.) - */ - while (*p != (char)0 && (*p == ' ' || *p == '\t')) - p++; - head = p; /* Save the start of the token to return */ - - /* - * Isolate a token from the command line. - */ - while (*p != (char)0 && (inquote || !(*p == ' ' || *p == '\t'))) { - if (*p == '\\' && *(p+1) == '"' && slashes % 2 == 0) - p++; - else if (*p == '"') - inquote = !inquote; - slashes = (*p++ == '\\') ? slashes + 1 : 0; - } - - /* - * If the token isolated isn't already terminated in a "char zero", - * then replace the whitespace character with one and move to the - * next character. - */ - if (*p != (char)0) - *p++ = (char)0; - - /* - * Update the parameter to point to the head of the remaining string - * reflecting the command line and return a pointer to the leading - * token which was isolated from the command line. - */ - *s = p; - return (head); -} - -/* - * Local helper routine to return a string equivalent to the input string - * s, but with quotes removed so the result is a string as would be found - * in argv[]. The returned string should be freed by a call to JLI_MemFree(). - * - * The rules for quoting (and escaped quotes) are: - * - * 1 A double quotation mark preceded by a backslash, \", is interpreted as a - * literal double quotation mark ("). - * - * 2 Backslashes are interpreted literally, unless they immediately precede a - * double quotation mark. - * - * 3 If an even number of backslashes is followed by a double quotation mark, - * then one backslash (\) is placed in the argv array for every pair of - * backslashes (\\), and the double quotation mark (") is interpreted as a - * string delimiter. - * - * 4 If an odd number of backslashes is followed by a double quotation mark, - * then one backslash (\) is placed in the argv array for every pair of - * backslashes (\\) and the double quotation mark is interpreted as an - * escape sequence by the remaining backslash, causing a literal double - * quotation mark (") to be placed in argv. - */ -static char* -unquote(const char *s) { - const char *p = s; /* Pointer to the tail of the original string */ - char *un = (char*)JLI_MemAlloc(JLI_StrLen(s) + 1); /* Ptr to unquoted string */ - char *pun = un; /* Pointer to the tail of the unquoted string */ - - while (*p != '\0') { - if (*p == '"') { - p++; - } else if (*p == '\\') { - const char *q = p + JLI_StrSpn(p,"\\"); - if (*q == '"') - do { - *pun++ = '\\'; - p += 2; - } while (*p == '\\' && p < q); - else - while (p < q) - *pun++ = *p++; - } else { - *pun++ = *p++; - } - } - *pun = '\0'; - return un; -} - -/* - * Given a path to a jre to execute, this routine checks if this process - * is indeed that jre. If not, it exec's that jre. - * - * We want to actually check the paths rather than just the version string - * built into the executable, so that given version specification will yield - * the exact same Java environment, regardless of the version of the arbitrary - * launcher we start with. - */ -void -ExecJRE(char *jre, char **argv) { - jint len; - char path[MAXPATHLEN + 1]; - - const char *progname = GetProgramName(); - - /* - * Resolve the real path to the currently running launcher. - */ - len = GetModuleFileName(NULL, path, MAXPATHLEN + 1); - if (len == 0 || len > MAXPATHLEN) { - JLI_ReportErrorMessageSys(JRE_ERROR9, progname); - exit(1); - } - - JLI_TraceLauncher("ExecJRE: old: %s\n", path); - JLI_TraceLauncher("ExecJRE: new: %s\n", jre); - - /* - * If the path to the selected JRE directory is a match to the initial - * portion of the path to the currently executing JRE, we have a winner! - * If so, just return. - */ - if (JLI_StrNCaseCmp(jre, path, JLI_StrLen(jre)) == 0) - return; /* I am the droid you were looking for */ - - /* - * If this isn't the selected version, exec the selected version. - */ - JLI_Snprintf(path, sizeof(path), "%s\\bin\\%s.exe", jre, progname); - - /* - * Although Windows has an execv() entrypoint, it doesn't actually - * overlay a process: it can only create a new process and terminate - * the old process. Therefore, any processes waiting on the initial - * process wake up and they shouldn't. Hence, a chain of pseudo-zombie - * processes must be retained to maintain the proper wait semantics. - * Fortunately the image size of the launcher isn't too large at this - * time. - * - * If it weren't for this semantic flaw, the code below would be ... - * - * execv(path, argv); - * JLI_ReportErrorMessage("Error: Exec of %s failed\n", path); - * exit(1); - * - * The incorrect exec semantics could be addressed by: - * - * exit((int)spawnv(_P_WAIT, path, argv)); - * - * Unfortunately, a bug in Windows spawn/exec impementation prevents - * this from completely working. All the Windows POSIX process creation - * interfaces are implemented as wrappers around the native Windows - * function CreateProcess(). CreateProcess() takes a single string - * to specify command line options and arguments, so the POSIX routine - * wrappers build a single string from the argv[] array and in the - * process, any quoting information is lost. - * - * The solution to this to get the original command line, to process it - * to remove the new multiple JRE options (if any) as was done for argv - * in the common SelectVersion() routine and finally to pass it directly - * to the native CreateProcess() Windows process control interface. - */ - { - char *cmdline; - char *p; - char *np; - char *ocl; - char *ccl; - char *unquoted; - DWORD exitCode; - STARTUPINFO si; - PROCESS_INFORMATION pi; - - /* - * The following code block gets and processes the original command - * line, replacing the argv[0] equivalent in the command line with - * the path to the new executable and removing the appropriate - * Multiple JRE support options. Note that similar logic exists - * in the platform independent SelectVersion routine, but is - * replicated here due to the syntax of CreateProcess(). - * - * The magic "+ 4" characters added to the command line length are - * 2 possible quotes around the path (argv[0]), a space after the - * path and a terminating null character. - */ - ocl = GetCommandLine(); - np = ccl = JLI_StringDup(ocl); - p = nextarg(&np); /* Discard argv[0] */ - cmdline = (char *)JLI_MemAlloc(JLI_StrLen(path) + JLI_StrLen(np) + 4); - if (JLI_StrChr(path, (int)' ') == NULL && JLI_StrChr(path, (int)'\t') == NULL) - cmdline = JLI_StrCpy(cmdline, path); - else - cmdline = JLI_StrCat(JLI_StrCat(JLI_StrCpy(cmdline, "\""), path), "\""); - - while (*np != (char)0) { /* While more command-line */ - p = nextarg(&np); - if (*p != (char)0) { /* If a token was isolated */ - unquoted = unquote(p); - if (*unquoted == '-') { /* Looks like an option */ - if (JLI_StrCmp(unquoted, "-classpath") == 0 || - JLI_StrCmp(unquoted, "-cp") == 0) { /* Unique cp syntax */ - cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p); - p = nextarg(&np); - if (*p != (char)0) /* If a token was isolated */ - cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p); - } else if (JLI_StrNCmp(unquoted, "-version:", 9) != 0 && - JLI_StrCmp(unquoted, "-jre-restrict-search") != 0 && - JLI_StrCmp(unquoted, "-no-jre-restrict-search") != 0) { - cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p); - } - } else { /* End of options */ - cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p); - cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), np); - JLI_MemFree((void *)unquoted); - break; - } - JLI_MemFree((void *)unquoted); - } - } - JLI_MemFree((void *)ccl); - - if (JLI_IsTraceLauncher()) { - np = ccl = JLI_StringDup(cmdline); - p = nextarg(&np); - printf("ReExec Command: %s (%s)\n", path, p); - printf("ReExec Args: %s\n", np); - JLI_MemFree((void *)ccl); - } - (void)fflush(stdout); - (void)fflush(stderr); - - /* - * The following code is modeled after a model presented in the - * Microsoft Technical Article "Moving Unix Applications to - * Windows NT" (March 6, 1994) and "Creating Processes" on MSDN - * (Februrary 2005). It approximates UNIX spawn semantics with - * the parent waiting for termination of the child. - */ - memset(&si, 0, sizeof(si)); - si.cb =sizeof(STARTUPINFO); - memset(&pi, 0, sizeof(pi)); - - if (!CreateProcess((LPCTSTR)path, /* executable name */ - (LPTSTR)cmdline, /* command line */ - (LPSECURITY_ATTRIBUTES)NULL, /* process security attr. */ - (LPSECURITY_ATTRIBUTES)NULL, /* thread security attr. */ - (BOOL)TRUE, /* inherits system handles */ - (DWORD)0, /* creation flags */ - (LPVOID)NULL, /* environment block */ - (LPCTSTR)NULL, /* current directory */ - (LPSTARTUPINFO)&si, /* (in) startup information */ - (LPPROCESS_INFORMATION)&pi)) { /* (out) process information */ - JLI_ReportErrorMessageSys(SYS_ERROR1, path); - exit(1); - } - - if (WaitForSingleObject(pi.hProcess, INFINITE) != WAIT_FAILED) { - if (GetExitCodeProcess(pi.hProcess, &exitCode) == FALSE) - exitCode = 1; - } else { - JLI_ReportErrorMessage(SYS_ERROR2); - exitCode = 1; - } - - CloseHandle(pi.hThread); - CloseHandle(pi.hProcess); - - exit(exitCode); - } -} - /* * Wrapper for platform dependent unsetenv function. */ diff --git a/jdk/src/java.base/windows/native/libjli/java_md.h b/jdk/src/java.base/windows/native/libjli/java_md.h index 72151b92e50..aa9fc2f0b44 100644 --- a/jdk/src/java.base/windows/native/libjli/java_md.h +++ b/jdk/src/java.base/windows/native/libjli/java_md.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -50,8 +50,7 @@ extern jlong Counter2Micros(jlong counts); /* * Function prototypes. */ -char *LocateJRE(manifest_info *info); -void ExecJRE(char *jre, char **argv); + int UnsetEnv(char *name); #endif /* JAVA_MD_H */ diff --git a/jdk/test/tools/launcher/Arrrghs.java b/jdk/test/tools/launcher/Arrrghs.java index 62552c38959..0096f22ad3b 100644 --- a/jdk/test/tools/launcher/Arrrghs.java +++ b/jdk/test/tools/launcher/Arrrghs.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 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 @@ -734,23 +734,6 @@ public class Arrrghs extends TestHelper { System.out.println(tr); } - @Test - static void testJreRestrictSearchFlag() { - // test both arguments to ensure they exist - TestResult tr = null; - tr = doExec(javaCmd, - "-no-jre-restrict-search", "-version"); - tr.checkPositive(); - if (!tr.testStatus) - System.out.println(tr); - - tr = doExec(javaCmd, - "-jre-restrict-search", "-version"); - tr.checkPositive(); - if (!tr.testStatus) - System.out.println(tr); - } - /** * @param args the command line arguments * @throws java.io.FileNotFoundException diff --git a/jdk/test/tools/launcher/MultipleJRE.sh b/jdk/test/tools/launcher/MultipleJRE.sh index 799d003e08f..61cac1b3eb9 100644 --- a/jdk/test/tools/launcher/MultipleJRE.sh +++ b/jdk/test/tools/launcher/MultipleJRE.sh @@ -5,7 +5,7 @@ # @build UglyPrintVersion # @build ZipMeUp # @run shell MultipleJRE.sh -# @summary Verify Multiple JRE version support +# @summary Verify Multiple JRE version support has been removed # @author Joseph E. Kowalski # @@ -222,37 +222,76 @@ CreateAlignedJar() { # long file name (path) or a long "Ext" entry, but adding the long # comment is the easiest way. # +MONDO=" Mondo comment line 00 is designed to take up space - lots and lots of space. Mondo comment line 01 is designed to take up space - lots and lots of space. Mondo comment line 02 is designed to take up space - lots and lots of space. Mondo comment line 03 is designed to take up space - lots and lots of space. Mondo comment line 04 is designed to take up space - lots and lots of space. Mondo comment line 05 is designed to take up space - lots and lots of space. Mondo comment line 06 is designed to take up space - lots and lots of space. Mondo comment line 07 is designed to take up space - lots and lots of space. Mondo comment line 08 is designed to take up space - lots and lots of space. Mondo comment line 09 is designed to take up space - lots and lots of space. Mondo comment line 0a is designed to take up space - lots and lots of space. Mondo comment line 0b is designed to take up space - lots and lots of space. Mondo comment line 0c is designed to take up space - lots and lots of space. Mondo comment line 0d is designed to take up space - lots and lots of space. Mondo comment line 0e is designed to take up space - lots and lots of space. Mondo comment line 0f is designed to take up space - lots and lots of space. Mondo comment line 10 is designed to take up space - lots and lots of space. Mondo comment line 11 is designed to take up space - lots and lots of space. Mondo comment line 12 is designed to take up space - lots and lots of space. Mondo comment line 13 is designed to take up space - lots and lots of space. Mondo comment line 14 is designed to take up space - lots and lots of space. Mondo comment line 15 is designed to take up space - lots and lots of space. Mondo comment line 16 is designed to take up space - lots and lots of space. Mondo comment line 17 is designed to take up space - lots and lots of space. Mondo comment line 18 is designed to take up space - lots and lots of space. Mondo comment line 19 is designed to take up space - lots and lots of space. Mondo comment line 1a is designed to take up space - lots and lots of space. Mondo comment line 1b is designed to take up space - lots and lots of space. Mondo comment line 1c is designed to take up space - lots and lots of space. Mondo comment line 1d is designed to take up space - lots and lots of space. Mondo comment line 1e is designed to take up space - lots and lots of space. Mondo comment line 1f is designed to take up space - lots and lots of space. Mondo comment line 20 is designed to take up space - lots and lots of space. Mondo comment line 21 is designed to take up space - lots and lots of space. Mondo comment line 22 is designed to take up space - lots and lots of space. Mondo comment line 23 is designed to take up space - lots and lots of space. Mondo comment line 24 is designed to take up space - lots and lots of space. Mondo comment line 25 is designed to take up space - lots and lots of space. Mondo comment line 26 is designed to take up space - lots and lots of space. Mondo comment line 27 is designed to take up space - lots and lots of space. Mondo comment line 28 is designed to take up space - lots and lots of space. Mondo comment line 29 is designed to take up space - lots and lots of space. Mondo comment line 2a is designed to take up space - lots and lots of space. Mondo comment line 2b is designed to take up space - lots and lots of space. Mondo comment line 2c is designed to take up space - lots and lots of space. Mondo comment line 2d is designed to take up space - lots and lots of space. Mondo comment line 2e is designed to take up space - lots and lots of space. Mondo comment line 2f is designed to take up space - lots and lots of space. Mondo comment line 30 is designed to take up space - lots and lots of space. Mondo comment line 31 is designed to take up space - lots and lots of space. Mondo comment line 32 is designed to take up space - lots and lots of space. Mondo comment line 33 is designed to take up space - lots and lots of space. Mondo comment line 34 is designed to take up space - lots and lots of space. Mondo comment line 35 is designed to take up space - lots and lots of space. Mondo comment line 36 is designed to take up space - lots and lots of space. Mondo comment line 37 is designed to take up space - lots and lots of space. Mondo comment line 38 is designed to take up space - lots and lots of space. Mondo comment line 39 is designed to take up space - lots and lots of space. Mondo comment line 3a is designed to take up space - lots and lots of space. Mondo comment line 3b is designed to take up space - lots and lots of space. Mondo comment line 3c is designed to take up space - lots and lots of space. Mondo comment line 3d is designed to take up space - lots and lots of space. Mondo comment line 3e is designed to take up space - lots and lots of space. Mondo comment line 3f is designed to take up space - lots and lots of space. Mondo comment line 40 is designed to take up space - lots and lots of space. Mondo comment line 41 is designed to take up space - lots and lots of space. Mondo comment line 42 is designed to take up space - lots and lots of space. Mondo comment line 43 is designed to take up space - lots and lots of space. Mondo comment line 44 is designed to take up space - lots and lots of space. Mondo comment line 45 is designed to take up space - lots and lots of space. Mondo comment line 46 is designed to take up space - lots and lots of space. Mondo comment line 47 is designed to take up space - lots and lots of space. Mondo comment line 48 is designed to take up space - lots and lots of space. Mondo comment line 49 is designed to take up space - lots and lots of space. Mondo comment line 4a is designed to take up space - lots and lots of space. Mondo comment line 4b is designed to take up space - lots and lots of space. Mondo comment line 4c is designed to take up space - lots and lots of space. Mondo comment line 4d is designed to take up space - lots and lots of space. Mondo comment line 4e is designed to take up space - lots and lots of space. Mondo comment line 4f is designed to take up space - lots and lots of space. Mondo comment line 50 is designed to take up space - lots and lots of space. Mondo comment line 51 is designed to take up space - lots and lots of space. Mondo comment line 52 is designed to take up space - lots and lots of space. Mondo comment line 53 is designed to take up space - lots and lots of space. Mondo comment line 54 is designed to take up space - lots and lots of space. Mondo comment line 55 is designed to take up space - lots and lots of space. Mondo comment line 56 is designed to take up space - lots and lots of space. Mondo comment line 57 is designed to take up space - lots and lots of space. Mondo comment line 58 is designed to take up space - lots and lots of space. Mondo comment line 59 is designed to take up space - lots and lots of space. Mondo comment line 5a is designed to take up space - lots and lots of space. Mondo comment line 5b is designed to take up space - lots and lots of space. Mondo comment line 5c is designed to take up space - lots and lots of space. Mondo comment line 5d is designed to take up space - lots and lots of space. Mondo comment line 5e is designed to take up space - lots and lots of space. Mondo comment line 5f is designed to take up space - lots and lots of space. Mondo comment line 60 is designed to take up space - lots and lots of space. Mondo comment line 61 is designed to take up space - lots and lots of space. Mondo comment line 62 is designed to take up space - lots and lots of space. Mondo comment line 63 is designed to take up space - lots and lots of space. Mondo comment line 64 is designed to take up space - lots and lots of space. Mondo comment line 65 is designed to take up space - lots and lots of space. Mondo comment line 66 is designed to take up space - lots and lots of space. Mondo comment line 67 is designed to take up space - lots and lots of space. Mondo comment line 68 is designed to take up space - lots and lots of space. Mondo comment line 69 is designed to take up space - lots and lots of space. Mondo comment line 6a is designed to take up space - lots and lots of space. Mondo comment line 6b is designed to take up space - lots and lots of space. Mondo comment line 6c is designed to take up space - lots and lots of space. Mondo comment line 6d is designed to take up space - lots and lots of space. Mondo comment line 6e is designed to take up space - lots and lots of space. Mondo comment line 6f is designed to take up space - lots and lots of space. Mondo comment line 70 is designed to take up space - lots and lots of space. Mondo comment line 71 is designed to take up space - lots and lots of space. Mondo comment line 72 is designed to take up space - lots and lots of space. Mondo comment line 73 is designed to take up space - lots and lots of space. Mondo comment line 74 is designed to take up space - lots and lots of space. Mondo comment line 75 is designed to take up space - lots and lots of space. Mondo comment line 76 is designed to take up space - lots and lots of space. Mondo comment line 77 is designed to take up space - lots and lots of space. Mondo comment line 78 is designed to take up space - lots and lots of space. Mondo comment line 79 is designed to take up space - lots and lots of space. Mondo comment line 7a is designed to take up space - lots and lots of space. Mondo comment line 7b is designed to take up space - lots and lots of space. Mondo comment line 7c is designed to take up space - lots and lots of space. Mondo comment line 7d is designed to take up space - lots and lots of space. Mondo comment line 7e is designed to take up space - lots and lots of space. Mondo comment line 7f is designed to take up space - lots and lots of space. Mondo comment line 80 is designed to take up space - lots and lots of space. Mondo comment line 81 is designed to take up space - lots and lots of space. Mondo comment line 82 is designed to take up space - lots and lots of space. Mondo comment line 83 is designed to take up space - lots and lots of space. Mondo comment line 84 is designed to take up space - lots and lots of space. Mondo comment line 85 is designed to take up space - lots and lots of space. Mondo comment line 86 is designed to take up space - lots and lots of space. Mondo comment line 87 is designed to take up space - lots and lots of space. Mondo comment line 88 is designed to take up space - lots and lots of space. Mondo comment line 89 is designed to take up space - lots and lots of space. Mondo comment line 8a is designed to take up space - lots and lots of space. Mondo comment line 8b is designed to take up space - lots and lots of space. Mondo comment line 8c is designed to take up space - lots and lots of space. Mondo comment line 8d is designed to take up space - lots and lots of space. Mondo comment line 8e is designed to take up space - lots and lots of space. Mondo comment line 8f is designed to take up space - lots and lots of space. Mondo comment line 90 is designed to take up space - lots and lots of space. Mondo comment line 91 is designed to take up space - lots and lots of space. Mondo comment line 92 is designed to take up space - lots and lots of space. Mondo comment line 93 is designed to take up space - lots and lots of space. Mondo comment line 94 is designed to take up space - lots and lots of space. Mondo comment line 95 is designed to take up space - lots and lots of space. Mondo comment line 96 is designed to take up space - lots and lots of space. Mondo comment line 97 is designed to take up space - lots and lots of space. Mondo comment line 98 is designed to take up space - lots and lots of space. Mondo comment line 99 is designed to take up space - lots and lots of space. Mondo comment line 9a is designed to take up space - lots and lots of space. Mondo comment line 9b is designed to take up space - lots and lots of space. Mondo comment line 9c is designed to take up space - lots and lots of space. Mondo comment line 9d is designed to take up space - lots and lots of space. Mondo comment line 9e is designed to take up space - lots and lots of space. Mondo comment line 9f is designed to take up space - lots and lots of space. Mondo comment line a0 is designed to take up space - lots and lots of space. Mondo comment line a1 is designed to take up space - lots and lots of space. Mondo comment line a2 is designed to take up space - lots and lots of space. Mondo comment line a3 is designed to take up space - lots and lots of space. Mondo comment line a4 is designed to take up space - lots and lots of space. Mondo comment line a5 is designed to take up space - lots and lots of space. Mondo comment line a6 is designed to take up space - lots and lots of space. Mondo comment line a7 is designed to take up space - lots and lots of space. Mondo comment line a8 is designed to take up space - lots and lots of space. Mondo comment line a9 is designed to take up space - lots and lots of space. Mondo comment line aa is designed to take up space - lots and lots of space. Mondo comment line ab is designed to take up space - lots and lots of space. Mondo comment line ac is designed to take up space - lots and lots of space. Mondo comment line ad is designed to take up space - lots and lots of space. Mondo comment line ae is designed to take up space - lots and lots of space. Mondo comment line af is designed to take up space - lots and lots of space. Mondo comment line b0 is designed to take up space - lots and lots of space. Mondo comment line b1 is designed to take up space - lots and lots of space. Mondo comment line b2 is designed to take up space - lots and lots of space. Mondo comment line b3 is designed to take up space - lots and lots of space. Mondo comment line b4 is designed to take up space - lots and lots of space. Mondo comment line b5 is designed to take up space - lots and lots of space. Mondo comment line b6 is designed to take up space - lots and lots of space. Mondo comment line b7 is designed to take up space - lots and lots of space. Mondo comment line b8 is designed to take up space - lots and lots of space. Mondo comment line b9 is designed to take up space - lots and lots of space. Mondo comment line ba is designed to take up space - lots and lots of space. Mondo comment line bb is designed to take up space - lots and lots of space. Mondo comment line bc is designed to take up space - lots and lots of space. Mondo comment line bd is designed to take up space - lots and lots of space. Mondo comment line be is designed to take up space - lots and lots of space. Mondo comment line bf is designed to take up space - lots and lots of space. Mondo comment line c0 is designed to take up space - lots and lots of space. Mondo comment line c1 is designed to take up space - lots and lots of space. Mondo comment line c2 is designed to take up space - lots and lots of space. Mondo comment line c3 is designed to take up space - lots and lots of space. Mondo comment line c4 is designed to take up space - lots and lots of space. Mondo comment line c5 is designed to take up space - lots and lots of space. Mondo comment line c6 is designed to take up space - lots and lots of space. Mondo comment line c7 is designed to take up space - lots and lots of space. Mondo comment line c8 is designed to take up space - lots and lots of space. Mondo comment line c9 is designed to take up space - lots and lots of space. Mondo comment line ca is designed to take up space - lots and lots of space. Mondo comment line cb is designed to take up space - lots and lots of space. Mondo comment line cc is designed to take up space - lots and lots of space. Mondo comment line cd is designed to take up space - lots and lots of space. Mondo comment line ce is designed to take up space - lots and lots of space. Mondo comment line cf is designed to take up space - lots and lots of space. Mondo comment line d0 is designed to take up space - lots and lots of space. Mondo comment line d1 is designed to take up space - lots and lots of space. Mondo comment line d2 is designed to take up space - lots and lots of space. Mondo comment line d3 is designed to take up space - lots and lots of space. Mondo comment line d4 is designed to take up space - lots and lots of space. Mondo comment line d5 is designed to take up space - lots and lots of space. Mondo comment line d6 is designed to take up space - lots and lots of space. Mondo comment line d7 is designed to take up space - lots and lots of space. Mondo comment line d8 is designed to take up space - lots and lots of space. Mondo comment line d9 is designed to take up space - lots and lots of space. Mondo comment line da is designed to take up space - lots and lots of space. Mondo comment line db is designed to take up space - lots and lots of space. Mondo comment line dc is designed to take up space - lots and lots of space. Mondo comment line dd is designed to take up space - lots and lots of space. Mondo comment line de is designed to take up space - lots and lots of space. Mondo comment line df is designed to take up space - lots and lots of space. Mondo comment line e0 is designed to take up space - lots and lots of space. Mondo comment line e1 is designed to take up space - lots and lots of space. Mondo comment line e2 is designed to take up space - lots and lots of space. Mondo comment line e3 is designed to take up space - lots and lots of space. Mondo comment line e4 is designed to take up space - lots and lots of space. Mondo comment line e5 is designed to take up space - lots and lots of space. Mondo comment line e6 is designed to take up space - lots and lots of space. Mondo comment line e7 is designed to take up space - lots and lots of space. Mondo comment line e8 is designed to take up space - lots and lots of space. Mondo comment line e9 is designed to take up space - lots and lots of space. Mondo comment line ea is designed to take up space - lots and lots of space. Mondo comment line eb is designed to take up space - lots and lots of space. Mondo comment line ec is designed to take up space - lots and lots of space. Mondo comment line ed is designed to take up space - lots and lots of space. Mondo comment line ee is designed to take up space - lots and lots of space. Mondo comment line ef is designed to take up space - lots and lots of space. Mondo comment line f0 is designed to take up space - lots and lots of space. Mondo comment line f1 is designed to take up space - lots and lots of space. Mondo comment line f2 is designed to take up space - lots and lots of space. Mondo comment line f3 is designed to take up space - lots and lots of space. Mondo comment line f4 is designed to take up space - lots and lots of space. Mondo comment line f5 is designed to take up space - lots and lots of space. Mondo comment line f6 is designed to take up space - lots and lots of space. Mondo comment line f7 is designed to take up space - lots and lots of space. Mondo comment line f8 is designed to take up space - lots and lots of space. Mondo comment line f9 is designed to take up space - lots and lots of space. Mondo comment line fa is designed to take up space - lots and lots of space. Mondo comment line fb is designed to take up space - lots and lots of space. Mondo comment line fc is designed to take up space - lots and lots of space. Mondo comment line fd is designed to take up space - lots and lots of space. Mondo comment line fe is designed to take up space - lots and lots of space. Mondo comment line ff is designed to take up space - lots and lots of space." CommentZipFile() { - file= - tail="is designed to take up space - lots and lots of space." - mv PrintVersion PrintVersion.zip - /usr/bin/zipnote PrintVersion.zip > zipout - while read ampersand line; do - if [ "$ampersand" = "@" ]; then - if [ "$line" = "(comment above this line)" ]; then - echo "File Comment Line." >> zipin - if [ "$file" = "$1" ]; then - for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do - for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do - echo "Mondo comment line $i$j $tail" >> zipin - done - done - fi - else - file=$line - fi + mkdir -p META-INF + echo "Manifest-Version: 1.0" > META-INF/MANIFEST.MF + echo "Main-Class: PrintVersion" >> META-INF/MANIFEST.MF + if [ "$1" != "" ]; then + echo "JRE-Version: $1" >> META-INF/MANIFEST.MF fi - echo "$ampersand $line" >> zipin - if [ "$ampersand" = "@" ]; then - if [ "$line" = "(zip file comment below this line)" ]; then - echo "Zip File Comment Line number 1" >> zipin - echo "Zip File Comment Line number 2" >> zipin - fi - fi - done < zipout - /usr/bin/zipnote -w PrintVersion.zip < zipin + cp $TESTCLASSES/PrintVersion.class . + + # The remaining code in CommentZipFile essentially replaces the + # following code, which added comments to the jar file. + # Unfortunately zipnote has been broken since 3.0 [ 2008 ] and + # there has been no new [ fixed ] version. zipnote has probably + # always failed, or failed for a long time without causing the + # test to fail. So no comments were added to the file. + # The comments are added using zip(1) during the creation of the + # zip file. + # + # NOTE: + # It seems the original intent of this test was to add a very long + # comment for one file. But zip allows a max of 256 characters, so + # we settle for adding 256-character comments to lots of files. + # + # $JAR $2cMf PrintVersion PrintVersion.class AfairlyLong* + # $JAR $2umf META-INF/MANIFEST.MF PrintVersion + # /usr/bin/zipnote PrintVersion.zip > zipout + # ... code to modify zipout adding comments + # /usr/bin/zipnote -w PrintVersion.zip < zipin + # mv PrintVersion.zip PrintVersion + # + + + for i in 0 1 2 3 4 5 6 7 8 9 ; do + for j in 0 1 2 3 4 5 6 7 8 9 ; do + touch AfairlyLongNameEatsUpDirectorySpaceBetter$i$j + done + done + + zip -$2c PrintVersion.zip PrintVersion.class AfairlyLong* META-INF/MANIFEST.MF << FINI +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +File Comment Line. +$MONDO +File Comment Line. +File Comment Line. +File Comment Line. +FINI + + rm -f AfairlyLong* + mv PrintVersion.zip PrintVersion - rm zipout zipin + } # @@ -261,22 +300,29 @@ CommentZipFile() { # LaunchVM() { if [ "$1" != "" ]; then - mess="`$JAVA -version:\"$1\" -jar PrintVersion 2>&1`" - else - mess="`$JAVA -jar PrintVersion 2>&1`" - fi - if [ $? -ne 0 ]; then - prefix=`echo "$mess" | cut -d ' ' -f 1-3` - if [ "$prefix" != "Unable to locate" ]; then + mess="`$JAVA \"$1\" -jar PrintVersion 2>&1`" + if [ $? -eq 0 ]; then + echo "Unexpected success of -Version:$1" echo "$mess" exit 1 fi - echo "Unexpected error in attempting to locate $1" - exit 1 + else + mess="`$JAVA -jar PrintVersion 2>&1`" + if [ $? -ne 0 ]; then + prefix=`echo "$mess" | cut -d ' ' -f 1-3` + if [ "$prefix" != "Unable to locate" ]; then + echo "$mess" + exit 1 + fi + echo "Unexpected error in attempting to locate $1" + exit 1 + fi + fi + echo $mess | grep "$2" > /dev/null 2>&1 if [ $? != 0 ]; then - echo "Launched $mess, expected $2" + echo "Launched $mess, expected $1" exit 1 fi } @@ -307,6 +353,7 @@ TestLongMainClass() { # # Main test sequence starts here # + RELEASE=`$JAVA -version 2>&1 | head -n 1 | cut -d ' ' -f 3 | \ sed -e "s/\"//g"` BASE_RELEASE=`echo $RELEASE | sed -e "s/-.*//g"` @@ -386,91 +433,31 @@ if [ -x /usr/bin/zipnote ]; then fi # -# Throw some syntactically challenged (illegal) version specifiers at -# the interface. Failure (of the launcher) is success for the test. +# Now test specification of mJRE +# +# In some cases this should result in failure of the command, +# in some cases, a warning messages, with the command succeeding. # -TestSyntax "1.2..3" # Two adjacent separators -TestSyntax "_1.2.3" # Begins with a separator -TestSyntax "1.2.3-" # Ends with a separator -TestSyntax "1.2+.3" # Embedded modifier -TestSyntax "1.2.4+&1.2*&1++" # Long and invalid -# On windows we see if there is another jre installed, usually -# there is, then we test using that, otherwise links are created -# to get through to SelectVersion. -if [ `IsWindows` = "false" ]; then - TestLongMainClass "mklink" -else - $JAVAEXE -version:1.0+ - if [ $? -eq 0 ]; then - TestLongMainClass "1.0+" - else - printf "Warning: TestLongMainClass skipped as there is no" - printf "viable MJRE installed.\n" - fi -fi + # Commandline use of "-version:" should fail + # with a message containing "no longer supported" + LaunchVM "-version:1.10+" "Error: Specifying an alternate JDK/JRE" + LaunchVM "-version:prettymuchanything" "Error: Specifying an alternate JDK/JRE" -# -# Because scribbling in the registry can be rather destructive, only a -# subset of the tests are run on Windows. -# -if [ `IsWindows` = "true" ]; then - exit 0; -fi + # Commandline use of "-jre-restrict-search" should now fail + LaunchVM "-jre-restrict-search" "\-jre\-no\-restrict\-search are also no longer valid" + # Commandline use of "-jre-no-restrict-search" should now fail + LaunchVM "-jre-no-restrict-search" "\-jre\-no\-restrict\-search are also no longer valid" -# -# Additional version specifiers containing spaces. (Sigh, unable to -# figure out the glomming on Windows) -# -TestSyntax "1.2.3_99 1.3.2+ 1.2.4+&1.2*&1++" # Long and invalid -# -# Create a mock installation of a number of shell scripts named as though -# they were installed JREs. Then test to see if the launcher can cause -# the right shell scripts to be invoked. -# -# Note, that as a side effect, this test verifies that JAVA_VERSION_PATH -# works. -# -rm -rf jdk -JAVA_VERSION_PATH="`pwd`/jdk" -export JAVA_VERSION_PATH - -CreateMockVM 1.10 -CreateMockVM 1.11.3 -CreateMockVM 1.11.3_03 -CreateMockVM 1.11.4 -CreateMockVM 1.12.3_03 -CreateMockVM 1.12.3_03-lastweek -CreateMockVM 1.13.3_03 -CreateMockVM 1.13.3_03-lastweek -CreateMockVM 1.13.3_03_lastweek -CreateMockVM 1.20.0 - -# -# Test extracting the version information from the jar file: -# -# Requested Expected -CreateJar "1.10+" "" -LaunchVM "" "1.20.0" -CreateJar "1.11.3_03+&1.11*" "" -LaunchVM "" "1.11.4" -CreateJar "1.12.3_03+&1.12.3*" "" -LaunchVM "" "1.12.3_03" -CreateJar "1.13.3_03+&1.13.3*" "" -LaunchVM "" "1.13.3_03_lastweek" # Strange but true - -# -# Test obtaining the version information from the command line (and that -# it overrides the manifest). -# -CreateJar "${BASERELEASE}*" "" -LaunchVM "1.10+" "1.20.0" -LaunchVM "1.11.3_03+&1.11*" "1.11.4" -LaunchVM "1.12.3_03+&1.12.3*" "1.12.3_03" -LaunchVM "1.13.3_03+&1.13.3*" "1.13.3_03_lastweek" # Strange but true - -[ -d jdk ] && rm -rf jdk -[ -d META_INF ] && rm -rf META_INF + # mJRE directives to use a specific version should be flagged + # with a warning, but the jar should be executed with the + # current jre + CreateFullJar "junk request" "" + LaunchVM "" "${RELEASE}" + # Going to silently ignore JRE-Version setting in jar file manifest + #LaunchVM "" "warning: The jarfile JRE-Version" + exit 0 + From 34372ab22367167d0f71f773221221263abb797d Mon Sep 17 00:00:00 2001 From: Zaiyao Liu Date: Mon, 8 Dec 2014 07:15:49 +0000 Subject: [PATCH 04/12] 8049432: New tests for TLS property jdk.tls.client.protocols Reviewed-by: xuelei --- .../net/ssl/TLS/TLSClientPropertyTest.java | 204 ++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 jdk/test/javax/net/ssl/TLS/TLSClientPropertyTest.java diff --git a/jdk/test/javax/net/ssl/TLS/TLSClientPropertyTest.java b/jdk/test/javax/net/ssl/TLS/TLSClientPropertyTest.java new file mode 100644 index 00000000000..e3398ae6ee5 --- /dev/null +++ b/jdk/test/javax/net/ssl/TLS/TLSClientPropertyTest.java @@ -0,0 +1,204 @@ +/* + * Copyright (c) 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 + * 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. + */ + +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; +import java.util.List; +import javax.net.ssl.SSLContext; + +/* + * @test + * @bug 8049432 + * @summary New tests for TLS property jdk.tls.client.protocols + * @run main/othervm TLSClientPropertyTest NoProperty + * @run main/othervm TLSClientPropertyTest SSLv3 + * @run main/othervm TLSClientPropertyTest TLSv1 + * @run main/othervm TLSClientPropertyTest TLSv11 + * @run main/othervm TLSClientPropertyTest TLSv12 + * @run main/othervm TLSClientPropertyTest WrongProperty + */ + +/** + * Sets the property jdk.tls.client.protocols to one of this protocols: + * SSLv3,TLSv1,TLSv1.1,TLSv1.2 and TLSV(invalid) or removes this + * property (if any),then validates the default, supported and current + * protocols in the SSLContext. + */ +public class TLSClientPropertyTest { + private final String[] expecteSupportedProtos = new String[] { + "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2" + }; + + public static void main(String[] args) throws Exception { + + if (args.length < 1) { + throw new RuntimeException( + "Incorrect arguments,expected arguments: testCase"); + } + + String[] expectedDefaultProtos; + String testCase = args[0]; + String contextProtocol; + switch (testCase) { + case "NoProperty": + if (System.getProperty("jdk.tls.client.protocols") != null) { + System.getProperties().remove("jdk.tls.client.protocols"); + } + contextProtocol = null; + expectedDefaultProtos = new String[] { + "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2" + }; + break; + case "SSLv3": + contextProtocol = "SSLv3"; + expectedDefaultProtos = new String[] { + "SSLv3" + }; + break; + case "TLSv1": + contextProtocol = "TLSv1"; + expectedDefaultProtos = new String[] { + "SSLv3", "TLSv1" + }; + break; + case "TLSv11": + contextProtocol = "TLSv1.1"; + expectedDefaultProtos = new String[] { + "SSLv3", "TLSv1", "TLSv1.1" + }; + break; + case "TLSv12": + contextProtocol = "TLSv1.2"; + expectedDefaultProtos = new String[] { + "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2" + }; + break; + case "WrongProperty": + expectedDefaultProtos = new String[] {}; + contextProtocol = "TLSV"; + break; + default: + throw new RuntimeException("test case is wrong"); + } + if (contextProtocol != null) { + System.setProperty("jdk.tls.client.protocols", contextProtocol); + } + try { + TLSClientPropertyTest test = new TLSClientPropertyTest(); + test.test(contextProtocol, expectedDefaultProtos); + if (testCase.equals("WrongProperty")) { + throw new RuntimeException( + "Test failed: NoSuchAlgorithmException " + + "is expected when input wrong protocol"); + } else { + System.out.println("Test " + contextProtocol + " passed"); + } + } catch (NoSuchAlgorithmException nsae) { + if (testCase.equals("WrongProperty")) { + System.out.println("NoSuchAlgorithmException is expected," + + contextProtocol + " test passed"); + } else { + throw nsae; + } + } + + } + + /** + * The parameter passed is the user enforced protocol. Does not catch + * NoSuchAlgorithmException, WrongProperty test will use it. + */ + public void test(String expectedContextProto, + String[] expectedDefaultProtos) throws NoSuchAlgorithmException { + + SSLContext context = null; + try { + if (expectedContextProto != null) { + context = SSLContext.getInstance(expectedContextProto); + context.init(null, null, null); + } else { + context = SSLContext.getDefault(); + } + printContextDetails(context); + } catch (KeyManagementException ex) { + error(null, ex); + } + + validateContext(expectedContextProto, expectedDefaultProtos, context); + } + + /** + * Simple print utility for SSLContext's protocol details. + */ + private void printContextDetails(SSLContext context) { + System.out.println("Default Protocols: " + + Arrays.toString(context.getDefaultSSLParameters() + .getProtocols())); + System.out.println("Supported Protocols: " + + Arrays.toString(context.getSupportedSSLParameters() + .getProtocols())); + System.out.println("Current Protocol : " + context.getProtocol()); + + } + + /** + * Error handler. + */ + private void error(String msg, Throwable tble) { + String finalMsg = "FAILED " + (msg != null ? msg : ""); + if (tble != null) { + throw new RuntimeException(finalMsg, tble); + } + throw new RuntimeException(finalMsg); + } + + /** + * Validates the SSLContext's protocols against the user enforced protocol. + */ + private void validateContext(String expectedProto, + String[] expectedDefaultProtos, SSLContext context) { + if (expectedProto == null) { + expectedProto = "Default"; + } + if (!context.getProtocol().equals(expectedProto)) { + error("Invalid current protocol:" + context.getProtocol() + + ", Expected:" + expectedProto, null); + } + List actualDefaultProtos = Arrays.asList(context + .getDefaultSSLParameters().getProtocols()); + for (String p: expectedDefaultProtos) { + if (!actualDefaultProtos.contains(p)) { + error("Default protocol " + p + "missing", null); + } + } + List actualSupportedProtos = Arrays.asList(context + .getSupportedSSLParameters().getProtocols()); + + for (String p: expecteSupportedProtos) { + if (!actualSupportedProtos.contains(p)) { + error("Expected to support protocol:" + p, null); + } + } + } +} From 8732d09ae7f6de828d2b4538b09ac1a88af0e053 Mon Sep 17 00:00:00 2001 From: Kumar Srinivasan Date: Mon, 8 Dec 2014 07:51:59 -0800 Subject: [PATCH 05/12] 8066745: tools/pack200/Pack200Props.java failed with java.lang.OutOfMemoryError: Java heap space Reviewed-by: alanb --- jdk/test/tools/pack200/Pack200Props.java | 2 ++ jdk/test/tools/pack200/Pack200Test.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/jdk/test/tools/pack200/Pack200Props.java b/jdk/test/tools/pack200/Pack200Props.java index e9d14322907..dcb90548be8 100644 --- a/jdk/test/tools/pack200/Pack200Props.java +++ b/jdk/test/tools/pack200/Pack200Props.java @@ -62,6 +62,8 @@ public class Pack200Props { List cmdsList = new ArrayList<>(); cmdsList.add(Utils.getPack200Cmd()); + cmdsList.add("-J-Xshare:off"); + cmdsList.add("-J-Xmx1280m"); cmdsList.add("--effort=1"); cmdsList.add("--verbose"); cmdsList.add("--no-gzip"); diff --git a/jdk/test/tools/pack200/Pack200Test.java b/jdk/test/tools/pack200/Pack200Test.java index 5d7fc105745..69cec754a07 100644 --- a/jdk/test/tools/pack200/Pack200Test.java +++ b/jdk/test/tools/pack200/Pack200Test.java @@ -34,7 +34,7 @@ import java.util.jar.*; * @summary check for memory leaks, test general packer/unpacker functionality\ * using native and java unpackers * @compile -XDignore.symbol.file Utils.java Pack200Test.java - * @run main/othervm/timeout=1200 -Xmx512m Pack200Test + * @run main/othervm/timeout=1200 -Xmx1280m -Xshare:off Pack200Test * @author ksrini */ From 220aa4b8385dc15030941c014825a67986290ca6 Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Mon, 8 Dec 2014 09:13:08 -0800 Subject: [PATCH 06/12] 8066643: (zipfs) Suppress deprecation warnings in jdk.zipfs module 8066634: Suppress deprecation warnings in java.management module 8066636: Suppress deprecation warnings in the jdk.jvmstat and jdk.jdi modules Reviewed-by: alanb, lancea, sherman, sla, dfuchs --- .../sun/jmx/interceptor/DefaultMBeanServerInterceptor.java | 5 ++++- .../com/sun/tools/example/debug/expr/ExpressionParser.java | 1 + .../sun/jvmstat/perfdata/monitor/PerfDataBufferImpl.java | 1 + .../jdk.jvmstat/share/classes/sun/tools/jstatd/Jstatd.java | 1 + jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipUtils.java | 2 ++ 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/jdk/src/java.management/share/classes/com/sun/jmx/interceptor/DefaultMBeanServerInterceptor.java b/jdk/src/java.management/share/classes/com/sun/jmx/interceptor/DefaultMBeanServerInterceptor.java index 47b95927307..a0589f72b05 100644 --- a/jdk/src/java.management/share/classes/com/sun/jmx/interceptor/DefaultMBeanServerInterceptor.java +++ b/jdk/src/java.management/share/classes/com/sun/jmx/interceptor/DefaultMBeanServerInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -1707,16 +1707,19 @@ public class DefaultMBeanServerInterceptor implements MBeanServerInterceptor { throw new UnsupportedOperationException("Not supported yet."); } + @SuppressWarnings("deprecation") public ObjectInputStream deserialize(ObjectName name, byte[] data) throws InstanceNotFoundException, OperationsException { throw new UnsupportedOperationException("Not supported yet."); } + @SuppressWarnings("deprecation") public ObjectInputStream deserialize(String className, byte[] data) throws OperationsException, ReflectionException { throw new UnsupportedOperationException("Not supported yet."); } + @SuppressWarnings("deprecation") public ObjectInputStream deserialize(String className, ObjectName loaderName, byte[] data) throws InstanceNotFoundException, OperationsException, ReflectionException { diff --git a/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/expr/ExpressionParser.java b/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/expr/ExpressionParser.java index 4005adc4262..c0c22e8f3ec 100644 --- a/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/expr/ExpressionParser.java +++ b/jdk/src/jdk.jdi/share/classes/com/sun/tools/example/debug/expr/ExpressionParser.java @@ -59,6 +59,7 @@ public class ExpressionParser implements ExpressionParserConstants { StackFrame get() throws IncompatibleThreadStateException; } + @SuppressWarnings("deprecation") public static Value evaluate(String expr, VirtualMachine vm, GetFrame frameGetter) throws ParseException, InvocationException, diff --git a/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/PerfDataBufferImpl.java b/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/PerfDataBufferImpl.java index 2bde91cf719..db72e654735 100644 --- a/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/PerfDataBufferImpl.java +++ b/jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/PerfDataBufferImpl.java @@ -158,6 +158,7 @@ public abstract class PerfDataBufferImpl { * the sun.jvmstat.perfdata.aliasmap file indicates some other * file as the source. */ + @SuppressWarnings("deprecation") private void buildAliasMap() { assert Thread.holdsLock(this); diff --git a/jdk/src/jdk.jvmstat/share/classes/sun/tools/jstatd/Jstatd.java b/jdk/src/jdk.jvmstat/share/classes/sun/tools/jstatd/Jstatd.java index 22238e70142..09a17803cfa 100644 --- a/jdk/src/jdk.jvmstat/share/classes/sun/tools/jstatd/Jstatd.java +++ b/jdk/src/jdk.jvmstat/share/classes/sun/tools/jstatd/Jstatd.java @@ -76,6 +76,7 @@ public class Jstatd { } } + @SuppressWarnings("deprecation") // Use of RMISecurityManager public static void main(String[] args) { String rminame = null; int argc = 0; diff --git a/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipUtils.java b/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipUtils.java index 0e3584e89c9..114dc4523d3 100644 --- a/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipUtils.java +++ b/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipUtils.java @@ -103,6 +103,7 @@ class ZipUtils { /* * Converts DOS time to Java time (number of milliseconds since epoch). */ + @SuppressWarnings("deprecation") public static long dosToJavaTime(long dtime) { Date d = new Date((int)(((dtime >> 25) & 0x7f) + 80), (int)(((dtime >> 21) & 0x0f) - 1), @@ -116,6 +117,7 @@ class ZipUtils { /* * Converts Java time to DOS time. */ + @SuppressWarnings("deprecation") public static long javaToDosTime(long time) { Date d = new Date(time); int year = d.getYear() + 1900; From 277a0d2dc8f06177bafec014f8acf9f6f9c18fb0 Mon Sep 17 00:00:00 2001 From: Kumar Srinivasan Date: Mon, 8 Dec 2014 11:54:17 -0800 Subject: [PATCH 07/12] 8066841: Need to exclude javacpl in tools/launcher/VersionCheck.java Reviewed-by: alanb --- jdk/test/tools/launcher/VersionCheck.java | 1 + 1 file changed, 1 insertion(+) diff --git a/jdk/test/tools/launcher/VersionCheck.java b/jdk/test/tools/launcher/VersionCheck.java index 59e0973b468..d7044446588 100644 --- a/jdk/test/tools/launcher/VersionCheck.java +++ b/jdk/test/tools/launcher/VersionCheck.java @@ -69,6 +69,7 @@ public class VersionCheck extends TestHelper { "java-rmi", "java-rmi.cgi", "javadoc", + "javacpl", "javaws", "jcmd", "jconsole", From b633764a638fcca2afef4fd1be9142e3c71540c4 Mon Sep 17 00:00:00 2001 From: Stuart Marks Date: Mon, 8 Dec 2014 14:32:31 -0800 Subject: [PATCH 08/12] 8066835: TEST_BUG: javax/management/remote/mandatory/connection/RMIConnector_NPETest.java fails Reviewed-by: lancea --- jdk/test/java/rmi/testlibrary/JavaVM.java | 19 ++++++++++++++++++- jdk/test/java/rmi/testlibrary/RMID.java | 2 +- .../connection/RMIConnector_NPETest.java | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/jdk/test/java/rmi/testlibrary/JavaVM.java b/jdk/test/java/rmi/testlibrary/JavaVM.java index a4345cb3e88..b304cd25213 100644 --- a/jdk/test/java/rmi/testlibrary/JavaVM.java +++ b/jdk/test/java/rmi/testlibrary/JavaVM.java @@ -194,7 +194,7 @@ public class JavaVM { throws InterruptedException, TimeoutException { if (vm == null) throw new IllegalStateException("can't wait for JavaVM that isn't running"); - long deadline = System.currentTimeMillis() + timeout; + long deadline = computeDeadline(System.currentTimeMillis(), timeout); while (true) { try { @@ -218,4 +218,21 @@ public class JavaVM { start(); return waitFor(); } + + /** + * Computes a deadline from a timestamp and a timeout value. + * Maximum timeout (before multipliers are applied) is one hour. + */ + public static long computeDeadline(long timestamp, long timeout) { + final long MAX_TIMEOUT_MS = 3_600_000L; + + if (timeout < 0L || timeout > MAX_TIMEOUT_MS) { + throw new IllegalArgumentException("timeout " + timeout + "ms out of range"); + } + + // TODO apply test.timeout.factor (and possibly jcov.sleep.multiplier) + // here instead of upstream + + return timestamp + timeout; + } } diff --git a/jdk/test/java/rmi/testlibrary/RMID.java b/jdk/test/java/rmi/testlibrary/RMID.java index 39e05b034bd..48fb49aa4d2 100644 --- a/jdk/test/java/rmi/testlibrary/RMID.java +++ b/jdk/test/java/rmi/testlibrary/RMID.java @@ -257,7 +257,7 @@ public class RMID extends JavaVM { waitTime = waitTime * slopFactor; long startTime = System.currentTimeMillis(); - long deadline = startTime + waitTime; + long deadline = computeDeadline(startTime, waitTime); while (true) { try { diff --git a/jdk/test/javax/management/remote/mandatory/connection/RMIConnector_NPETest.java b/jdk/test/javax/management/remote/mandatory/connection/RMIConnector_NPETest.java index c672296c11d..54af752e5c3 100644 --- a/jdk/test/javax/management/remote/mandatory/connection/RMIConnector_NPETest.java +++ b/jdk/test/javax/management/remote/mandatory/connection/RMIConnector_NPETest.java @@ -38,7 +38,7 @@ import javax.management.remote.rmi.*; public class RMIConnector_NPETest { public static void main(String argv[]) throws Exception { RMID rmid = RMID.createRMID(); - rmid.start(Long.MAX_VALUE); + rmid.start(); int rmidPort = rmid.getPort(); Exception failureCause = null; RMIConnector agent = null; From 294a85dbe7f02e98ca4a8abfe08a7d78190cd9a0 Mon Sep 17 00:00:00 2001 From: Erik Joelsson Date: Tue, 9 Dec 2014 08:43:06 +0100 Subject: [PATCH 09/12] 8066752: Remove space after -L on linker lines Reviewed-by: ihse --- jdk/make/lib/Awt2dLibraries.gmk | 14 +++++++------- jdk/make/lib/Lib-java.instrument.gmk | 4 ++-- jdk/make/lib/LibCommon.gmk | 4 +++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/jdk/make/lib/Awt2dLibraries.gmk b/jdk/make/lib/Awt2dLibraries.gmk index 08253f6d660..d4b1e8ce017 100644 --- a/jdk/make/lib/Awt2dLibraries.gmk +++ b/jdk/make/lib/Awt2dLibraries.gmk @@ -367,7 +367,7 @@ ifeq ($(findstring $(OPENJDK_TARGET_OS),windows macosx),) $(X_LIBS) $(LIBAWT_XAWT_LDFLAGS) \ $(call SET_SHARED_LIBRARY_ORIGIN) \ $(call SET_SHARED_LIBRARY_ORIGIN,/..) \ - -L $(INSTALL_LIBRARIES_HERE), \ + -L$(INSTALL_LIBRARIES_HERE), \ LDFLAGS_SUFFIX := $(LIBAWT_XAWT_LDFLAGS_SUFFIX), \ VERSIONINFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE), \ RC_FLAGS := $(RC_FLAGS) \ @@ -421,7 +421,7 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBLCMS, \ MAPFILE := $(JDK_TOPDIR)/make/mapfiles/liblcms/mapfile-vers, \ LDFLAGS := $(LDFLAGS_JDKLIB) \ $(call SET_SHARED_LIBRARY_ORIGIN), \ - LDFLAGS_unix := -L $(INSTALL_LIBRARIES_HERE), \ + LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \ LDFLAGS_solaris := /usr/lib$(OPENJDK_TARGET_CPU_ISADIR)/libm.so.2, \ LDFLAGS_windows := $(WIN_AWT_LIB) $(WIN_JAVA_LIB), \ LDFLAGS_SUFFIX_solaris := -lawt -ljava -ljvm -lc $(LCMS_LIBS), \ @@ -581,7 +581,7 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBFONTMANAGER, \ MAPFILE := $(BUILD_LIBFONTMANAGER_MAPFILE), \ LDFLAGS := $(subst -Xlinker -z -Xlinker defs,,$(LDFLAGS_JDKLIB)) $(LDFLAGS_CXX_JDK) \ $(call SET_SHARED_LIBRARY_ORIGIN), \ - LDFLAGS_unix := -L $(INSTALL_LIBRARIES_HERE), \ + LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \ LDFLAGS_SUFFIX := $(BUILD_LIBFONTMANAGER_FONTLIB), \ LDFLAGS_SUFFIX_linux := -lawt $(LIBM) $(LIBCXX) -ljava -ljvm -lc, \ LDFLAGS_SUFFIX_solaris := $(filter-out -R%, $(X_LIBS)) \ @@ -698,7 +698,7 @@ else # OPENJDK_TARGET_OS not windows MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libjawt/mapfile-vers, \ LDFLAGS := $(LDFLAGS_JDKLIB) \ $(call SET_SHARED_LIBRARY_ORIGIN), \ - LDFLAGS_unix := -L $(INSTALL_LIBRARIES_HERE), \ + LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \ LDFLAGS_solaris := $(X_LIBS), \ LDFLAGS_SUFFIX_linux := $(JAWT_LIBS) $(LDFLAGS_JDKLIB_SUFFIX), \ LDFLAGS_SUFFIX_aix := $(JAWT_LIBS) $(LDFLAGS_JDKLIB_SUFFIX),\ @@ -775,7 +775,7 @@ ifeq ($(BUILD_HEADLESS), true) MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libawt_headless/mapfile-vers, \ LDFLAGS := $(LDFLAGS_JDKLIB) \ $(call SET_SHARED_LIBRARY_ORIGIN), \ - LDFLAGS_unix := -L $(INSTALL_LIBRARIES_HERE), \ + LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \ LDFLAGS_linux := $(call SET_SHARED_LIBRARY_ORIGIN,/..), \ LDFLAGS_solaris := $(call SET_SHARED_LIBRARY_ORIGIN,/..), \ LDFLAGS_macosx := $(call SET_SHARED_LIBRARY_ORIGIN)., \ @@ -954,7 +954,7 @@ ifeq ($(OPENJDK_TARGET_OS), macosx) $(LIBAWT_LWAWT_CFLAGS), \ LDFLAGS := $(LDFLAGS_JDKLIB) \ $(call SET_SHARED_LIBRARY_ORIGIN) \ - -L $(INSTALL_LIBRARIES_HERE), \ + -L$(INSTALL_LIBRARIES_HERE), \ LDFLAGS_SUFFIX_macosx := -lawt -lmlib_image -losxapp -ljvm $(LIBM) \ -framework Accelerate \ -framework ApplicationServices \ @@ -1002,7 +1002,7 @@ ifeq ($(OPENJDK_TARGET_OS), macosx) LDFLAGS := $(LDFLAGS_JDKLIB) \ $(call SET_SHARED_LIBRARY_ORIGIN) \ -Xlinker -rpath -Xlinker @loader_path \ - -L $(INSTALL_LIBRARIES_HERE), \ + -L$(INSTALL_LIBRARIES_HERE), \ LDFLAGS_SUFFIX_macosx := -lawt -losxapp -lawt_lwawt \ -framework Cocoa \ -framework Carbon \ diff --git a/jdk/make/lib/Lib-java.instrument.gmk b/jdk/make/lib/Lib-java.instrument.gmk index 9799dadc1f6..4aaec5ce5e2 100644 --- a/jdk/make/lib/Lib-java.instrument.gmk +++ b/jdk/make/lib/Lib-java.instrument.gmk @@ -72,8 +72,8 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBINSTRUMENT, \ -framework Cocoa -framework Security -framework ApplicationServices, \ LDFLAGS_SUFFIX := $(LIBINSTRUMENT_LDFLAGS_SUFFIX), \ LDFLAGS_SUFFIX_macosx := -liconv $(LIBZ), \ - LDFLAGS_SUFFIX_solaris := $(LIBZ) -L $(call FindLibDirForModule, java.base)/jli -ljli $(LIBDL) -lc, \ - LDFLAGS_SUFFIX_linux := $(LIBZ) -L $(call FindLibDirForModule, java.base)/jli -ljli $(LIBDL), \ + LDFLAGS_SUFFIX_solaris := $(LIBZ) -L$(call FindLibDirForModule, java.base)/jli -ljli $(LIBDL) -lc, \ + LDFLAGS_SUFFIX_linux := $(LIBZ) -L$(call FindLibDirForModule, java.base)/jli -ljli $(LIBDL), \ LDFLAGS_SUFFIX_aix := $(LIBZ) -L$(SUPPORT_OUTPUTDIR)/native/java.base -ljli_static $(LIBDL),\ VERSIONINFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE), \ RC_FLAGS := $(RC_FLAGS) \ diff --git a/jdk/make/lib/LibCommon.gmk b/jdk/make/lib/LibCommon.gmk index e60e4d57d5b..f8eb27a1139 100644 --- a/jdk/make/lib/LibCommon.gmk +++ b/jdk/make/lib/LibCommon.gmk @@ -79,7 +79,9 @@ endif # Param 2 - library name # Param 3 - subdir for library define FindLib - $(call FindLibDirForModule, $(strip $1))$(strip $3)/$(LIBRARY_PREFIX)$(strip $2)$(SHARED_LIBRARY_SUFFIX) +$(strip \ + $(call FindLibDirForModule, $(strip $1))$(strip $3)/$(LIBRARY_PREFIX)$(strip $2)$(SHARED_LIBRARY_SUFFIX) \ +) endef ################################################################################ From 77e5c6eadf919f96420f36edc1b896cd38bb5434 Mon Sep 17 00:00:00 2001 From: Erik Joelsson Date: Tue, 9 Dec 2014 08:57:41 +0100 Subject: [PATCH 10/12] 8066761: Investigate -sourcepath usage when compiling java Removed all uses of -sourcepath Reviewed-by: jfranck, alanb, ihse --- jdk/make/CompileInterimRmic.gmk | 3 +-- jdk/make/gendata/GendataBreakIterator.gmk | 9 +-------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/jdk/make/CompileInterimRmic.gmk b/jdk/make/CompileInterimRmic.gmk index 003a4af73e7..f31db8dfd04 100644 --- a/jdk/make/CompileInterimRmic.gmk +++ b/jdk/make/CompileInterimRmic.gmk @@ -46,8 +46,7 @@ $(eval $(call SetupJavaCompilation,BUILD_INTERIM_RMIC, \ SRC := $(JDK_TOPDIR)/src/jdk.rmic/share/classes, \ INCLUDES := $(RMIC_PKGS), \ BIN := $(BUILDTOOLS_OUTPUTDIR)/interim_rmic_classes, \ - COPY := .properties, \ - JAVAC_SOURCE_PATH_OVERRIDE := $(addprefix $(JDK_TOPDIR)/src/jdk.rmic/share/classes/, $(RMIC_PKGS)))) + COPY := .properties)) ########################################################################################## diff --git a/jdk/make/gendata/GendataBreakIterator.gmk b/jdk/make/gendata/GendataBreakIterator.gmk index 1db16158e76..6c60ec26d6b 100644 --- a/jdk/make/gendata/GendataBreakIterator.gmk +++ b/jdk/make/gendata/GendataBreakIterator.gmk @@ -44,17 +44,10 @@ TEXT_SOURCES := $(TEXT_PKG)/BreakIteratorRules.java \ # Generate BreakIteratorData BREAK_ITERATOR_CLASSES := $(BUILDTOOLS_OUTPUTDIR)/break_iterator_classes -# JAVAC_SOURCE_PATH_OVERRIDE is set to isolate the compile to just those -# two files in that directory and not get anything implicit from -# surrounding directories which aren't jdk N-1 compatible. -# Because we are targeting jdk N-1, but the surrounding source code is jdk N. -# These two files should be moved out to a build tool! We have to disable -# sjavac here as well. +# These two files should be moved out to a build tool! $(eval $(call SetupJavaCompilation,BUILD_BREAKITERATOR, \ SETUP := GENERATE_OLDBYTECODE, \ SRC := $(TEXT_SRCDIR), \ - DISABLE_SJAVAC := true, \ - JAVAC_SOURCE_PATH_OVERRIDE := $(patsubst %, %/$(TEXT_PKG), $(TEXT_SRCDIR)), \ INCLUDES := $(TEXT_PKG), \ INCLUDE_FILES := $(TEXT_SOURCES), \ BIN := $(BREAK_ITERATOR_CLASSES))) From 26099e744a05fb6dfd8d73aeeae03ddf53ce1aee Mon Sep 17 00:00:00 2001 From: Weijun Wang Date: Tue, 9 Dec 2014 18:28:26 +0800 Subject: [PATCH 11/12] 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes Reviewed-by: valeriep --- .../classes/sun/security/krb5/Config.java | 72 +++++++- .../sun/security/krb5/Credentials.java | 19 ++ .../classes/sun/security/krb5/KrbAsReq.java | 33 +++- .../sun/security/krb5/KrbAsReqBuilder.java | 10 ++ .../classes/sun/security/krb5/KrbKdcRep.java | 38 ++-- .../classes/sun/security/krb5/KrbTgsReq.java | 1 - .../security/krb5/internal/HostAddresses.java | 4 + .../security/krb5/internal/KerberosTime.java | 9 + .../security/krb5/internal/tools/Kinit.java | 66 +++++-- .../krb5/internal/tools/KinitOptions.java | 60 ++++--- jdk/test/sun/security/krb5/auto/KDC.java | 27 ++- .../security/krb5/auto/LifeTimeInSeconds.java | 2 +- jdk/test/sun/security/krb5/auto/Renewal.java | 164 ++++++++++++++++++ .../sun/security/krb5/config/Duration.java | 71 ++++++++ 14 files changed, 494 insertions(+), 82 deletions(-) create mode 100644 jdk/test/sun/security/krb5/auto/Renewal.java create mode 100644 jdk/test/sun/security/krb5/config/Duration.java diff --git a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/Config.java b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/Config.java index 26722f2b885..30f5f67ccf2 100644 --- a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/Config.java +++ b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/Config.java @@ -30,19 +30,19 @@ */ package sun.security.krb5; -import java.io.File; -import java.io.FilePermission; +import java.io.*; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.Path; import java.security.PrivilegedAction; import java.util.*; -import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; import java.security.AccessController; import java.security.PrivilegedExceptionAction; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import sun.net.dns.ResolverConfiguration; import sun.security.krb5.internal.crypto.EType; @@ -314,6 +314,72 @@ public class Config { } } + /** + * Translates a duration value into seconds. + * + * The format can be one of "h:m[:s]", "NdNhNmNs", and "N". See + * http://web.mit.edu/kerberos/krb5-devel/doc/basic/date_format.html#duration + * for definitions. + * + * @param s the string duration + * @return time in seconds + * @throw KrbException if format is illegal + */ + public static int duration(String s) throws KrbException { + + if (s.isEmpty()) { + throw new KrbException("Duration cannot be empty"); + } + + // N + if (s.matches("\\d+")) { + return Integer.parseInt(s); + } + + // h:m[:s] + Matcher m = Pattern.compile("(\\d+):(\\d+)(:(\\d+))?").matcher(s); + if (m.matches()) { + int hr = Integer.parseInt(m.group(1)); + int min = Integer.parseInt(m.group(2)); + if (min >= 60) { + throw new KrbException("Illegal duration format " + s); + } + int result = hr * 3600 + min * 60; + if (m.group(4) != null) { + int sec = Integer.parseInt(m.group(4)); + if (sec >= 60) { + throw new KrbException("Illegal duration format " + s); + } + result += sec; + } + return result; + } + + // NdNhNmNs + // 120m allowed. Maybe 1h120m is not good, but still allowed + m = Pattern.compile( + "((\\d+)d)?\\s*((\\d+)h)?\\s*((\\d+)m)?\\s*((\\d+)s)?", + Pattern.CASE_INSENSITIVE).matcher(s); + if (m.matches()) { + int result = 0; + if (m.group(2) != null) { + result += 86400 * Integer.parseInt(m.group(2)); + } + if (m.group(4) != null) { + result += 3600 * Integer.parseInt(m.group(4)); + } + if (m.group(6) != null) { + result += 60 * Integer.parseInt(m.group(6)); + } + if (m.group(8) != null) { + result += Integer.parseInt(m.group(8)); + } + return result; + } + + throw new KrbException("Illegal duration format " + s); + } + /** * Gets the int value for the specified keys. * @param keys the keys diff --git a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/Credentials.java b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/Credentials.java index 25a93772422..4b72f4f01cc 100644 --- a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/Credentials.java +++ b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/Credentials.java @@ -527,4 +527,23 @@ public class Credentials { return sb.toString(); } + public sun.security.krb5.internal.ccache.Credentials toCCacheCreds() { + return new sun.security.krb5.internal.ccache.Credentials( + getClient(), getServer(), + getSessionKey(), + date2kt(getAuthTime()), + date2kt(getStartTime()), + date2kt(getEndTime()), + date2kt(getRenewTill()), + false, + flags, + new HostAddresses(getClientAddresses()), + getAuthzData(), + getTicket(), + null); + } + + private static KerberosTime date2kt(Date d) { + return d == null ? null : new KerberosTime(d); + } } diff --git a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbAsReq.java b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbAsReq.java index 8de29b346ae..01fdb9bbb33 100644 --- a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbAsReq.java +++ b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbAsReq.java @@ -35,6 +35,7 @@ import sun.security.krb5.internal.*; import sun.security.krb5.internal.crypto.Nonce; import sun.security.krb5.internal.crypto.KeyUsage; import java.io.IOException; +import java.time.Instant; /** * This class encapsulates the KRB-AS-REQ message that the client @@ -64,7 +65,6 @@ public class KrbAsReq { if (options == null) { options = new KDCOptions(); } - // check if they are valid arguments. The optional fields should be // consistent with settings in KDCOptions. Mar 17 2000 if (options.get(KDCOptions.FORWARDED) || @@ -82,12 +82,6 @@ public class KrbAsReq { } else { if (from != null) from = null; } - if (options.get(KDCOptions.RENEWABLE)) { - // if (rtime == null) - // throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS); - } else { - if (rtime != null) rtime = null; - } PAData[] paData = null; if (pakey != null) { @@ -109,8 +103,10 @@ public class KrbAsReq { System.out.println(">>> KrbAsReq creating message"); } + Config cfg = Config.getInstance(); + // check to use addresses in tickets - if (addresses == null && Config.getInstance().useAddresses()) { + if (addresses == null && cfg.useAddresses()) { addresses = HostAddresses.getLocalAddresses(); } @@ -120,7 +116,26 @@ public class KrbAsReq { } if (till == null) { - till = new KerberosTime(0); // Choose KDC maximum allowed + String d = cfg.get("libdefaults", "ticket_lifetime"); + if (d != null) { + till = new KerberosTime(Instant.now().plusSeconds(Config.duration(d))); + } else { + till = new KerberosTime(0); // Choose KDC maximum allowed + } + } + + if (rtime == null) { + String d = cfg.get("libdefaults", "renew_lifetime"); + if (d != null) { + rtime = new KerberosTime(Instant.now().plusSeconds(Config.duration(d))); + } + } + + if (rtime != null) { + options.set(KDCOptions.RENEWABLE, true); + if (till.greaterThan(rtime)) { + rtime = till; + } } // enc-authorization-data and additional-tickets never in AS-REQ diff --git a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbAsReqBuilder.java b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbAsReqBuilder.java index 3c8fb904017..5b6688000f7 100644 --- a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbAsReqBuilder.java +++ b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbAsReqBuilder.java @@ -224,6 +224,16 @@ public final class KrbAsReqBuilder { this.options = options; } + public void setTill(KerberosTime till) { + checkState(State.INIT, "Cannot specify till"); + this.till = till; + } + + public void setRTime(KerberosTime rtime) { + checkState(State.INIT, "Cannot specify rtime"); + this.rtime = rtime; + } + /** * Sets or clears target. If cleared, KrbAsReq might choose krbtgt * for cname realm diff --git a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbKdcRep.java b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbKdcRep.java index dd0e951028d..4c63fe1302c 100644 --- a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbKdcRep.java +++ b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbKdcRep.java @@ -80,49 +80,41 @@ abstract class KrbKdcRep { rep.encKDCRepPart.flags.get(KDCOptions.RENEWABLE)) { throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); } - if ((req.reqBody.from == null) || req.reqBody.from.isZero()) + + if ((req.reqBody.from == null) || req.reqBody.from.isZero()) { // verify this is allowed if ((rep.encKDCRepPart.starttime != null) && - !rep.encKDCRepPart.starttime.inClockSkew()) { + !rep.encKDCRepPart.starttime.inClockSkew()) { rep.encKDCRepPart.key.destroy(); throw new KrbApErrException(Krb5.KRB_AP_ERR_SKEW); } + } - if ((req.reqBody.from != null) && !req.reqBody.from.isZero()) + if ((req.reqBody.from != null) && !req.reqBody.from.isZero()) { // verify this is allowed if ((rep.encKDCRepPart.starttime != null) && - !req.reqBody.from.equals(rep.encKDCRepPart.starttime)) { + !req.reqBody.from.equals(rep.encKDCRepPart.starttime)) { rep.encKDCRepPart.key.destroy(); throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); } + } if (!req.reqBody.till.isZero() && - rep.encKDCRepPart.endtime.greaterThan(req.reqBody.till)) { + rep.encKDCRepPart.endtime.greaterThan(req.reqBody.till)) { rep.encKDCRepPart.key.destroy(); throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); } - if (req.reqBody.kdcOptions.get(KDCOptions.RENEWABLE)) - if (req.reqBody.rtime != null && !req.reqBody.rtime.isZero()) - // verify this is required + if (req.reqBody.kdcOptions.get(KDCOptions.RENEWABLE)) { + if (req.reqBody.rtime != null && !req.reqBody.rtime.isZero()) { + // verify this is required if ((rep.encKDCRepPart.renewTill == null) || - rep.encKDCRepPart.renewTill.greaterThan(req.reqBody.rtime) - ) { - rep.encKDCRepPart.key.destroy(); - throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); - } - - if (req.reqBody.kdcOptions.get(KDCOptions.RENEWABLE_OK) && - rep.encKDCRepPart.flags.get(KDCOptions.RENEWABLE)) - if (!req.reqBody.till.isZero()) - // verify this is required - if ((rep.encKDCRepPart.renewTill == null) || - rep.encKDCRepPart.renewTill.greaterThan(req.reqBody.till) - ) { + rep.encKDCRepPart.renewTill.greaterThan(req.reqBody.rtime) + ) { rep.encKDCRepPart.key.destroy(); throw new KrbApErrException(Krb5.KRB_AP_ERR_MODIFIED); } + } + } } - - } diff --git a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbTgsReq.java b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbTgsReq.java index 798b78d3e63..45f25e825ce 100644 --- a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbTgsReq.java +++ b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/KrbTgsReq.java @@ -35,7 +35,6 @@ import sun.security.krb5.internal.*; import sun.security.krb5.internal.crypto.*; import java.io.IOException; import java.net.UnknownHostException; -import java.util.Arrays; /** * This class encapsulates a Kerberos TGS-REQ that is sent from the diff --git a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/internal/HostAddresses.java b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/internal/HostAddresses.java index 8dc9a2853e1..7f18b98f9c3 100644 --- a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/internal/HostAddresses.java +++ b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/internal/HostAddresses.java @@ -250,6 +250,10 @@ public class HostAddresses implements Cloneable { */ public void writeAddrs(CCacheOutputStream cos) throws IOException { + if (addresses == null || addresses.length == 0) { + cos.write32(0); + return; + } cos.write32(addresses.length); for (int i = 0; i < addresses.length; i++) { cos.write16(addresses[i].addrType); diff --git a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/internal/KerberosTime.java b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/internal/KerberosTime.java index 264f2e06192..da30f9dc42c 100644 --- a/jdk/src/java.security.jgss/share/classes/sun/security/krb5/internal/KerberosTime.java +++ b/jdk/src/java.security.jgss/share/classes/sun/security/krb5/internal/KerberosTime.java @@ -38,6 +38,7 @@ import sun.security.util.DerOutputStream; import sun.security.util.DerValue; import java.io.IOException; +import java.time.Instant; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; @@ -128,6 +129,14 @@ public class KerberosTime { this(time.getTime(), 0); } + /** + * Creates a KerberosTime object from an Instant object + */ + public KerberosTime(Instant instant) { + this(instant.getEpochSecond()*1000 + instant.getNano()/1000000L, + instant.getNano()/1000%1000); + } + /** * Creates a KerberosTime object for now. It uses System.nanoTime() * to get a more precise time than "new Date()". diff --git a/jdk/src/java.security.jgss/windows/classes/sun/security/krb5/internal/tools/Kinit.java b/jdk/src/java.security.jgss/windows/classes/sun/security/krb5/internal/tools/Kinit.java index a436d585cba..5839a5e13e4 100644 --- a/jdk/src/java.security.jgss/windows/classes/sun/security/krb5/internal/tools/Kinit.java +++ b/jdk/src/java.security.jgss/windows/classes/sun/security/krb5/internal/tools/Kinit.java @@ -36,7 +36,6 @@ import sun.security.krb5.internal.*; import sun.security.krb5.internal.ccache.*; import java.io.IOException; import java.util.Arrays; -import javax.security.auth.kerberos.KerberosPrincipal; import sun.security.util.Password; import javax.security.auth.kerberos.KeyTab; @@ -53,22 +52,9 @@ public class Kinit { /** * The main method is used to accept user command line input for ticket - * request. - *

- * Usage: kinit [-A] [-f] [-p] [-c cachename] [[-k [-t keytab_file_name]] - * [principal] [password] - *

    - *
  • -A do not include addresses - *
  • -f forwardable - *
  • -p proxiable - *
  • -c cache name (i.e., FILE://c:\temp\mykrb5cc) - *
  • -k use keytab - *
  • -t keytab file name - *
  • principal the principal name (i.e., duke@java.sun.com) - *
  • password the principal's Kerberos password - *
- *

- * Use java sun.security.krb5.tools.Kinit -help to bring up help menu. + * request. Read {@link KinitOptions#printHelp} for usages or call + * java sun.security.krb5.internal.tools.Kinit -help + * to bring up help menu. *

* We currently support only file-based credentials cache to * store the tickets obtained from the KDC. @@ -146,6 +132,49 @@ public class Kinit { } else { options = new KinitOptions(args); } + switch (options.action) { + case 1: + acquire(); + break; + case 2: + renew(); + break; + default: + throw new KrbException("kinit does not support action " + + options.action); + } + } + + private void renew() + throws IOException, RealmException, KrbException { + + PrincipalName principal = options.getPrincipal(); + String realm = principal.getRealmAsString(); + CredentialsCache cache = CredentialsCache.getInstance(options.cachename); + + if (cache == null) { + throw new IOException("Unable to find existing cache file " + + options.cachename); + } + sun.security.krb5.internal.ccache.Credentials credentials = + cache.getCreds(PrincipalName.tgsService(realm, realm)); + + credentials = credentials.setKrbCreds() + .renew() + .toCCacheCreds(); + + cache = CredentialsCache.create(principal, options.cachename); + if (cache == null) { + throw new IOException("Unable to create the cache file " + + options.cachename); + } + cache.update(credentials); + cache.save(); + } + + private void acquire() + throws IOException, RealmException, KrbException { + String princName = null; PrincipalName principal = options.getPrincipal(); if (principal != null) { @@ -216,6 +245,9 @@ public class Kinit { if (options.getAddressOption()) builder.setAddresses(HostAddresses.getLocalAddresses()); + builder.setTill(options.lifetime); + builder.setRTime(options.renewable_lifetime); + builder.action(); sun.security.krb5.internal.ccache.Credentials credentials = diff --git a/jdk/src/java.security.jgss/windows/classes/sun/security/krb5/internal/tools/KinitOptions.java b/jdk/src/java.security.jgss/windows/classes/sun/security/krb5/internal/tools/KinitOptions.java index e7507a0a27f..23bfecad837 100644 --- a/jdk/src/java.security.jgss/windows/classes/sun/security/krb5/internal/tools/KinitOptions.java +++ b/jdk/src/java.security.jgss/windows/classes/sun/security/krb5/internal/tools/KinitOptions.java @@ -33,12 +33,8 @@ package sun.security.krb5.internal.tools; import sun.security.krb5.*; import sun.security.krb5.internal.*; import sun.security.krb5.internal.ccache.*; -import java.io.File; import java.io.IOException; -import java.util.StringTokenizer; -import java.util.Vector; -import java.io.BufferedReader; -import java.io.InputStreamReader; +import java.time.Instant; import java.io.FileInputStream; /** @@ -49,14 +45,15 @@ import java.io.FileInputStream; * @author Ram Marti */ class KinitOptions { - public boolean validate = false; + + // 1. acquire, 2. renew, 3. validate + public int action = 1; // forwardable and proxiable flags have two states: // -1 - flag set to be not forwardable or proxiable; // 1 - flag set to be forwardable or proxiable. - public short forwardable = -1; - public short proxiable = -1; - public boolean renew = false; + public short forwardable = 0; + public short proxiable = 0; public KerberosTime lifetime; public KerberosTime renewable_lifetime; public String target_service; @@ -134,6 +131,12 @@ class KinitOptions { } useKeytab = true; + } else if (args[i].equals("-R")) { + action = 2; + } else if (args[i].equals("-l")) { + lifetime = getTime(Config.duration(args[++i])); + } else if (args[i].equals("-r")) { + renewable_lifetime = getTime(Config.duration(args[++i])); } else if (args[i].equalsIgnoreCase("-help")) { printHelp(); System.exit(0); @@ -223,23 +226,28 @@ class KinitOptions { void printHelp() { - System.out.println("Usage: kinit " + - "[-A] [-f] [-p] [-c cachename] " + - "[[-k [-t keytab_file_name]] [principal] " + + System.out.println("Usage:\n\n1. Initial ticket request:\n" + + " kinit [-A] [-f] [-p] [-c cachename] " + + "[-l lifetime] [-r renewable_time]\n" + + " [[-k [-t keytab_file_name]] [principal] " + "[password]"); - System.out.println("\tavailable options to " + + System.out.println("2. Renew a ticket:\n" + + " kinit -R [-c cachename] [principal]"); + System.out.println("\nAvailable options to " + "Kerberos 5 ticket request:"); - System.out.println("\t -A do not include addresses"); - System.out.println("\t -f forwardable"); - System.out.println("\t -p proxiable"); - System.out.println("\t -c cache name " + - "(i.e., FILE:\\d:\\myProfiles\\mykrb5cache)"); - System.out.println("\t -k use keytab"); - System.out.println("\t -t keytab file name"); - System.out.println("\t principal the principal name "+ - "(i.e., qweadf@ATHENA.MIT.EDU qweadf)"); - System.out.println("\t password " + - "the principal's Kerberos password"); + System.out.println("\t-A do not include addresses"); + System.out.println("\t-f forwardable"); + System.out.println("\t-p proxiable"); + System.out.println("\t-c cache name " + + "(i.e., FILE:\\d:\\myProfiles\\mykrb5cache)"); + System.out.println("\t-l lifetime"); + System.out.println("\t-r renewable time " + + "(total lifetime a ticket can be renewed)"); + System.out.println("\t-k use keytab"); + System.out.println("\t-t keytab file name"); + System.out.println("\tprincipal the principal name "+ + "(i.e., qweadf@ATHENA.MIT.EDU qweadf)"); + System.out.println("\tpassword the principal's Kerberos password"); } public boolean getAddressOption() { @@ -257,4 +265,8 @@ class KinitOptions { public PrincipalName getPrincipal() { return principal; } + + private KerberosTime getTime(int s) { + return new KerberosTime(Instant.now().plusSeconds(s)); + } } diff --git a/jdk/test/sun/security/krb5/auto/KDC.java b/jdk/test/sun/security/krb5/auto/KDC.java index 686e238579e..1b2814daf29 100644 --- a/jdk/test/sun/security/krb5/auto/KDC.java +++ b/jdk/test/sun/security/krb5/auto/KDC.java @@ -35,6 +35,7 @@ import sun.net.spi.nameservice.NameServiceDescriptor; import sun.security.krb5.*; import sun.security.krb5.internal.*; import sun.security.krb5.internal.ccache.CredentialsCache; +import sun.security.krb5.internal.crypto.EType; import sun.security.krb5.internal.crypto.KeyUsage; import sun.security.krb5.internal.ktab.KeyTab; import sun.security.util.DerInputStream; @@ -120,6 +121,9 @@ import sun.security.util.DerValue; */ public class KDC { + public static final int DEFAULT_LIFETIME = 39600; + public static final int DEFAULT_RENEWTIME = 86400; + // Under the hood. // The random generator to generate random keys (including session keys) @@ -204,7 +208,8 @@ public class KDC { * A standalone KDC server. */ public static void main(String[] args) throws Exception { - KDC kdc = create("RABBIT.HOLE", "kdc.rabbit.hole", 0, false); + int port = args.length > 0 ? Integer.parseInt(args[0]) : 0; + KDC kdc = create("RABBIT.HOLE", "kdc.rabbit.hole", port, false); kdc.addPrincipal("dummy", "bogus".toCharArray()); kdc.addPrincipal("foo", "bar".toCharArray()); kdc.addPrincipalRandKey("krbtgt/RABBIT.HOLE"); @@ -871,6 +876,14 @@ public class KDC { eTypes = KDCReqBodyDotEType(body); int eType = eTypes[0]; + // Maybe server does not support aes256, but a kinit does + if (!EType.isSupported(eType)) { + if (eTypes.length < 2) { + throw new KrbException(Krb5.KDC_ERR_ETYPE_NOSUPP); + } + eType = eTypes[1]; + } + EncryptionKey ckey = keyForUser(body.cname, eType, false); EncryptionKey skey = keyForUser(service, eType, true); @@ -899,10 +912,16 @@ public class KDC { EncryptionKey key = generateRandomKey(eType); // Check time, TODO KerberosTime till = body.till; + KerberosTime rtime = body.rtime; if (till == null) { throw new KrbException(Krb5.KDC_ERR_NEVER_VALID); // TODO } else if (till.isZero()) { - till = new KerberosTime(new Date().getTime() + 1000 * 3600 * 11); + till = new KerberosTime( + new Date().getTime() + 1000 * DEFAULT_LIFETIME); + } + if (rtime == null && body.kdcOptions.get(KDCOptions.RENEWABLE)) { + rtime = new KerberosTime( + new Date().getTime() + 1000 * DEFAULT_RENEWTIME); } //body.from boolean[] bFlags = new boolean[Krb5.TKT_OPTS_MAX+1]; @@ -1053,7 +1072,7 @@ public class KDC { new TransitedEncoding(1, new byte[0]), new KerberosTime(new Date()), body.from, - till, body.rtime, + till, rtime, body.addresses, null); Ticket t = new Ticket( @@ -1071,7 +1090,7 @@ public class KDC { tFlags, new KerberosTime(new Date()), body.from, - till, body.rtime, + till, rtime, service, body.addresses ); diff --git a/jdk/test/sun/security/krb5/auto/LifeTimeInSeconds.java b/jdk/test/sun/security/krb5/auto/LifeTimeInSeconds.java index 9c518ff6cbb..961990bdda7 100644 --- a/jdk/test/sun/security/krb5/auto/LifeTimeInSeconds.java +++ b/jdk/test/sun/security/krb5/auto/LifeTimeInSeconds.java @@ -40,7 +40,7 @@ public class LifeTimeInSeconds { int time = cred.getRemainingLifetime(); int time2 = cred.getRemainingInitLifetime(null); // The test KDC issues a TGT with a default lifetime of 11 hours - int elevenhrs = 11*3600; + int elevenhrs = KDC.DEFAULT_LIFETIME; if (time > elevenhrs+60 || time < elevenhrs-60) { throw new Exception("getRemainingLifetime returns wrong value."); } diff --git a/jdk/test/sun/security/krb5/auto/Renewal.java b/jdk/test/sun/security/krb5/auto/Renewal.java new file mode 100644 index 00000000000..fc9ab80e0d3 --- /dev/null +++ b/jdk/test/sun/security/krb5/auto/Renewal.java @@ -0,0 +1,164 @@ +/* + * 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 8044500 + * @summary Add kinit options and krb5.conf flags that allow users to + * obtain renewable tickets and specify ticket lifetimes + * @library ../../../../java/security/testlibrary/ + * @compile -XDignore.symbol.file Renewal.java + * @run main/othervm Renewal + */ + +import sun.security.jgss.GSSUtil; +import sun.security.krb5.Config; +import sun.security.krb5.internal.ccache.Credentials; +import sun.security.krb5.internal.ccache.FileCredentialsCache; + +import javax.security.auth.kerberos.KerberosTicket; +import java.util.Date; +import java.util.Random; +import java.util.Set; + +// The basic krb5 test skeleton you can copy from +public class Renewal { + + static OneKDC kdc; + static String clazz = "sun.security.krb5.internal.tools.Kinit"; + + public static void main(String[] args) throws Exception { + + kdc = new OneKDC(null); + kdc.writeJAASConf(); + kdc.setOption(KDC.Option.PREAUTH_REQUIRED, false); + + checkLogin(null, null, KDC.DEFAULT_LIFETIME, -1); + checkLogin("1h", null, 3600, -1); + checkLogin(null, "2d", KDC.DEFAULT_LIFETIME, 86400*2); + checkLogin("1h", "10h", 3600, 36000); + // When rtime is before till, use till as rtime + checkLogin("10h", "1h", 36000, 36000); + + try { + Class.forName(clazz); + } catch (ClassNotFoundException cnfe) { + return; + } + + checkKinit(null, null, null, null, KDC.DEFAULT_LIFETIME, -1); + checkKinit("1h", "10h", null, null, 3600, 36000); + checkKinit(null, null, "30m", "5h", 1800, 18000); + checkKinit("1h", "10h", "30m", "5h", 1800, 18000); + + checkKinitRenew(); + } + + static int count = 0; + + static void checkKinit( + String s1, // ticket_lifetime in krb5.conf, null if none + String s2, // renew_lifetime in krb5.conf, null if none + String c1, // -l on kinit, null if none + String c2, // -r on kinit, null if none + int t1, int t2 // expected lifetimes, -1 of unexpected + ) throws Exception { + KDC.saveConfig(OneKDC.KRB5_CONF, kdc, + s1 != null ? ("ticket_lifetime = " + s1) : "", + s2 != null ? ("renew_lifetime = " + s2) : ""); + Proc p = Proc.create(clazz); + if (c1 != null) { + p.args("-l", c1); + } + if (c2 != null) { + p.args("-r", c2); + } + count++; + p.args(OneKDC.USER, new String(OneKDC.PASS)) + .inheritIO() + .prop("sun.net.spi.nameservice.provider.1", "ns,mock") + .prop("java.security.krb5.conf", OneKDC.KRB5_CONF) + .env("KRB5CCNAME", "ccache" + count) + .start(); + if (p.waitFor() != 0) { + throw new Exception(); + } + FileCredentialsCache fcc = + FileCredentialsCache.acquireInstance(null, "ccache" + count); + Credentials cred = fcc.getDefaultCreds(); + checkRough(cred.getEndTime().toDate(), t1); + if (cred.getRenewTill() == null) { + checkRough(null, t2); + } else { + checkRough(cred.getRenewTill().toDate(), t2); + } + } + + static void checkKinitRenew() throws Exception { + Proc p = Proc.create(clazz) + .args("-R") + .inheritIO() + .prop("sun.net.spi.nameservice.provider.1", "ns,mock") + .prop("java.security.krb5.conf", OneKDC.KRB5_CONF) + .env("KRB5CCNAME", "ccache" + count) + .start(); + if (p.waitFor() != 0) { + throw new Exception(); + } + } + + static void checkLogin( + String s1, // ticket_lifetime in krb5.conf, null if none + String s2, // renew_lifetime in krb5.conf, null if none + int t1, int t2 // expected lifetimes, -1 of unexpected + ) throws Exception { + KDC.saveConfig(OneKDC.KRB5_CONF, kdc, + s1 != null ? ("ticket_lifetime = " + s1) : "", + s2 != null ? ("renew_lifetime = " + s2) : ""); + Config.refresh(); + + Context c; + c = Context.fromJAAS("client"); + + Set tickets = + c.s().getPrivateCredentials(KerberosTicket.class); + if (tickets.size() != 1) { + throw new Exception(); + } + KerberosTicket ticket = tickets.iterator().next(); + + checkRough(ticket.getEndTime(), t1); + checkRough(ticket.getRenewTill(), t2); + } + + static void checkRough(Date t, int duration) throws Exception { + Date now = new Date(); + if (t == null && duration == -1) { + return; + } + long change = (t.getTime() - System.currentTimeMillis()) / 1000; + if (change > duration + 20 || change < duration - 20) { + throw new Exception(t + " is not " + duration); + } + } +} diff --git a/jdk/test/sun/security/krb5/config/Duration.java b/jdk/test/sun/security/krb5/config/Duration.java new file mode 100644 index 00000000000..d9c0f3961c7 --- /dev/null +++ b/jdk/test/sun/security/krb5/config/Duration.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 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 + * 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 8044500 + * @summary Add kinit options and krb5.conf flags that allow users to + * obtain renewable tickets and specify ticket lifetimes + * @compile -XDignore.symbol.file Duration.java + * @run main Duration + */ +import sun.security.krb5.Config; +import sun.security.krb5.KrbException; + +public class Duration { + public static void main(String[] args) throws Exception { + check("123", 123); + check("1:1", 3660); + check("1:1:1", 3661); + check("1d", 86400); + check("1h", 3600); + check("1h1m", 3660); + check("1h 1m", 3660); + check("1d 1h 1m 1s", 90061); + check("1d1h1m1s", 90061); + + check("", -1); + check("abc", -1); + check("1ms", -1); + check("1d1d", -1); + check("1h1d", -1); + check("x1h", -1); + check("1h x 1m", -1); + check(":", -1); + check("1:60", -1); + check("1:1:1:1", -1); + check("1:1:1:", -1); + } + + static void check(String s, int ex) throws Exception { + System.out.print("\u001b[1;37;41m" +s + " " + ex); + System.out.print("\u001b[m\n"); + try { + int result = Config.duration(s); + if (result != ex) throw new Exception("for " + s + " is " + result); + } catch (KrbException ke) { + ke.printStackTrace(); + if (ex != -1) throw new Exception(); + } + } +} From e0eba41e1c3ca7beccd340c5a6bb7b34d4ccd79b Mon Sep 17 00:00:00 2001 From: Vladimir Ivanov Date: Tue, 9 Dec 2014 09:22:07 -0800 Subject: [PATCH 12/12] 8066746: MHs.explicitCastArguments does incorrect type checks for VarargsCollector Reviewed-by: jrose, psandoz --- .../java/lang/invoke/MethodHandles.java | 2 +- .../invoke/ExplicitCastArgumentsTest.java | 21 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java index 0fe5a897417..eda6a6d27df 100644 --- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java +++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java @@ -2028,7 +2028,7 @@ return invoker; MethodType oldType = target.type(); if (oldType == newType) return target; if (oldType.explicitCastEquivalentToAsType(newType)) { - return target.asType(newType); + return target.asFixedArity().asType(newType); } return MethodHandleImpl.makePairwiseConvert(target, newType, false); } diff --git a/jdk/test/java/lang/invoke/ExplicitCastArgumentsTest.java b/jdk/test/java/lang/invoke/ExplicitCastArgumentsTest.java index 06f7a64aabd..045ec15599e 100644 --- a/jdk/test/java/lang/invoke/ExplicitCastArgumentsTest.java +++ b/jdk/test/java/lang/invoke/ExplicitCastArgumentsTest.java @@ -32,21 +32,36 @@ import sun.invoke.util.Wrapper; */ public class ExplicitCastArgumentsTest { private static final boolean VERBOSE = Boolean.getBoolean("verbose"); + private static final Class THIS_CLASS = ExplicitCastArgumentsTest.class; public static void main(String[] args) throws Throwable { + testVarargsCollector(); + testRef2Prim(); + System.out.println("TEST PASSED"); + } + + public static String[] f(String... args) { return args; } + + public static void testVarargsCollector() throws Throwable { + MethodType mt = MethodType.methodType(String[].class, String[].class); + MethodHandle mh = MethodHandles.publicLookup().findStatic(THIS_CLASS, "f", mt); + mh = MethodHandles.explicitCastArguments(mh, MethodType.methodType(Object.class, Object.class)); + mh.invokeWithArguments((Object)(new String[] {"str1", "str2"})); + } + + public static void testRef2Prim() throws Throwable { for (Wrapper from : Wrapper.values()) { for (Wrapper to : Wrapper.values()) { if (from == Wrapper.VOID || to == Wrapper.VOID) continue; - testRef2Prim (from, to); + testRef2Prim(from, to); } } - System.out.println("TEST PASSED"); } public static void testRef2Prim(Wrapper from, Wrapper to) throws Throwable { // MHs.eCA javadoc: // If T0 is a reference and T1 a primitive, and if the reference is null at runtime, a zero value is introduced. - test(from.wrapperType(), to.primitiveType(), null, false); + test(from.wrapperType(), to.primitiveType(), null, false); } public static void test(Class from, Class to, Object param, boolean failureExpected) throws Throwable {