OpenJDK / jdk / jdk
changeset 23636:e8579a943a6f
Merge
author | prr |
---|---|
date | Tue, 11 Mar 2014 10:46:38 -0700 |
parents | 71c09f77edb5 0a84d339822a |
children | b27b1c3beeb2 |
files | |
diffstat | 8 files changed, 263 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/jdk/src/share/classes/java/lang/invoke/MethodHandleImpl.java Tue Mar 11 19:28:11 2014 +0400 +++ b/jdk/src/share/classes/java/lang/invoke/MethodHandleImpl.java Tue Mar 11 10:46:38 2014 -0700 @@ -736,16 +736,17 @@ @LambdaForm.Hidden static Object guardWithCatch(MethodHandle target, Class<? extends Throwable> exType, MethodHandle catcher, Object... av) throws Throwable { + // Use asFixedArity() to avoid unnecessary boxing of last argument for VarargsCollector case. try { - return target.invokeWithArguments(av); + return target.asFixedArity().invokeWithArguments(av); } catch (Throwable t) { if (!exType.isInstance(t)) throw t; - Object[] args = prepend(t, av); - return catcher.invokeWithArguments(args); + return catcher.asFixedArity().invokeWithArguments(prepend(t, av)); } } /** Prepend an element {@code elem} to an {@code array}. */ + @LambdaForm.Hidden private static Object[] prepend(Object elem, Object[] array) { Object[] newArray = new Object[array.length+1]; newArray[0] = elem;
--- a/jdk/src/share/classes/sun/security/krb5/Config.java Tue Mar 11 19:28:11 2014 +0400 +++ b/jdk/src/share/classes/sun/security/krb5/Config.java Tue Mar 11 10:46:38 2014 -0700 @@ -549,12 +549,11 @@ previous = line.substring(1).trim(); } } else { - if (previous == null) { - throw new KrbException( - "Config file must starts with a section"); + // Lines before the first section are ignored + if (previous != null) { + v.add(previous); + previous = line; } - v.add(previous); - previous = line; } } if (previous != null) {
--- a/jdk/src/share/native/sun/security/pkcs11/j2secmod.c Tue Mar 11 19:28:11 2014 +0400 +++ b/jdk/src/share/native/sun/security/pkcs11/j2secmod.c Tue Mar 11 10:46:38 2014 -0700 @@ -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 @@ -30,20 +30,27 @@ // #define SECMOD_DEBUG #include "j2secmod.h" +#include "jni_util.h" JNIEXPORT jboolean JNICALL Java_sun_security_pkcs11_Secmod_nssVersionCheck (JNIEnv *env, jclass thisClass, jlong jHandle, jstring jVersion) { - const char *requiredVersion = (*env)->GetStringUTFChars(env, jVersion, NULL); - int res; - FPTR_VersionCheck versionCheck = - (FPTR_VersionCheck)findFunction(env, jHandle, "NSS_VersionCheck"); + int res = 0; + FPTR_VersionCheck versionCheck; + const char *requiredVersion; + versionCheck = (FPTR_VersionCheck)findFunction(env, jHandle, + "NSS_VersionCheck"); if (versionCheck == NULL) { return JNI_FALSE; } + requiredVersion = (*env)->GetStringUTFChars(env, jVersion, NULL); + if (requiredVersion == NULL) { + return JNI_FALSE; + } + res = versionCheck(requiredVersion); dprintf2("-version >=%s: %d\n", requiredVersion, res); (*env)->ReleaseStringUTFChars(env, jVersion, requiredVersion); @@ -59,55 +66,73 @@ JNIEXPORT jboolean JNICALL Java_sun_security_pkcs11_Secmod_nssInitialize (JNIEnv *env, jclass thisClass, jstring jFunctionName, jlong jHandle, jstring jConfigDir, jboolean jNssOptimizeSpace) { - const char *functionName = - (*env)->GetStringUTFChars(env, jFunctionName, NULL); - const char *configDir = (jConfigDir == NULL) - ? NULL : (*env)->GetStringUTFChars(env, jConfigDir, NULL); + int res = 0; FPTR_Initialize initialize = (FPTR_Initialize)findFunction(env, jHandle, "NSS_Initialize"); - int res = 0; unsigned int flags = 0x00; + const char *configDir = NULL; + const char *functionName = NULL; + + /* If we cannot initialize, exit now */ + if (initialize == NULL) { + res = 1; + goto cleanup; + } + + functionName = (*env)->GetStringUTFChars(env, jFunctionName, NULL); + if (functionName == NULL) { + res = 1; + goto cleanup; + } + + if (jConfigDir != NULL) { + configDir = (*env)->GetStringUTFChars(env, jConfigDir, NULL); + if (!configDir) { + res = 1; + goto cleanup; + } + } if (jNssOptimizeSpace == JNI_TRUE) { flags = 0x20; // NSS_INIT_OPTIMIZESPACE flag } - if (initialize != NULL) { - /* - * If the NSS_Init function is requested then call NSS_Initialize to - * open the Cert, Key and Security Module databases, read only. - */ - if (strcmp("NSS_Init", functionName) == 0) { - flags = flags | 0x01; // NSS_INIT_READONLY flag - res = initialize(configDir, "", "", "secmod.db", flags); + /* + * If the NSS_Init function is requested then call NSS_Initialize to + * open the Cert, Key and Security Module databases, read only. + */ + if (strcmp("NSS_Init", functionName) == 0) { + flags = flags | 0x01; // NSS_INIT_READONLY flag + res = initialize(configDir, "", "", "secmod.db", flags); - /* - * If the NSS_InitReadWrite function is requested then call - * NSS_Initialize to open the Cert, Key and Security Module databases, - * read/write. - */ - } else if (strcmp("NSS_InitReadWrite", functionName) == 0) { - res = initialize(configDir, "", "", "secmod.db", flags); + /* + * If the NSS_InitReadWrite function is requested then call + * NSS_Initialize to open the Cert, Key and Security Module databases, + * read/write. + */ + } else if (strcmp("NSS_InitReadWrite", functionName) == 0) { + res = initialize(configDir, "", "", "secmod.db", flags); - /* - * If the NSS_NoDB_Init function is requested then call - * NSS_Initialize without creating Cert, Key or Security Module - * databases. - */ - } else if (strcmp("NSS_NoDB_Init", functionName) == 0) { - flags = flags | 0x02 // NSS_INIT_NOCERTDB flag - | 0x04 // NSS_INIT_NOMODDB flag - | 0x08 // NSS_INIT_FORCEOPEN flag - | 0x10; // NSS_INIT_NOROOTINIT flag - res = initialize("", "", "", "", flags); + /* + * If the NSS_NoDB_Init function is requested then call + * NSS_Initialize without creating Cert, Key or Security Module + * databases. + */ + } else if (strcmp("NSS_NoDB_Init", functionName) == 0) { + flags = flags | 0x02 // NSS_INIT_NOCERTDB flag + | 0x04 // NSS_INIT_NOMODDB flag + | 0x08 // NSS_INIT_FORCEOPEN flag + | 0x10; // NSS_INIT_NOROOTINIT flag + res = initialize("", "", "", "", flags); - } else { - res = 2; - } } else { - res = 1; + res = 2; } - (*env)->ReleaseStringUTFChars(env, jFunctionName, functionName); + +cleanup: + if (functionName != NULL) { + (*env)->ReleaseStringUTFChars(env, jFunctionName, functionName); + } if (configDir != NULL) { (*env)->ReleaseStringUTFChars(env, jConfigDir, configDir); } @@ -142,13 +167,30 @@ } jListClass = (*env)->FindClass(env, "java/util/ArrayList"); + if (jListClass == NULL) { + return NULL; + } jListConstructor = (*env)->GetMethodID(env, jListClass, "<init>", "()V"); + if (jListConstructor == NULL) { + return NULL; + } jAdd = (*env)->GetMethodID(env, jListClass, "add", "(Ljava/lang/Object;)Z"); + if (jAdd == NULL) { + return NULL; + } jList = (*env)->NewObject(env, jListClass, jListConstructor); - + if (jList == NULL) { + return NULL; + } jModuleClass = (*env)->FindClass(env, "sun/security/pkcs11/Secmod$Module"); + if (jModuleClass == NULL) { + return NULL; + } jModuleConstructor = (*env)->GetMethodID(env, jModuleClass, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZI)V"); + if (jModuleConstructor == NULL) { + return NULL; + } while (list != NULL) { module = list->module; @@ -160,16 +202,28 @@ dprintf1("-internal: %d\n", module->internal); dprintf1("-fips: %d\n", module->isFIPS); jCommonName = (*env)->NewStringUTF(env, module->commonName); + if (jCommonName == NULL) { + return NULL; + } if (module->dllName == NULL) { jDllName = NULL; } else { jDllName = (*env)->NewStringUTF(env, module->dllName); + if (jDllName == NULL) { + return NULL; + } } jFIPS = module->isFIPS; for (i = 0; i < module->slotCount; i++ ) { jModule = (*env)->NewObject(env, jModuleClass, jModuleConstructor, jLibDir, jDllName, jCommonName, jFIPS, i); + if (jModule == NULL) { + return NULL; + } (*env)->CallVoidMethod(env, jList, jAdd, jModule); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } } list = list->next; }
--- a/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.c Tue Mar 11 19:28:11 2014 +0400 +++ b/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.c Tue Mar 11 10:46:38 2014 -0700 @@ -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 @@ -50,6 +50,10 @@ (JNIEnv *env, jclass thisClass, jstring jLibName) { const char *libName = (*env)->GetStringUTFChars(env, jLibName, NULL); + if (libName == NULL) { + return 0L; + } + // look up existing handle only, do not load #if defined(AIX) void *hModule = dlopen(libName, RTLD_LAZY); @@ -66,6 +70,9 @@ { void *hModule; const char *libName = (*env)->GetStringUTFChars(env, jLibName, NULL); + if (libName == NULL) { + return 0L; + } dprintf1("-lib %s\n", libName); hModule = dlopen(libName, RTLD_LAZY);
--- a/jdk/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c Tue Mar 11 19:28:11 2014 +0400 +++ b/jdk/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c Tue Mar 11 10:46:38 2014 -0700 @@ -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. */ /* Copyright (c) 2002 Graz University of Technology. All rights reserved. @@ -88,6 +88,9 @@ const char *getFunctionListStr; const char *libraryNameStr = (*env)->GetStringUTFChars(env, jPkcs11ModulePath, 0); + if (libraryNameStr == NULL) { + return; + } TRACE1("DEBUG: connect to PKCS#11 module: %s ... ", libraryNameStr); @@ -123,6 +126,9 @@ // with the old JAR file jGetFunctionList is null, temporarily check for that if (jGetFunctionList != NULL) { getFunctionListStr = (*env)->GetStringUTFChars(env, jGetFunctionList, 0); + if (getFunctionListStr == NULL) { + return; + } C_GetFunctionList = (CK_C_GetFunctionList) dlsym(hModule, getFunctionListStr); (*env)->ReleaseStringUTFChars(env, jGetFunctionList, getFunctionListStr); }
--- a/jdk/test/java/lang/invoke/MethodHandles/TestCatchException.java Tue Mar 11 19:28:11 2014 +0400 +++ b/jdk/test/java/lang/invoke/MethodHandles/TestCatchException.java Tue Mar 11 10:46:38 2014 -0700 @@ -72,19 +72,55 @@ assertEquals(x, 17); } + final static Object masterParam = new Object(); + final static Object[] masterTail = new Object[] { "str" }; + static Exception masterEx = new Exception(); public static Object m1(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7, Object o8, Object... tail) { + assertEquals(masterParam, o1); + assertEquals(masterParam, o2); + assertEquals(masterParam, o3); + assertEquals(masterParam, o4); + assertEquals(masterParam, o5); + assertEquals(masterParam, o6); + assertEquals(masterParam, o7); + assertEquals(masterParam, o8); + assertEquals(masterTail, tail); return tail; } public static Object m2(Exception e, Object o1, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7, Object o8, Object... tail) { + assertEquals(masterEx, e); + assertEquals(masterParam, o1); + assertEquals(masterParam, o2); + assertEquals(masterParam, o3); + assertEquals(masterParam, o4); + assertEquals(masterParam, o5); + assertEquals(masterParam, o6); + assertEquals(masterParam, o7); + assertEquals(masterParam, o8); + assertEquals(masterTail, tail); return tail; } + public static Object throwEx(Object o1, Object o2, Object o3, Object o4, Object o5, + Object o6, Object o7, Object o8, Object... tail) throws Exception { + assertEquals(masterParam, o1); + assertEquals(masterParam, o2); + assertEquals(masterParam, o3); + assertEquals(masterParam, o4); + assertEquals(masterParam, o5); + assertEquals(masterParam, o6); + assertEquals(masterParam, o7); + assertEquals(masterParam, o8); + assertEquals(masterTail, tail); + throw masterEx; + } + @Test - public void testVarargsCollector() throws Throwable { + public void testVarargsCollectorNoThrow() throws Throwable { MethodType t1 = MethodType.methodType(Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object.class, Object[].class); @@ -92,17 +128,34 @@ MethodHandle target = LOOKUP.findStatic(TestCatchException.class, "m1", t1) .asVarargsCollector(Object[].class); - - MethodHandle catcher = LOOKUP.findStatic(TestCatchException.class, "m2", t2); - + MethodHandle catcher = LOOKUP.findStatic(TestCatchException.class, "m2", t2) + .asVarargsCollector(Object[].class); MethodHandle gwc = MethodHandles.catchException(target, Exception.class, catcher); - Object o = new Object(); - Object[] obj1 = new Object[] { "str" }; + Object o = masterParam; + Object[] obj1 = masterTail; - Object r1 = target.invokeExact(o, o, o, o, o, o, o, o, obj1); Object r2 = gwc.invokeExact(o, o, o, o, o, o, o, o, obj1); - assertEquals(r1, obj1); + assertEquals(r2, obj1); + } + + @Test + public void testVarargsCollectorThrow() throws Throwable { + MethodType t1 = MethodType.methodType(Object.class, Object.class, Object.class, Object.class, Object.class, + Object.class, Object.class, Object.class, Object.class, Object[].class); + + MethodType t2 = t1.insertParameterTypes(0, Exception.class); + + MethodHandle target = LOOKUP.findStatic(TestCatchException.class, "throwEx", t1) + .asVarargsCollector(Object[].class); + MethodHandle catcher = LOOKUP.findStatic(TestCatchException.class, "m2", t2) + .asVarargsCollector(Object[].class); + MethodHandle gwc = MethodHandles.catchException(target, Exception.class, catcher); + + Object o = masterParam; + Object[] obj1 = masterTail; + + Object r2 = gwc.invokeExact(o, o, o, o, o, o, o, o, obj1); assertEquals(r2, obj1); } @@ -110,7 +163,8 @@ TestCatchException test = new TestCatchException(); test.testNoThrowPath(); test.testThrowPath(); - test.testVarargsCollector(); + test.testVarargsCollectorNoThrow(); + test.testVarargsCollectorThrow(); System.out.println("TEST PASSED"); } }
--- a/jdk/test/java/lang/management/ThreadMXBean/Locks.java Tue Mar 11 19:28:11 2014 +0400 +++ b/jdk/test/java/lang/management/ThreadMXBean/Locks.java Tue Mar 11 10:46:38 2014 -0700 @@ -166,6 +166,9 @@ private static CheckerThread checker; static class WaitingThread extends Thread { private final Phaser p; + + volatile boolean waiting = false; + public WaitingThread(Phaser p) { super("WaitingThread"); this.p = p; @@ -175,7 +178,9 @@ System.out.println("WaitingThread about to wait on objC"); try { // Signal checker thread, about to wait on objC. + waiting = false; p.arriveAndAwaitAdvance(); // Phase 1 (waiting) + waiting = true; objC.wait(); } catch (InterruptedException e) { e.printStackTrace(); @@ -194,7 +199,9 @@ synchronized(objC) { try { // signal checker thread, about to wait on objC + waiting = false; p.arriveAndAwaitAdvance(); // Phase 3 (waiting) + waiting = true; objC.wait(); } catch (InterruptedException e) { e.printStackTrace(); @@ -203,25 +210,35 @@ } System.out.println("WaitingThread about to exit waiting on objC 2"); } - } - static class CheckerThread extends Thread { - private final Phaser p; - public CheckerThread(Phaser p) { - super("CheckerThread"); - this.p = p; + + public void waitForWaiting() { + p.arriveAndAwaitAdvance(); + while (!waiting) { + goSleep(10); + } + waitForState(State.WAITING); + } + + public void waitForBlocked() { + p.arriveAndAwaitAdvance(); + waitForState(State.BLOCKED); } private void waitForState(Thread.State state) { - p.arriveAndAwaitAdvance(); while (!waiter.isInterrupted() && waiter.getState() != state) { - goSleep(10); + Thread.yield(); } } + } + static class CheckerThread extends Thread { + public CheckerThread() { + super("CheckerThread"); + } public void run() { synchronized (ready) { // wait until WaitingThread about to wait for objC - waitForState(Thread.State.WAITING); // Phase 1 (waiting) + waiter.waitForWaiting(); // Phase 1 (waiting) checkBlockedObject(waiter, objC, null, Thread.State.WAITING); synchronized (objC) { @@ -230,13 +247,13 @@ // wait for waiter thread to about to enter // synchronized object ready. - waitForState(Thread.State.BLOCKED); // Phase 2 (waiting) + waiter.waitForBlocked(); // Phase 2 (waiting) checkBlockedObject(waiter, ready, this, Thread.State.BLOCKED); } // wait for signal from waiting thread that it is about // wait for objC. - waitForState(Thread.State.WAITING); // Phase 3 (waiting) + waiter.waitForWaiting(); // Phase 3 (waiting) synchronized(objC) { checkBlockedObject(waiter, objC, Thread.currentThread(), Thread.State.WAITING); objC.notify(); @@ -284,7 +301,7 @@ waiter = new WaitingThread(p); waiter.start(); - checker = new CheckerThread(p); + checker = new CheckerThread(); checker.start(); try {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/sun/security/krb5/config/ExtraLines.java Tue Mar 11 10:46:38 2014 -0700 @@ -0,0 +1,52 @@ +/* + * 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 8036971 + * @compile -XDignore.symbol.file ExtraLines.java + * @run main/othervm ExtraLines + * @summary krb5.conf does not accept directive lines before the first section + */ + +import sun.security.krb5.Config; +import java.nio.file.*; +import java.util.Objects; + +public class ExtraLines { + public static void main(String[] args) throws Exception { + Path base = Paths.get("krb5.conf"); + Path include = Paths.get("included.conf"); + String baseConf = "include " + include.toAbsolutePath().toString() + + "\n[x]\na = b\n"; + String includeConf = "[y]\nc = d\n"; + Files.write(include, includeConf.getBytes()); + Files.write(base, baseConf.getBytes()); + + System.setProperty("java.security.krb5.conf", base.toString()); + Config.refresh(); + + if (!Objects.equals(Config.getInstance().get("x", "a"), "b")) { + throw new Exception("Failed"); + } + } +}