Mercurial > hg > openjdk > aarch64-port > jdk
changeset 9995:3eef63e7b644
Merge
author | amurillo |
---|---|
date | Tue, 02 Sep 2014 11:42:02 -0700 |
parents | 3c901cd1b8f9 (current diff) 9896782f8af7 (diff) |
children | 20f82ad73a93 |
files | test/sun/jvmstat/monitor/MonitoredVm/MonitorVmStartTerminate.sh test/sun/jvmstat/testlibrary/JavaProcess.java |
diffstat | 66 files changed, 1687 insertions(+), 956 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags Thu Aug 28 14:04:38 2014 -0700 +++ b/.hgtags Tue Sep 02 11:42:02 2014 -0700 @@ -309,6 +309,9 @@ 693025bbc45d683676fa78bb76201b665e0d8f2d jdk8u20-b21 0c2393744b29175de5204140d4dfbf12ca3d364f jdk8u20-b22 be30cb2a3088f2b7b334b499f7eddbd5312312a7 jdk8u20-b23 +dfb9f24d56b51e5a2ca26e77fc69a2464d51a4d3 jdk8u20-b24 +dfb9f24d56b51e5a2ca26e77fc69a2464d51a4d3 jdk8u20-b25 +dd229c5f57bff4e75a70908294a13072b9a48385 jdk8u20-b26 e6ed015afbbf3459ba3297e270b4f3170e989c80 jdk8u40-b00 6e223d48080ef40f4ec11ecbcd19b4a20813b9eb jdk8u40-b01 4797cd0713b44b009525f1276d571ade7e24f3f5 jdk8u40-b02
--- a/make/lib/ServiceabilityLibraries.gmk Thu Aug 28 14:04:38 2014 -0700 +++ b/make/lib/ServiceabilityLibraries.gmk Tue Sep 02 11:42:02 2014 -0700 @@ -23,6 +23,10 @@ # questions. # +# Include custom extensions if available. +-include $(CUSTOM_MAKE_DIR)/lib/ServiceabilityLibraries.gmk + + LIBATTACH_EXCLUDE_FILES := ifneq ($(OPENJDK_TARGET_OS), solaris) LIBATTACH_EXCLUDE_FILES += SolarisVirtualMachine.c @@ -283,12 +287,12 @@ ########################################################################################## -BUILD_LIBMANAGEMENT_SRC := $(JDK_TOPDIR)/src/share/native/sun/management \ +BUILD_LIBMANAGEMENT_SRC += $(JDK_TOPDIR)/src/share/native/sun/management \ $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/management BUILD_LIBMANAGEMENT_EXCLUDES := -BUILD_LIBMANAGEMENT_CFLAGS := -I$(JDK_TOPDIR)/src/share/native/sun/management +BUILD_LIBMANAGEMENT_CFLAGS += -I$(JDK_TOPDIR)/src/share/native/sun/management ifneq ($(OPENJDK_TARGET_OS), solaris) BUILD_LIBMANAGEMENT_EXCLUDES += SolarisOperatingSystem.c @@ -309,6 +313,9 @@ endif endif +# Make it possible to override this variable +LIBMANAGEMENT_MAPFILE ?= $(JDK_TOPDIR)/make/mapfiles/libmanagement/mapfile-vers + $(eval $(call SetupNativeCompilation,BUILD_LIBMANAGEMENT, \ LIBRARY := management, \ OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \ @@ -317,7 +324,7 @@ LANG := C, \ OPTIMIZATION := $(LIBMANAGEMENT_OPTIMIZATION), \ CFLAGS := $(CFLAGS_JDKLIB) $(BUILD_LIBMANAGEMENT_CFLAGS), \ - MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libmanagement/mapfile-vers, \ + MAPFILE := $(LIBMANAGEMENT_MAPFILE), \ LDFLAGS := $(LDFLAGS_JDKLIB) \ $(call SET_SHARED_LIBRARY_ORIGIN), \ LDFLAGS_solaris := -lkstat, \
--- a/make/mapfiles/libjava/mapfile-vers Thu Aug 28 14:04:38 2014 -0700 +++ b/make/mapfiles/libjava/mapfile-vers Tue Sep 02 11:42:02 2014 -0700 @@ -78,13 +78,13 @@ Java_java_io_FileInputStream_available; Java_java_io_FileInputStream_close0; Java_java_io_FileInputStream_initIDs; - Java_java_io_FileInputStream_open; + Java_java_io_FileInputStream_open0; Java_java_io_FileInputStream_read0; Java_java_io_FileInputStream_readBytes; Java_java_io_FileInputStream_skip; Java_java_io_FileOutputStream_close0; Java_java_io_FileOutputStream_initIDs; - Java_java_io_FileOutputStream_open; + Java_java_io_FileOutputStream_open0; Java_java_io_FileOutputStream_write; Java_java_io_FileOutputStream_writeBytes; Java_java_io_ObjectInputStream_bytesToDoubles; @@ -97,7 +97,7 @@ Java_java_io_RandomAccessFile_getFilePointer; Java_java_io_RandomAccessFile_initIDs; Java_java_io_RandomAccessFile_length; - Java_java_io_RandomAccessFile_open; + Java_java_io_RandomAccessFile_open0; Java_java_io_RandomAccessFile_read0; Java_java_io_RandomAccessFile_readBytes; Java_java_io_RandomAccessFile_seek0;
--- a/make/mapfiles/libjava/reorder-sparc Thu Aug 28 14:04:38 2014 -0700 +++ b/make/mapfiles/libjava/reorder-sparc Tue Sep 02 11:42:02 2014 -0700 @@ -44,7 +44,7 @@ text: .text%Java_java_io_UnixFileSystem_canonicalize; text: .text%JNU_GetStringPlatformChars; text: .text%JNU_ReleaseStringPlatformChars; -text: .text%Java_java_io_FileInputStream_open; +text: .text%Java_java_io_FileInputStream_open0; text: .text%fileOpen; text: .text%Java_java_io_FileInputStream_readBytes; text: .text%readBytes;
--- a/make/mapfiles/libjava/reorder-sparcv9 Thu Aug 28 14:04:38 2014 -0700 +++ b/make/mapfiles/libjava/reorder-sparcv9 Tue Sep 02 11:42:02 2014 -0700 @@ -47,7 +47,7 @@ text: .text%Java_java_io_UnixFileSystem_canonicalize; text: .text%JNU_GetStringPlatformChars; text: .text%JNU_ReleaseStringPlatformChars; -text: .text%Java_java_io_FileInputStream_open; +text: .text%Java_java_io_FileInputStream_open0; text: .text%fileOpen; text: .text%Java_java_io_FileInputStream_readBytes; text: .text%readBytes;
--- a/make/mapfiles/libjava/reorder-x86 Thu Aug 28 14:04:38 2014 -0700 +++ b/make/mapfiles/libjava/reorder-x86 Tue Sep 02 11:42:02 2014 -0700 @@ -57,7 +57,7 @@ text: .text%Java_java_lang_ClassLoader_00024NativeLibrary_find; text: .text%Java_java_lang_Float_floatToIntBits; text: .text%Java_java_lang_Double_doubleToLongBits; -text: .text%Java_java_io_FileInputStream_open; +text: .text%Java_java_io_FileInputStream_open0; text: .text%fileOpen; text: .text%Java_java_io_UnixFileSystem_getLength; text: .text%Java_java_io_FileInputStream_readBytes; @@ -90,7 +90,7 @@ text: .text%JNU_CallMethodByName; text: .text%JNU_CallMethodByNameV; text: .text%Java_java_util_logging_FileHandler_lockFile; -text: .text%Java_java_io_FileOutputStream_open; +text: .text%Java_java_io_FileOutputStream_open0; text: .text%Java_java_io_UnixFileSystem_createDirectory; text: .text%Java_java_io_UnixFileSystem_getLastModifiedTime; text: .text%Java_java_util_prefs_FileSystemPreferences_lockFile0;
--- a/src/share/bin/java.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/bin/java.c Tue Sep 02 11:42:02 2014 -0700 @@ -98,6 +98,7 @@ */ static void SetClassPath(const char *s); static void SelectVersion(int argc, char **argv, char **main_class); +static void SetJvmEnvironment(int argc, char **argv); static jboolean ParseArguments(int *pargc, char ***pargv, int *pmode, char **pwhat, int *pret, const char *jrepath); @@ -238,6 +239,10 @@ jvmpath, sizeof(jvmpath), jvmcfg, sizeof(jvmcfg)); + if (!IsJavaArgs()) { + SetJvmEnvironment(argc,argv); + } + ifn.CreateJavaVM = 0; ifn.GetDefaultJavaVMInitArgs = 0; @@ -633,6 +638,67 @@ return jvmtype; } +/* + * static void SetJvmEnvironment(int argc, char **argv); + * Is called just before the JVM is loaded. We can set env variables + * that are consumed by the JVM. This function is non-destructive, + * leaving the arg list intact. The first use is for the JVM flag + * -XX:NativeMemoryTracking=value. + */ +static void +SetJvmEnvironment(int argc, char **argv) { + + static const char* NMT_Env_Name = "NMT_LEVEL_"; + + int i; + for (i = 0; i < argc; i++) { + /* + * The following case checks for "-XX:NativeMemoryTracking=value". + * If value is non null, an environmental variable set to this value + * will be created to be used by the JVM. + * The argument is passed to the JVM, which will check validity. + * The JVM is responsible for removing the env variable. + */ + char *arg = argv[i]; + if (JLI_StrCCmp(arg, "-XX:NativeMemoryTracking=") == 0) { + int retval; + // get what follows this parameter, include "=" + size_t pnlen = JLI_StrLen("-XX:NativeMemoryTracking="); + if (JLI_StrLen(arg) > pnlen) { + char* value = arg + pnlen; + size_t pbuflen = pnlen + JLI_StrLen(value) + 10; // 10 max pid digits + + /* + * ensures that malloc successful + * DONT JLI_MemFree() pbuf. JLI_PutEnv() uses system call + * that could store the address. + */ + char * pbuf = (char*)JLI_MemAlloc(pbuflen); + + JLI_Snprintf(pbuf, pbuflen, "%s%d=%s", NMT_Env_Name, JLI_GetPid(), value); + retval = JLI_PutEnv(pbuf); + if (JLI_IsTraceLauncher()) { + char* envName; + char* envBuf; + + // ensures that malloc successful + envName = (char*)JLI_MemAlloc(pbuflen); + JLI_Snprintf(envName, pbuflen, "%s%d", NMT_Env_Name, JLI_GetPid()); + + printf("TRACER_MARKER: NativeMemoryTracking: env var is %s\n",envName); + printf("TRACER_MARKER: NativeMemoryTracking: putenv arg %s\n",pbuf); + envBuf = getenv(envName); + printf("TRACER_MARKER: NativeMemoryTracking: got value %s\n",envBuf); + free(envName); + } + + } + + } + + } +} + /* copied from HotSpot function "atomll()" */ static int parse_size(const char *s, jlong *result) {
--- a/src/share/bin/jli_util.h Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/bin/jli_util.h Tue Sep 02 11:42:02 2014 -0700 @@ -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 @@ -64,17 +64,22 @@ #ifdef _WIN32 #include <windows.h> #include <io.h> +#include <process.h> #define JLI_StrCaseCmp(p1, p2) stricmp((p1), (p2)) #define JLI_StrNCaseCmp(p1, p2, p3) strnicmp((p1), (p2), (p3)) int JLI_Snprintf(char *buffer, size_t size, const char *format, ...); void JLI_CmdToArgs(char *cmdline); #define JLI_Lseek _lseeki64 +#define JLI_PutEnv _putenv +#define JLI_GetPid _getpid #else /* NIXES */ #include <unistd.h> #include <strings.h> #define JLI_StrCaseCmp(p1, p2) strcasecmp((p1), (p2)) #define JLI_StrNCaseCmp(p1, p2, p3) strncasecmp((p1), (p2), (p3)) #define JLI_Snprintf snprintf +#define JLI_PutEnv putenv +#define JLI_GetPid getpid #ifdef __solaris__ #define JLI_Lseek llseek #endif
--- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ja.properties Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ja.properties Tue Sep 02 11:42:02 2014 -0700 @@ -42,13 +42,13 @@ FileChooser.renameErrorFileExists.textAndMnemonic={0}\u306E\u540D\u524D\u3092\u5909\u66F4\u3067\u304D\u307E\u305B\u3093: \u6307\u5B9A\u3057\u305F\u540D\u524D\u306E\u30D5\u30A1\u30A4\u30EB\u306F\u3059\u3067\u306B\u5B58\u5728\u3057\u307E\u3059\u3002\u5225\u306E\u30D5\u30A1\u30A4\u30EB\u540D\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002 FileChooser.acceptAllFileFilter.textAndMnemonic=\u3059\u3079\u3066\u306E\u30D5\u30A1\u30A4\u30EB FileChooser.cancelButton.textAndMnemonic=\u53D6\u6D88 -FileChooser.saveButton.textAndMnemonic=\u4FDD\u5B58(&S) -FileChooser.openButton.textAndMnemonic=\u958B\u304F(&O) +FileChooser.saveButton.textAndMnemonic=\u4FDD\u5B58 +FileChooser.openButton.textAndMnemonic=\u958B\u304F FileChooser.saveDialogTitle.textAndMnemonic=\u4FDD\u5B58 FileChooser.openDialogTitle.textAndMnemonic=\u958B\u304F FileChooser.updateButton.textAndMnemonic=\u66F4\u65B0(&U) FileChooser.helpButton.textAndMnemonic=\u30D8\u30EB\u30D7(&H) -FileChooser.directoryOpenButton.textAndMnemonic=\u958B\u304F(&O) +FileChooser.directoryOpenButton.textAndMnemonic=\u958B\u304F # File Size Units FileChooser.fileSizeKiloBytes={0} KB
--- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ko.properties Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ko.properties Tue Sep 02 11:42:02 2014 -0700 @@ -42,13 +42,13 @@ FileChooser.renameErrorFileExists.textAndMnemonic={0}\uC758 \uC774\uB984\uC744 \uBC14\uAFC0 \uC218 \uC5C6\uC74C: \uC9C0\uC815\uD55C \uC774\uB984\uC744 \uC0AC\uC6A9\uD558\uB294 \uD30C\uC77C\uC774 \uC874\uC7AC\uD569\uB2C8\uB2E4. \uB2E4\uB978 \uD30C\uC77C \uC774\uB984\uC744 \uC9C0\uC815\uD558\uC2ED\uC2DC\uC624. FileChooser.acceptAllFileFilter.textAndMnemonic=\uBAA8\uB4E0 \uD30C\uC77C FileChooser.cancelButton.textAndMnemonic=\uCDE8\uC18C -FileChooser.saveButton.textAndMnemonic=\uC800\uC7A5(&S) -FileChooser.openButton.textAndMnemonic=\uC5F4\uAE30(&O) +FileChooser.saveButton.textAndMnemonic=\uC800\uC7A5 +FileChooser.openButton.textAndMnemonic=\uC5F4\uAE30 FileChooser.saveDialogTitle.textAndMnemonic=\uC800\uC7A5 FileChooser.openDialogTitle.textAndMnemonic=\uC5F4\uAE30 FileChooser.updateButton.textAndMnemonic=\uC5C5\uB370\uC774\uD2B8(&U) FileChooser.helpButton.textAndMnemonic=\uB3C4\uC6C0\uB9D0(&H) -FileChooser.directoryOpenButton.textAndMnemonic=\uC5F4\uAE30(&O) +FileChooser.directoryOpenButton.textAndMnemonic=\uC5F4\uAE30 # File Size Units FileChooser.fileSizeKiloBytes={0} KB
--- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_CN.properties Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_CN.properties Tue Sep 02 11:42:02 2014 -0700 @@ -42,13 +42,13 @@ FileChooser.renameErrorFileExists.textAndMnemonic=\u65E0\u6CD5\u91CD\u547D\u540D{0}: \u5DF2\u5B58\u5728\u5177\u6709\u6240\u6307\u5B9A\u540D\u79F0\u7684\u6587\u4EF6\u3002\u8BF7\u6307\u5B9A\u5176\u4ED6\u6587\u4EF6\u540D\u3002 FileChooser.acceptAllFileFilter.textAndMnemonic=\u6240\u6709\u6587\u4EF6 FileChooser.cancelButton.textAndMnemonic=\u53D6\u6D88 -FileChooser.saveButton.textAndMnemonic=\u4FDD\u5B58(&S) -FileChooser.openButton.textAndMnemonic=\u6253\u5F00(&O) +FileChooser.saveButton.textAndMnemonic=\u4FDD\u5B58 +FileChooser.openButton.textAndMnemonic=\u6253\u5F00 FileChooser.saveDialogTitle.textAndMnemonic=\u4FDD\u5B58 FileChooser.openDialogTitle.textAndMnemonic=\u6253\u5F00 FileChooser.updateButton.textAndMnemonic=\u66F4\u65B0(&U) FileChooser.helpButton.textAndMnemonic=\u5E2E\u52A9(&H) -FileChooser.directoryOpenButton.textAndMnemonic=\u6253\u5F00(&O) +FileChooser.directoryOpenButton.textAndMnemonic=\u6253\u5F00 # File Size Units FileChooser.fileSizeKiloBytes={0} KB
--- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_TW.properties Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_TW.properties Tue Sep 02 11:42:02 2014 -0700 @@ -42,13 +42,13 @@ FileChooser.renameErrorFileExists.textAndMnemonic=\u7121\u6CD5\u91CD\u65B0\u547D\u540D {0}: \u5DF2\u7D93\u5B58\u5728\u60A8\u6240\u6307\u5B9A\u540D\u7A31\u7684\u6A94\u6848\u3002\u8ACB\u6307\u5B9A\u4E0D\u540C\u7684\u540D\u7A31\u3002 FileChooser.acceptAllFileFilter.textAndMnemonic=\u6240\u6709\u6A94\u6848 FileChooser.cancelButton.textAndMnemonic=\u53D6\u6D88 -FileChooser.saveButton.textAndMnemonic=\u5132\u5B58(&S) -FileChooser.openButton.textAndMnemonic=\u958B\u555F(&O) +FileChooser.saveButton.textAndMnemonic=\u5132\u5B58 +FileChooser.openButton.textAndMnemonic=\u958B\u555F FileChooser.saveDialogTitle.textAndMnemonic=\u5132\u5B58 FileChooser.openDialogTitle.textAndMnemonic=\u958B\u555F FileChooser.updateButton.textAndMnemonic=\u66F4\u65B0(&U) FileChooser.helpButton.textAndMnemonic=\u8AAA\u660E(&H) -FileChooser.directoryOpenButton.textAndMnemonic=\u958B\u555F(&O) +FileChooser.directoryOpenButton.textAndMnemonic=\u958B\u555F # File Size Units FileChooser.fileSizeKiloBytes={0} KB
--- a/src/share/classes/java/io/FileInputStream.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/java/io/FileInputStream.java Tue Sep 02 11:42:02 2014 -0700 @@ -184,7 +184,16 @@ * Opens the specified file for reading. * @param name the name of the file */ - private native void open(String name) throws FileNotFoundException; + private native void open0(String name) throws FileNotFoundException; + + // wrap native call to allow instrumentation + /** + * Opens the specified file for reading. + * @param name the name of the file + */ + private void open(String name) throws FileNotFoundException { + open0(name); + } /** * Reads a byte of data from this input stream. This method blocks
--- a/src/share/classes/java/io/FileOutputStream.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/java/io/FileOutputStream.java Tue Sep 02 11:42:02 2014 -0700 @@ -256,9 +256,20 @@ * @param name name of file to be opened * @param append whether the file is to be opened in append mode */ - private native void open(String name, boolean append) + private native void open0(String name, boolean append) throws FileNotFoundException; + // wrap native call to allow instrumentation + /** + * Opens a file, with the specified name, for overwriting or appending. + * @param name name of file to be opened + * @param append whether the file is to be opened in append mode + */ + private void open(String name, boolean append) + throws FileNotFoundException { + open0(name, append); + } + /** * Writes the specified byte to this file output stream. *
--- a/src/share/classes/java/io/RandomAccessFile.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/java/io/RandomAccessFile.java Tue Sep 02 11:42:02 2014 -0700 @@ -296,9 +296,26 @@ * @param mode the mode flags, a combination of the O_ constants * defined above */ - private native void open(String name, int mode) + private native void open0(String name, int mode) throws FileNotFoundException; + // wrap native call to allow instrumentation + /** + * Opens a file and returns the file descriptor. The file is + * opened in read-write mode if the O_RDWR bit in {@code mode} + * is true, else the file is opened as read-only. + * If the {@code name} refers to a directory, an IOException + * is thrown. + * + * @param name the name of the file + * @param mode the mode flags, a combination of the O_ constants + * defined above + */ + private void open(String name, int mode) + throws FileNotFoundException { + open0(name, mode); + } + // 'Read' primitives /**
--- a/src/share/classes/java/lang/reflect/Constructor.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/java/lang/reflect/Constructor.java Tue Sep 02 11:42:02 2014 -0700 @@ -543,15 +543,33 @@ */ @Override public AnnotatedType getAnnotatedReceiverType() { - if (getDeclaringClass().getEnclosingClass() == null) - return super.getAnnotatedReceiverType(); + Class<?> thisDeclClass = getDeclaringClass(); + Class<?> enclosingClass = thisDeclClass.getEnclosingClass(); + + if (enclosingClass == null) { + // A Constructor for a top-level class + return null; + } + Class<?> outerDeclaringClass = thisDeclClass.getDeclaringClass(); + if (outerDeclaringClass == null) { + // A constructor for a local or anonymous class + return null; + } + + // Either static nested or inner class + if (Modifier.isStatic(thisDeclClass.getModifiers())) { + // static nested + return null; + } + + // A Constructor for an inner class return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(), sun.misc.SharedSecrets.getJavaLangAccess(). - getConstantPool(getDeclaringClass()), + getConstantPool(thisDeclClass), this, - getDeclaringClass(), - getDeclaringClass().getEnclosingClass(), + thisDeclClass, + enclosingClass, TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER); } }
--- a/src/share/classes/java/lang/reflect/Executable.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/java/lang/reflect/Executable.java Tue Sep 02 11:42:02 2014 -0700 @@ -592,21 +592,24 @@ /** * Returns an {@code AnnotatedType} object that represents the use of a * type to specify the receiver type of the method/constructor represented - * by this Executable object. The receiver type of a method/constructor is - * available only if the method/constructor has a <em>receiver - * parameter</em> (JLS 8.4.1). + * by this {@code Executable} object. * - * If this {@code Executable} object represents a constructor or instance - * method that does not have a receiver parameter, or has a receiver - * parameter with no annotations on its type, then the return value is an - * {@code AnnotatedType} object representing an element with no + * The receiver type of a method/constructor is available only if the + * method/constructor has a receiver parameter (JLS 8.4.1). If this {@code + * Executable} object <em>represents an instance method or represents a + * constructor of an inner member class</em>, and the + * method/constructor <em>either</em> has no receiver parameter or has a + * receiver parameter with no annotations on its type, then the return + * value is an {@code AnnotatedType} object representing an element with no * annotations. * - * If this {@code Executable} object represents a static method, then the - * return value is null. + * If this {@code Executable} object represents a static method or + * represents a constructor of a top level, static member, local, or + * anoymous class, then the return value is null. * * @return an object representing the receiver type of the method or - * constructor represented by this {@code Executable} + * constructor represented by this {@code Executable} or {@code null} if + * this {@code Executable} can not have a receiver parameter * * @since 1.8 */
--- a/src/share/classes/java/net/SocketInputStream.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/java/net/SocketInputStream.java Tue Sep 02 11:42:02 2014 -0700 @@ -96,6 +96,26 @@ int timeout) throws IOException; + // wrap native call to allow instrumentation + /** + * Reads into an array of bytes at the specified offset using + * the received socket primitive. + * @param fd the FileDescriptor + * @param b the buffer into which the data is read + * @param off the start offset of the data + * @param len the maximum number of bytes read + * @param timeout the read timeout in ms + * @return the actual number of bytes read, -1 is + * returned when the end of the stream is reached. + * @exception IOException If an I/O error has occurred. + */ + private int socketRead(FileDescriptor fd, + byte b[], int off, int len, + int timeout) + throws IOException { + return socketRead0(fd, b, off, len, timeout); + } + /** * Reads into a byte array data from the socket. * @param b the buffer into which the data is read @@ -147,7 +167,7 @@ // acquire file descriptor and do the read FileDescriptor fd = impl.acquireFD(); try { - n = socketRead0(fd, b, off, length, timeout); + n = socketRead(fd, b, off, length, timeout); if (n > 0) { return n; } @@ -165,7 +185,7 @@ impl.setConnectionResetPending(); impl.acquireFD(); try { - n = socketRead0(fd, b, off, length, timeout); + n = socketRead(fd, b, off, length, timeout); if (n > 0) { return n; }
--- a/src/share/classes/sun/awt/ComponentFactory.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/sun/awt/ComponentFactory.java Tue Sep 02 11:42:02 2014 -0700 @@ -25,6 +25,8 @@ package sun.awt; +import sun.awt.datatransfer.DataTransferer; + import java.awt.*; import java.awt.dnd.*; import java.awt.dnd.peer.DragSourceContextPeer; @@ -93,4 +95,6 @@ RobotPeer createRobot(Robot target, GraphicsDevice screen) throws AWTException, HeadlessException; + DataTransferer getDataTransferer(); + }
--- a/src/share/classes/sun/awt/HeadlessToolkit.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/sun/awt/HeadlessToolkit.java Tue Sep 02 11:42:02 2014 -0700 @@ -25,6 +25,8 @@ package sun.awt; +import sun.awt.datatransfer.DataTransferer; + import java.awt.*; import java.awt.dnd.*; import java.awt.dnd.peer.DragSourceContextPeer; @@ -401,6 +403,11 @@ return null; } + @Override + public DataTransferer getDataTransferer() { + return null; + } + @SuppressWarnings("deprecation") public FontMetrics getFontMetrics(Font font) { return tk.getFontMetrics(font);
--- a/src/share/classes/sun/awt/SunToolkit.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/sun/awt/SunToolkit.java Tue Sep 02 11:42:02 2014 -0700 @@ -205,8 +205,6 @@ public abstract boolean isTraySupported(); - public abstract DataTransferer getDataTransferer(); - @SuppressWarnings("deprecation") public abstract FontPeer getFontPeer(String name, int style);
--- a/src/share/classes/sun/awt/datatransfer/DataTransferer.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/sun/awt/datatransfer/DataTransferer.java Tue Sep 02 11:42:02 2014 -0700 @@ -86,6 +86,7 @@ import java.util.TreeMap; import java.util.TreeSet; +import sun.awt.ComponentFactory; import sun.util.logging.PlatformLogger; import sun.awt.AppContext; @@ -272,7 +273,7 @@ * instead, null will be returned. */ public static synchronized DataTransferer getInstance() { - return ((SunToolkit) Toolkit.getDefaultToolkit()).getDataTransferer(); + return ((ComponentFactory) Toolkit.getDefaultToolkit()).getDataTransferer(); } /**
--- a/src/share/classes/sun/java2d/opengl/OGLSurfaceDataProxy.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/sun/java2d/opengl/OGLSurfaceDataProxy.java Tue Sep 02 11:42:02 2014 -0700 @@ -65,7 +65,11 @@ int w, int h) { if (cachedData == null) { - cachedData = oglgc.createManagedSurface(w, h, transparency); + try { + cachedData = oglgc.createManagedSurface(w, h, transparency); + } catch (OutOfMemoryError er) { + return null; + } } return cachedData; }
--- a/src/share/classes/sun/nio/ch/DatagramChannelImpl.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/sun/nio/ch/DatagramChannelImpl.java Tue Sep 02 11:42:02 2014 -0700 @@ -195,15 +195,8 @@ synchronized (stateLock) { ensureOpen(); - if (name == StandardSocketOptions.IP_TOS) { - // IPv4 only; no-op for IPv6 - if (family == StandardProtocolFamily.INET) { - Net.setSocketOption(fd, family, name, value); - } - return this; - } - - if (name == StandardSocketOptions.IP_MULTICAST_TTL || + if (name == StandardSocketOptions.IP_TOS || + name == StandardSocketOptions.IP_MULTICAST_TTL || name == StandardSocketOptions.IP_MULTICAST_LOOP) { // options are protocol dependent @@ -256,16 +249,8 @@ synchronized (stateLock) { ensureOpen(); - if (name == StandardSocketOptions.IP_TOS) { - // IPv4 only; always return 0 on IPv6 - if (family == StandardProtocolFamily.INET) { - return (T) Net.getSocketOption(fd, family, name); - } else { - return (T) Integer.valueOf(0); - } - } - - if (name == StandardSocketOptions.IP_MULTICAST_TTL || + if (name == StandardSocketOptions.IP_TOS || + name == StandardSocketOptions.IP_MULTICAST_TTL || name == StandardSocketOptions.IP_MULTICAST_LOOP) { return (T) Net.getSocketOption(fd, family, name);
--- a/src/share/classes/sun/nio/ch/Net.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/sun/nio/ch/Net.java Tue Sep 02 11:42:02 2014 -0700 @@ -352,7 +352,8 @@ } boolean mayNeedConversion = (family == UNSPEC); - setIntOption0(fd, mayNeedConversion, key.level(), key.name(), arg); + boolean isIPv6 = (family == StandardProtocolFamily.INET6); + setIntOption0(fd, mayNeedConversion, key.level(), key.name(), arg, isIPv6); } static Object getSocketOption(FileDescriptor fd, ProtocolFamily family, @@ -499,7 +500,7 @@ throws IOException; private static native void setIntOption0(FileDescriptor fd, boolean mayNeedConversion, - int level, int opt, int arg) + int level, int opt, int arg, boolean isIPv6) throws IOException; static native int poll(FileDescriptor fd, int events, long timeout)
--- a/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java Tue Sep 02 11:42:02 2014 -0700 @@ -133,6 +133,14 @@ synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); + + if (name == StandardSocketOptions.IP_TOS) { + ProtocolFamily family = Net.isIPv6Available() ? + StandardProtocolFamily.INET6 : StandardProtocolFamily.INET; + Net.setSocketOption(fd, family, name, value); + return this; + } + if (name == StandardSocketOptions.SO_REUSEADDR && Net.useExclusiveBind()) { @@ -177,6 +185,7 @@ HashSet<SocketOption<?>> set = new HashSet<SocketOption<?>>(2); set.add(StandardSocketOptions.SO_RCVBUF); set.add(StandardSocketOptions.SO_REUSEADDR); + set.add(StandardSocketOptions.IP_TOS); return Collections.unmodifiableSet(set); } }
--- a/src/share/classes/sun/nio/ch/SocketChannelImpl.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/sun/nio/ch/SocketChannelImpl.java Tue Sep 02 11:42:02 2014 -0700 @@ -173,14 +173,14 @@ if (!isOpen()) throw new ClosedChannelException(); - // special handling for IP_TOS: no-op when IPv6 if (name == StandardSocketOptions.IP_TOS) { - if (!Net.isIPv6Available()) - Net.setSocketOption(fd, StandardProtocolFamily.INET, name, value); + ProtocolFamily family = Net.isIPv6Available() ? + StandardProtocolFamily.INET6 : StandardProtocolFamily.INET; + Net.setSocketOption(fd, family, name, value); return this; - } else if (name == StandardSocketOptions.SO_REUSEADDR && - Net.useExclusiveBind()) - { + } + + if (name == StandardSocketOptions.SO_REUSEADDR && Net.useExclusiveBind()) { // SO_REUSEADDR emulated when using exclusive bind isReuseAddress = (Boolean)value; return this; @@ -215,8 +215,9 @@ // special handling for IP_TOS: always return 0 when IPv6 if (name == StandardSocketOptions.IP_TOS) { - return (Net.isIPv6Available()) ? (T) Integer.valueOf(0) : - (T) Net.getSocketOption(fd, StandardProtocolFamily.INET, name); + ProtocolFamily family = Net.isIPv6Available() ? + StandardProtocolFamily.INET6 : StandardProtocolFamily.INET; + return (T) Net.getSocketOption(fd, family, name); } // no options that require special handling
--- a/src/share/classes/sun/security/jgss/wrapper/GSSLibStub.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/sun/security/jgss/wrapper/GSSLibStub.java Tue Sep 02 11:42:02 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 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 @@ -48,10 +48,11 @@ /** * Initialization routine to dynamically load function pointers. * - * @param library name to dlopen + * @param lib library name to dlopen + * @param debug set to true for reporting native debugging info * @return true if succeeded, false otherwise. */ - static native boolean init(String lib); + static native boolean init(String lib, boolean debug); private static native long getMechPtr(byte[] oidDerEncoding); // Miscellaneous routines
--- a/src/share/classes/sun/security/jgss/wrapper/SunNativeProvider.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/sun/security/jgss/wrapper/SunNativeProvider.java Tue Sep 02 11:42:02 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 @@ -100,7 +100,7 @@ gssLibs = new String[]{ defaultLib }; } for (String libName: gssLibs) { - if (GSSLibStub.init(libName)) { + if (GSSLibStub.init(libName, DEBUG)) { debug("Loaded GSS library: " + libName); Oid[] mechs = GSSLibStub.indicateMechs(); HashMap<String, String> map =
--- a/src/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java Tue Sep 02 11:42:02 2014 -0700 @@ -402,8 +402,7 @@ String uidStr = null; long uid = 0; - if (osname.startsWith("SunOS") || - (osname.startsWith("Linux"))) { + if (!osname.startsWith("Windows")) { try { Class<?> c = Class.forName ("com.sun.security.auth.module.UnixSystem");
--- a/src/share/classes/sun/security/pkcs11/SessionManager.java Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/classes/sun/security/pkcs11/SessionManager.java Tue Sep 02 11:42:02 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, 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 @@ -34,6 +34,9 @@ import sun.security.pkcs11.wrapper.*; import static sun.security.pkcs11.wrapper.PKCS11Constants.*; +import java.util.concurrent.ConcurrentLinkedDeque; +import java.util.concurrent.atomic.AtomicInteger; + /** * Session manager. There is one session manager object per PKCS#11 * provider. It allows code to checkout a session, release it @@ -77,7 +80,7 @@ private final int maxSessions; // total number of active sessions - private int activeSessions; + private AtomicInteger activeSessions = new AtomicInteger(); // pool of available object sessions private final Pool objSessions; @@ -118,7 +121,7 @@ return (maxSessions <= DEFAULT_MAX_SESSIONS); } - synchronized Session getObjSession() throws PKCS11Exception { + Session getObjSession() throws PKCS11Exception { Session session = objSessions.poll(); if (session != null) { return ensureValid(session); @@ -131,7 +134,7 @@ return ensureValid(session); } - synchronized Session getOpSession() throws PKCS11Exception { + Session getOpSession() throws PKCS11Exception { Session session = opSessions.poll(); if (session != null) { return ensureValid(session); @@ -139,7 +142,7 @@ // create a new session rather than re-using an obj session // that avoids potential expensive cancels() for Signatures & RSACipher if (maxSessions == Integer.MAX_VALUE || - activeSessions < maxSessions) { + activeSessions.get() < maxSessions) { session = openSession(); return ensureValid(session); } @@ -155,20 +158,20 @@ return session; } - synchronized Session killSession(Session session) { + Session killSession(Session session) { if ((session == null) || (token.isValid() == false)) { return null; } if (debug != null) { String location = new Exception().getStackTrace()[2].toString(); System.out.println("Killing session (" + location + ") active: " - + activeSessions); + + activeSessions.get()); } closeSession(session); return null; } - synchronized Session releaseSession(Session session) { + Session releaseSession(Session session) { if ((session == null) || (token.isValid() == false)) { return null; } @@ -181,13 +184,13 @@ return null; } - synchronized void demoteObjSession(Session session) { + void demoteObjSession(Session session) { if (token.isValid() == false) { return; } if (debug != null) { System.out.println("Demoting session, active: " + - activeSessions); + activeSessions.get()); } boolean present = objSessions.remove(session); if (present == false) { @@ -200,18 +203,21 @@ private Session openSession() throws PKCS11Exception { if ((maxSessions != Integer.MAX_VALUE) && - (activeSessions >= maxSessions)) { + (activeSessions.get() >= maxSessions)) { throw new ProviderException("No more sessions available"); } + long id = token.p11.C_OpenSession (token.provider.slotID, openSessionFlags, null, null); Session session = new Session(token, id); - activeSessions++; + activeSessions.incrementAndGet(); if (debug != null) { - if (activeSessions > maxActiveSessions) { - maxActiveSessions = activeSessions; - if (maxActiveSessions % 10 == 0) { - System.out.println("Open sessions: " + maxActiveSessions); + synchronized(this) { + if (activeSessions.get() > maxActiveSessions) { + maxActiveSessions = activeSessions.get(); + if (maxActiveSessions % 10 == 0) { + System.out.println("Open sessions: " + maxActiveSessions); + } } } } @@ -220,18 +226,18 @@ private void closeSession(Session session) { session.close(); - activeSessions--; + activeSessions.decrementAndGet(); } - private static final class Pool { + public static final class Pool { private final SessionManager mgr; - private final List<Session> pool; + private final ConcurrentLinkedDeque<Session> pool; Pool(SessionManager mgr) { - this.mgr = mgr; - pool = new ArrayList<Session>(); + this.mgr = mgr; + pool = new ConcurrentLinkedDeque<Session>(); } boolean remove(Session session) { @@ -239,45 +245,40 @@ } Session poll() { - int n = pool.size(); - if (n == 0) { - return null; - } - Session session = pool.remove(n - 1); - return session; + return pool.pollLast(); } void release(Session session) { - pool.add(session); - // if there are idle sessions, close them + pool.offer(session); if (session.hasObjects()) { return; } + int n = pool.size(); if (n < 5) { return; } - Session oldestSession = pool.get(0); + + Session oldestSession; long time = System.currentTimeMillis(); - if (session.isLive(time) && oldestSession.isLive(time)) { - return; - } - Collections.sort(pool); int i = 0; - while (i < n - 1) { // always keep at least 1 session open - oldestSession = pool.get(i); - if (oldestSession.isLive(time)) { + // Check if the session head is too old and continue through queue + // until only one is left. + do { + oldestSession = pool.peek(); + if (oldestSession == null || oldestSession.isLive(time) || + !pool.remove(oldestSession)) { break; } + i++; mgr.closeSession(oldestSession); - } + } while ((n - i) > 1); + if (debug != null) { System.out.println("Closing " + i + " idle sessions, active: " + mgr.activeSessions); } - List<Session> subList = pool.subList(0, i); - subList.clear(); } }
--- a/src/share/lib/security/sunpkcs11-solaris.cfg Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/lib/security/sunpkcs11-solaris.cfg Tue Sep 02 11:42:02 2014 -0700 @@ -18,16 +18,6 @@ disabledMechanisms = { CKM_DSA_KEY_PAIR_GEN -# the following mechanisms are disabled due to CKR_SAVED_STATE_INVALID bug -# (Solaris bug 7058108) - CKM_MD2 - CKM_MD5 - CKM_SHA_1 -# the following mechanisms are disabled due to no cloning support -# (Solaris bug 7050617) - CKM_SHA256 - CKM_SHA384 - CKM_SHA512 # the following mechanisms are disabled due to performance issues # (Solaris bug 6337157) CKM_DSA_SHA1 @@ -36,10 +26,5 @@ CKM_SHA256_RSA_PKCS CKM_SHA384_RSA_PKCS CKM_SHA512_RSA_PKCS -# the following mechanisms are disabled to ensure backward compatibility -# (Solaris bug 6545046) - CKM_DES_CBC_PAD - CKM_DES3_CBC_PAD - CKM_AES_CBC_PAD }
--- a/src/share/native/java/io/FileInputStream.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/native/java/io/FileInputStream.c Tue Sep 02 11:42:02 2014 -0700 @@ -57,7 +57,7 @@ */ JNIEXPORT void JNICALL -Java_java_io_FileInputStream_open(JNIEnv *env, jobject this, jstring path) { +Java_java_io_FileInputStream_open0(JNIEnv *env, jobject this, jstring path) { fileOpen(env, this, path, fis_fd, O_RDONLY); }
--- a/src/share/native/java/io/RandomAccessFile.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/native/java/io/RandomAccessFile.c Tue Sep 02 11:42:02 2014 -0700 @@ -47,8 +47,8 @@ JNIEXPORT void JNICALL -Java_java_io_RandomAccessFile_open(JNIEnv *env, - jobject this, jstring path, jint mode) +Java_java_io_RandomAccessFile_open0(JNIEnv *env, + jobject this, jstring path, jint mode) { int flags = 0; if (mode & java_io_RandomAccessFile_O_RDONLY)
--- a/src/share/native/sun/nio/ch/genSocketOptionRegistry.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/native/sun/nio/ch/genSocketOptionRegistry.c Tue Sep 02 11:42:02 2014 -0700 @@ -110,6 +110,7 @@ emit_inet("StandardSocketOptions.IP_MULTICAST_LOOP", IPPROTO_IP, IP_MULTICAST_LOOP); #ifdef AF_INET6 + emit_inet6("StandardSocketOptions.IP_TOS", IPPROTO_IPV6, IPV6_TCLASS); emit_inet6("StandardSocketOptions.IP_MULTICAST_IF", IPPROTO_IPV6, IPV6_MULTICAST_IF); emit_inet6("StandardSocketOptions.IP_MULTICAST_TTL", IPPROTO_IPV6, IPV6_MULTICAST_HOPS); emit_inet6("StandardSocketOptions.IP_MULTICAST_LOOP", IPPROTO_IPV6, IPV6_MULTICAST_LOOP);
--- a/src/share/native/sun/security/jgss/wrapper/GSSLibStub.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/native/sun/security/jgss/wrapper/GSSLibStub.c Tue Sep 02 11:42:02 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 @@ -29,19 +29,6 @@ #include "jlong.h" #include <jni.h> -/* Throws a Java Exception by name */ - -void throwByName(JNIEnv *env, const char *name, const char *msg) { - jclass cls = (*env)->FindClass(env, name); - - if (cls != 0) /* Otherwise an exception has already been thrown */ - (*env)->ThrowNew(env, cls, msg); -} - -void throwOutOfMemoryError(JNIEnv *env, const char *message) { - throwByName(env, "java/lang/OutOfMemoryError", message); -} - /* Constants for indicating what type of info is needed for inquiries */ const int TYPE_CRED_NAME = 10; const int TYPE_CRED_TIME = 11; @@ -50,23 +37,32 @@ /* * Class: sun_security_jgss_wrapper_GSSLibStub * Method: init - * Signature: (Ljava/lang/String;)Z + * Signature: (Ljava/lang/String;Z)Z */ JNIEXPORT jboolean JNICALL Java_sun_security_jgss_wrapper_GSSLibStub_init(JNIEnv *env, jclass jcls, - jstring jlibName) { + jstring jlibName, + jboolean jDebug) { const char *libName; char *error = NULL; + if (!jDebug) { + JGSS_DEBUG = 0; + } else { + JGSS_DEBUG = 1; + } + if (jlibName == NULL) { - debug(env, "[GSSLibStub_init] GSS lib name is NULL"); + TRACE0("[GSSLibStub_init] GSS lib name is NULL"); return JNI_FALSE; } libName = (*env)->GetStringUTFChars(env, jlibName, NULL); - sprintf(debugBuf, "[GSSLibStub_init] libName=%s", libName); - debug(env, debugBuf); + if (libName == NULL) { + return JNI_FALSE; + } + TRACE1("[GSSLibStub_init] libName=%s", libName); /* initialize global function table */ error = loadNative(libName); @@ -75,7 +71,7 @@ if (error == NULL) { return JNI_TRUE; } else { - debug(env, error); + TRACE0(error); return JNI_FALSE; } } @@ -93,126 +89,137 @@ unsigned int i, len; jbyte* bytes; jthrowable gssEx; - jboolean found; + int found; if (jbytes != NULL) { - found = JNI_FALSE; + found = 0; len = (unsigned int)((*env)->GetArrayLength(env, jbytes) - 2); bytes = (*env)->GetByteArrayElements(env, jbytes, NULL); - if (bytes != NULL) { - for (i = 0; i < ftab->mechs->count; i++) { - cOid = &(ftab->mechs->elements[i]); - if (len == cOid->length && - (memcmp(cOid->elements, (bytes + 2), len) == 0)) { - // Found a match - found = JNI_TRUE; - break; - } + if (bytes == NULL) { + return ptr_to_jlong(NULL); + } + for (i = 0; i < ftab->mechs->count; i++) { + cOid = &(ftab->mechs->elements[i]); + if (len == cOid->length && + (memcmp(cOid->elements, (bytes + 2), len) == 0)) { + // Found a match + found = 1; + break; } - (*env)->ReleaseByteArrayElements(env, jbytes, bytes, 0); } - if (found != JNI_TRUE) { + (*env)->ReleaseByteArrayElements(env, jbytes, bytes, 0); + + if (found != 1) { checkStatus(env, NULL, GSS_S_BAD_MECH, 0, "[GSSLibStub_getMechPtr]"); return ptr_to_jlong(NULL); - } else return ptr_to_jlong(cOid); - } else return ptr_to_jlong(GSS_C_NO_OID); + } else { + return ptr_to_jlong(cOid); + } + } else { + return ptr_to_jlong(GSS_C_NO_OID); + } } +/* + * Utility routine which releases the specified gss_channel_bindings_t + * structure. + */ +void deleteGSSCB(gss_channel_bindings_t cb) { + jobject jinetAddr; + jbyteArray value; + + if (cb == GSS_C_NO_CHANNEL_BINDINGS) return; + + /* release initiator address */ + if (cb->initiator_addrtype != GSS_C_AF_NULLADDR) { + resetGSSBuffer(&(cb->initiator_address)); + } + /* release acceptor address */ + if (cb->acceptor_addrtype != GSS_C_AF_NULLADDR) { + resetGSSBuffer(&(cb->acceptor_address)); + } + /* release application data */ + if (cb->application_data.length != 0) { + resetGSSBuffer(&(cb->application_data)); + } + free(cb); +} /* * Utility routine which creates a gss_channel_bindings_t structure * using the specified org.ietf.jgss.ChannelBinding object. + * NOTE: must call deleteGSSCB() to free up the resources. */ -gss_channel_bindings_t getGSSCB(JNIEnv *env, jobject jcb) { +gss_channel_bindings_t newGSSCB(JNIEnv *env, jobject jcb) { gss_channel_bindings_t cb; jobject jinetAddr; jbyteArray value; + int i; if (jcb == NULL) { return GSS_C_NO_CHANNEL_BINDINGS; } cb = malloc(sizeof(struct gss_channel_bindings_struct)); - if (cb == NULL) { throwOutOfMemoryError(env,NULL); return NULL; } + // initialize addrtype in CB first + cb->initiator_addrtype = GSS_C_AF_NULLADDR; + cb->acceptor_addrtype = GSS_C_AF_NULLADDR; + /* set up initiator address */ - jinetAddr = - (*env)->CallObjectMethod(env, jcb, - MID_ChannelBinding_getInitiatorAddr); + jinetAddr = (*env)->CallObjectMethod(env, jcb, + MID_ChannelBinding_getInitiatorAddr); + if ((*env)->ExceptionCheck(env)) { + goto cleanup; + } if (jinetAddr != NULL) { - cb->initiator_addrtype = GSS_C_AF_INET; value = (*env)->CallObjectMethod(env, jinetAddr, MID_InetAddress_getAddr); + if ((*env)->ExceptionCheck(env)) { + goto cleanup; + } + cb->initiator_addrtype = GSS_C_AF_INET; initGSSBuffer(env, value, &(cb->initiator_address)); - } else { - cb->initiator_addrtype = GSS_C_AF_NULLADDR; - cb->initiator_address.length = 0; - cb->initiator_address.value = NULL; + if ((*env)->ExceptionCheck(env)) { + goto cleanup; + } } /* set up acceptor address */ - jinetAddr = - (*env)->CallObjectMethod(env, jcb, - MID_ChannelBinding_getAcceptorAddr); + jinetAddr = (*env)->CallObjectMethod(env, jcb, + MID_ChannelBinding_getAcceptorAddr); + if ((*env)->ExceptionCheck(env)) { + goto cleanup; + } if (jinetAddr != NULL) { - cb->acceptor_addrtype = GSS_C_AF_INET; value = (*env)->CallObjectMethod(env, jinetAddr, MID_InetAddress_getAddr); + if ((*env)->ExceptionCheck(env)) { + goto cleanup; + } + cb->acceptor_addrtype = GSS_C_AF_INET; initGSSBuffer(env, value, &(cb->acceptor_address)); - } else { - cb->acceptor_addrtype = GSS_C_AF_NULLADDR; - cb->acceptor_address.length = 0; - cb->acceptor_address.value = NULL; + if ((*env)->ExceptionCheck(env)) { + goto cleanup; + } } /* set up application data */ value = (*env)->CallObjectMethod(env, jcb, MID_ChannelBinding_getAppData); - if (value != NULL) { - initGSSBuffer(env, value, &(cb->application_data)); - } else { - cb->application_data.length = 0; - cb->application_data.value = NULL; + if ((*env)->ExceptionCheck(env)) { + goto cleanup; + } + initGSSBuffer(env, value, &(cb->application_data)); + if ((*env)->ExceptionCheck(env)) { + goto cleanup; } return cb; -} - -/* - * Utility routine which releases the specified gss_channel_bindings_t - * structure. - */ -void releaseGSSCB(JNIEnv *env, jobject jcb, gss_channel_bindings_t cb) { - jobject jinetAddr; - jbyteArray value; - - if (cb == GSS_C_NO_CHANNEL_BINDINGS) return; - /* release initiator address */ - if (cb->initiator_addrtype != GSS_C_AF_NULLADDR) { - jinetAddr = - (*env)->CallObjectMethod(env, jcb, - MID_ChannelBinding_getInitiatorAddr); - value = (*env)->CallObjectMethod(env, jinetAddr, - MID_InetAddress_getAddr); - resetGSSBuffer(env, value, &(cb->initiator_address)); - } - /* release acceptor address */ - if (cb->acceptor_addrtype != GSS_C_AF_NULLADDR) { - jinetAddr = - (*env)->CallObjectMethod(env, jcb, - MID_ChannelBinding_getAcceptorAddr); - value = (*env)->CallObjectMethod(env, jinetAddr, - MID_InetAddress_getAddr); - resetGSSBuffer(env, value, &(cb->acceptor_address)); - } - /* release application data */ - if (cb->application_data.length != 0) { - value = (*env)->CallObjectMethod(env, jcb, - MID_ChannelBinding_getAppData); - resetGSSBuffer(env, value, &(cb->application_data)); - } - free(cb); +cleanup: + deleteGSSCB(cb); + return NULL; } /* @@ -230,6 +237,9 @@ isUnseq = ((suppInfo & GSS_S_UNSEQ_TOKEN) != 0); hasGap = ((suppInfo & GSS_S_GAP_TOKEN) != 0); minorMsg = getMinorMessage(env, jstub, minor); + if ((*env)->ExceptionCheck(env)) { + return; + } (*env)->CallVoidMethod(env, jprop, MID_MessageProp_setSupplementaryStates, isDuplicate, isOld, isUnseq, hasGap, minor, minorMsg); @@ -265,21 +275,26 @@ jobjectArray result; if (ftab->inquireNamesForMech != NULL) { + mech = (gss_OID)jlong_to_ptr((*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech)); + nameTypes = GSS_C_NO_OID_SET; - mech = (gss_OID)jlong_to_ptr((*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech)); - nameTypes = GSS_C_NO_OID_SET; - - /* gss_inquire_names_for_mech(...) => N/A */ - major = (*ftab->inquireNamesForMech)(&minor, mech, &nameTypes); + /* gss_inquire_names_for_mech(...) => N/A */ + major = (*ftab->inquireNamesForMech)(&minor, mech, &nameTypes); - result = getJavaOIDArray(env, nameTypes); + /* release intermediate buffers before checking status */ + result = getJavaOIDArray(env, nameTypes); + deleteGSSOIDSet(nameTypes); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } - /* release intermediate buffers */ - deleteGSSOIDSet(nameTypes); - - checkStatus(env, jobj, major, minor, "[GSSLibStub_inquireNamesForMech]"); - return result; - } else return NULL; + checkStatus(env, jobj, major, minor, "[GSSLibStub_inquireNamesForMech]"); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + return result; + } + return NULL; } /* @@ -297,8 +312,7 @@ nameHdl = (gss_name_t) jlong_to_ptr(pName); - sprintf(debugBuf, "[GSSLibStub_releaseName] %ld", (long) pName); - debug(env, debugBuf); + TRACE1("[GSSLibStub_releaseName] %ld", (long) pName); if (nameHdl != GSS_C_NO_NAME) { /* gss_release_name(...) => GSS_S_BAD_NAME */ @@ -324,13 +338,16 @@ gss_name_t nameHdl; nameHdl = GSS_C_NO_NAME; - debug(env, "[GSSLibStub_importName]"); + TRACE0("[GSSLibStub_importName]"); initGSSBuffer(env, jnameVal, &nameVal); + if ((*env)->ExceptionCheck(env)) { + return jlong_zero; + } + nameType = newGSSOID(env, jnameType); if ((*env)->ExceptionCheck(env)) { - deleteGSSOID(nameType); - resetGSSBuffer(env, jnameVal, &nameVal); + resetGSSBuffer(&nameVal); return jlong_zero; } @@ -338,14 +355,16 @@ GSS_S_BAD_MECH */ major = (*ftab->importName)(&minor, &nameVal, nameType, &nameHdl); - sprintf(debugBuf, "[GSSLibStub_importName] %ld", (long) nameHdl); - debug(env, debugBuf); + TRACE1("[GSSLibStub_importName] %ld", (long) nameHdl); /* release intermediate buffers */ deleteGSSOID(nameType); - resetGSSBuffer(env, jnameVal, &nameVal); + resetGSSBuffer(&nameVal); checkStatus(env, jobj, major, minor, "[GSSLibStub_importName]"); + if ((*env)->ExceptionCheck(env)) { + return jlong_zero; + } return ptr_to_jlong(nameHdl); } @@ -369,9 +388,7 @@ nameHdl1 = (gss_name_t) jlong_to_ptr(pName1); nameHdl2 = (gss_name_t) jlong_to_ptr(pName2); - sprintf(debugBuf, "[GSSLibStub_compareName] %ld %ld", (long) pName1, - (long) pName2); - debug(env, debugBuf); + TRACE2("[GSSLibStub_compareName] %ld %ld", (long)pName1, (long)pName2); if ((nameHdl1 != GSS_C_NO_NAME) && (nameHdl2 != GSS_C_NO_NAME)) { @@ -398,8 +415,8 @@ gss_OID mech; nameHdl = (gss_name_t) jlong_to_ptr(pName); - sprintf(debugBuf, "[GSSLibStub_canonicalizeName] %ld", (long) pName); - debug(env, debugBuf); + + TRACE1("[GSSLibStub_canonicalizeName] %ld", (long) pName); if (nameHdl != GSS_C_NO_NAME) { mech = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech)); @@ -409,16 +426,15 @@ GSS_S_BAD_NAME, GSS_S_BAD_MECH */ major = (*ftab->canonicalizeName)(&minor, nameHdl, mech, &mnNameHdl); - sprintf(debugBuf, "[GSSLibStub_canonicalizeName] MN=%ld", - (long)mnNameHdl); - debug(env, debugBuf); - - /* release intermediate buffers */ + TRACE1("[GSSLibStub_canonicalizeName] MN=%ld", (long)mnNameHdl); checkStatus(env, jobj, major, minor, "[GSSLibStub_canonicalizeName]"); - } else mnNameHdl = GSS_C_NO_NAME; - - return ptr_to_jlong(mnNameHdl); + if ((*env)->ExceptionCheck(env)) { + return (jlong) GSS_C_NO_NAME; + } + return ptr_to_jlong(mnNameHdl); + } + return (jlong) GSS_C_NO_NAME; } /* @@ -436,8 +452,8 @@ jbyteArray jresult; nameHdl = (gss_name_t) jlong_to_ptr(pName); - sprintf(debugBuf, "[GSSLibStub_exportName] %ld", (long) pName); - debug(env, debugBuf); + + TRACE1("[GSSLibStub_exportName] %ld", (long) pName); /* gss_export_name(...) => GSS_S_NAME_NOT_MN, GSS_S_BAD_NAMETYPE, GSS_S_BAD_NAME */ @@ -445,28 +461,38 @@ /* canonicalize the internal name to MN and retry */ if (major == GSS_S_NAME_NOT_MN) { - debug(env, "[GSSLibStub_exportName] canonicalize and re-try"); + /* release intermediate buffers before retrying */ + (*ftab->releaseBuffer)(&minor, &outBuf); + + TRACE0("[GSSLibStub_exportName] canonicalize and re-try"); mNameHdl = (gss_name_t)jlong_to_ptr( Java_sun_security_jgss_wrapper_GSSLibStub_canonicalizeName (env, jobj, pName)); - /* return immediately if an exception has occurred */ if ((*env)->ExceptionCheck(env)) { - return NULL; + return NULL; } + major = (*ftab->exportName)(&minor, mNameHdl, &outBuf); Java_sun_security_jgss_wrapper_GSSLibStub_releaseName (env, jobj, ptr_to_jlong(mNameHdl)); - /* return immediately if an exception has occurred */ if ((*env)->ExceptionCheck(env)) { + /* release intermediate buffers */ + (*ftab->releaseBuffer)(&minor, &outBuf); return NULL; } } - /* release intermediate buffers */ + /* release intermediate buffers before checking status */ jresult = getJavaBuffer(env, &outBuf); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } checkStatus(env, jobj, major, minor, "[GSSLibStub_exportName]"); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } return jresult; } @@ -488,8 +514,8 @@ jobjectArray jresult; nameHdl = (gss_name_t) jlong_to_ptr(pName); - sprintf(debugBuf, "[GSSLibStub_displayName] %ld", (long) pName); - debug(env, debugBuf); + + TRACE1("[GSSLibStub_displayName] %ld", (long) pName); if (nameHdl == GSS_C_NO_NAME) { checkStatus(env, jobj, GSS_S_BAD_NAME, 0, "[GSSLibStub_displayName]"); @@ -499,21 +525,37 @@ /* gss_display_name(...) => GSS_S_BAD_NAME */ major = (*ftab->displayName)(&minor, nameHdl, &outNameBuf, &outNameType); - /* release intermediate buffers */ + /* release intermediate buffers before checking status */ jname = getJavaString(env, &outNameBuf); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + + checkStatus(env, jobj, major, minor, "[GSSLibStub_displayName]"); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } jtype = getJavaOID(env, outNameType); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + jresult = (*env)->NewObjectArray(env, 2, CLS_Object, NULL); - /* return immediately if an exception has occurred */ if ((*env)->ExceptionCheck(env)) { return NULL; } (*env)->SetObjectArrayElement(env, jresult, 0, jname); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } (*env)->SetObjectArrayElement(env, jresult, 1, jtype); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } - checkStatus(env, jobj, major, minor, "[GSSLibStub_displayName]"); return jresult; } @@ -537,20 +579,14 @@ gss_cred_id_t credHdl; credHdl = GSS_C_NO_CREDENTIAL; - debug(env, "[GSSLibStub_acquireCred]"); - + TRACE0("[GSSLibStub_acquireCred]"); mech = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech)); - mechs = newGSSOIDSet(env, mech); - if ((*env)->ExceptionCheck(env)) { - return jlong_zero; - } + mechs = newGSSOIDSet(mech); credUsage = (gss_cred_usage_t) usage; nameHdl = (gss_name_t) jlong_to_ptr(pName); - sprintf(debugBuf, "[GSSLibStub_acquireCred] pName=%ld, usage=%d", - (long) pName, usage); - debug(env, debugBuf); + TRACE2("[GSSLibStub_acquireCred] pName=%ld, usage=%d", (long)pName, usage); /* gss_acquire_cred(...) => GSS_S_BAD_MECH, GSS_S_BAD_NAMETYPE, GSS_S_BAD_NAME, GSS_S_CREDENTIALS_EXPIRED, GSS_S_NO_CRED */ @@ -560,10 +596,12 @@ /* release intermediate buffers */ deleteGSSOIDSet(mechs); - sprintf(debugBuf, "[GSSLibStub_acquireCred] pCred=%ld", (long) credHdl); - debug(env, debugBuf); + TRACE1("[GSSLibStub_acquireCred] pCred=%ld", (long) credHdl); checkStatus(env, jobj, major, minor, "[GSSLibStub_acquireCred]"); + if ((*env)->ExceptionCheck(env)) { + return jlong_zero; + } return ptr_to_jlong(credHdl); } @@ -582,15 +620,16 @@ credHdl = (gss_cred_id_t) jlong_to_ptr(pCred); - sprintf(debugBuf, "[GSSLibStub_releaseCred] %ld", (long int)pCred); - debug(env, debugBuf); + TRACE1("[GSSLibStub_releaseCred] %ld", (long int)pCred); if (credHdl != GSS_C_NO_CREDENTIAL) { - /* gss_release_cred(...) => GSS_S_NO_CRED(!) */ major = (*ftab->releaseCred)(&minor, &credHdl); checkStatus(env, jobj, major, minor, "[GSSLibStub_releaseCred]"); + if ((*env)->ExceptionCheck(env)) { + return jlong_zero; + } } return ptr_to_jlong(credHdl); } @@ -606,8 +645,7 @@ credHdl = pCred; - sprintf(debugBuf, "[gss_inquire_cred] %ld", (long) pCred); - debug(env, debugBuf); + TRACE1("[gss_inquire_cred] %ld", (long) pCred); /* gss_inquire_cred(...) => GSS_S_DEFECTIVE_CREDENTIAL(!), GSS_S_CREDENTIALS_EXPIRED(!), GSS_S_NO_CRED(!) */ @@ -619,8 +657,6 @@ major = (*ftab->inquireCred)(&minor, credHdl, NULL, NULL, result, NULL); } - /* release intermediate buffers */ - routineErr = GSS_ROUTINE_ERROR(major); if (routineErr == GSS_S_CREDENTIALS_EXPIRED) { /* ignore GSS_S_CREDENTIALS_EXPIRED for query */ @@ -649,20 +685,16 @@ credHdl = (gss_cred_id_t) jlong_to_ptr(pCred); - sprintf(debugBuf, "[GSSLibStub_getCredName] %ld", (long int)pCred); - debug(env, debugBuf); + TRACE1("[GSSLibStub_getCredName] %ld", (long int)pCred); nameHdl = GSS_C_NO_NAME; inquireCred(env, jobj, credHdl, TYPE_CRED_NAME, &nameHdl); - /* return immediately if an exception has occurred */ if ((*env)->ExceptionCheck(env)) { return jlong_zero; } - sprintf(debugBuf, "[GSSLibStub_getCredName] pName=%ld", (long) nameHdl); - debug(env, debugBuf); - + TRACE1("[GSSLibStub_getCredName] pName=%ld", (long) nameHdl); return ptr_to_jlong(nameHdl); } @@ -681,12 +713,10 @@ credHdl = (gss_cred_id_t) jlong_to_ptr(pCred); - sprintf(debugBuf, "[GSSLibStub_getCredTime] %ld", (long int)pCred); - debug(env, debugBuf); + TRACE1("[GSSLibStub_getCredTime] %ld", (long int)pCred); lifetime = 0; inquireCred(env, jobj, credHdl, TYPE_CRED_TIME, &lifetime); - /* return immediately if an exception has occurred */ if ((*env)->ExceptionCheck(env)) { return 0; @@ -709,11 +739,9 @@ credHdl = (gss_cred_id_t) jlong_to_ptr(pCred); - sprintf(debugBuf, "[GSSLibStub_getCredUsage] %ld", (long int)pCred); - debug(env, debugBuf); + TRACE1("[GSSLibStub_getCredUsage] %ld", (long int)pCred); inquireCred(env, jobj, credHdl, TYPE_CRED_USAGE, &usage); - /* return immediately if an exception has occurred */ if ((*env)->ExceptionCheck(env)) { return -1; @@ -735,21 +763,22 @@ gss_ctx_id_t contextHdl; gss_OID mech, mech2; - debug(env, "[GSSLibStub_importContext]"); + TRACE0("[GSSLibStub_importContext]"); contextHdl = GSS_C_NO_CONTEXT; initGSSBuffer(env, jctxtToken, &ctxtToken); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } /* gss_import_sec_context(...) => GSS_S_NO_CONTEXT, GSS_S_DEFECTIVE_TOKEN, GSS_S_UNAVAILABLE, GSS_S_UNAUTHORIZED */ major = (*ftab->importSecContext)(&minor, &ctxtToken, &contextHdl); - sprintf(debugBuf, "[GSSLibStub_importContext] pContext=%ld", - (long) contextHdl); - debug(env, debugBuf); + TRACE1("[GSSLibStub_importContext] pContext=%ld", (long) contextHdl); /* release intermediate buffers */ - resetGSSBuffer(env, jctxtToken, &ctxtToken); + resetGSSBuffer(&ctxtToken); checkStatus(env, jobj, major, minor, "[GSSLibStub_importContext]"); /* return immediately if an exception has occurred */ @@ -768,9 +797,10 @@ return NULL; } - mech2 = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jobj, FID_GSSLibStub_pMech)); + mech2 = (gss_OID) jlong_to_ptr((*env)->GetLongField(env, jobj, + FID_GSSLibStub_pMech)); - if (sameMech(env, mech, mech2) == JNI_TRUE) { + if (sameMech(mech, mech2) == JNI_TRUE) { /* mech match - return the context object */ return (*env)->NewObject(env, CLS_NativeGSSContext, MID_NativeGSSContext_ctor, @@ -779,10 +809,11 @@ /* mech mismatch - clean up then return null */ major = (*ftab->deleteSecContext)(&minor, &contextHdl, GSS_C_NO_BUFFER); checkStatus(env, jobj, major, minor, - "[GSSLibStub_importContext] cleanup"); + "[GSSLibStub_importContext] cleanup"); return NULL; } } + /* * Class: sun_security_jgss_wrapper_GSSLibStub * Method: initContext @@ -812,7 +843,8 @@ gss_OID aMech; jobject jMech; */ - debug(env, "[GSSLibStub_initContext]"); + + TRACE0("[GSSLibStub_initContext]"); credHdl = (gss_cred_id_t) jlong_to_ptr(pCred); contextHdl = (gss_ctx_id_t) jlong_to_ptr( @@ -823,18 +855,19 @@ FID_NativeGSSContext_flags); time = getGSSTime((*env)->GetIntField(env, jcontextSpi, FID_NativeGSSContext_lifetime)); - cb = getGSSCB(env, jcb); + cb = newGSSCB(env, jcb); if ((*env)->ExceptionCheck(env)) { - free(cb); return NULL; } initGSSBuffer(env, jinToken, &inToken); + if ((*env)->ExceptionCheck(env)) { + deleteGSSCB(cb); + return NULL; + } - sprintf(debugBuf, - "[GSSLibStub_initContext] before: pCred=%ld, pContext=%ld", + TRACE2( "[GSSLibStub_initContext] before: pCred=%ld, pContext=%ld", (long)credHdl, (long)contextHdl); - debug(env, debugBuf); /* gss_init_sec_context(...) => GSS_S_CONTINUE_NEEDED(!), GSS_S_DEFECTIVE_TOKEN, GSS_S_NO_CRED, GSS_S_DEFECTIVE_CREDENTIAL(!), @@ -842,29 +875,24 @@ GSS_S_OLD_TOKEN, GSS_S_DUPLICATE_TOKEN, GSS_S_NO_CONTEXT(!), GSS_S_BAD_NAMETYPE, GSS_S_BAD_NAME(!), GSS_S_BAD_MECH */ major = (*ftab->initSecContext)(&minor, credHdl, - &contextHdl, targetName, mech, - flags, time, cb, &inToken, NULL /*aMech*/, - &outToken, &aFlags, &aTime); + &contextHdl, targetName, mech, + flags, time, cb, &inToken, NULL /*aMech*/, + &outToken, &aFlags, &aTime); - sprintf(debugBuf, "[GSSLibStub_initContext] after: pContext=%ld", - (long)contextHdl); - debug(env, debugBuf); - sprintf(debugBuf, "[GSSLibStub_initContext] outToken len=%ld", - (long)outToken.length); - debug(env, debugBuf); + TRACE2("[GSSLibStub_initContext] after: pContext=%ld, outToken len=%ld", + (long)contextHdl, (long)outToken.length); if (GSS_ERROR(major) == GSS_S_COMPLETE) { /* update member values if needed */ (*env)->SetLongField(env, jcontextSpi, FID_NativeGSSContext_pContext, ptr_to_jlong(contextHdl)); (*env)->SetIntField(env, jcontextSpi, FID_NativeGSSContext_flags, aFlags); - sprintf(debugBuf, "[GSSLibStub_initContext] set flags=0x%x", aFlags); - debug(env, debugBuf); + TRACE1("[GSSLibStub_initContext] set flags=0x%x", aFlags); if (major == GSS_S_COMPLETE) { (*env)->SetIntField(env, jcontextSpi, FID_NativeGSSContext_lifetime, getJavaTime(aTime)); - debug(env, "[GSSLibStub_initContext] context established"); + TRACE0("[GSSLibStub_initContext] context established"); (*env)->SetBooleanField(env, jcontextSpi, FID_NativeGSSContext_isEstablished, @@ -876,16 +904,23 @@ FID_NativeGSSContext_actualMech, jMech); */ } else if (major & GSS_S_CONTINUE_NEEDED) { - debug(env, "[GSSLibStub_initContext] context not established"); + TRACE0("[GSSLibStub_initContext] context not established"); major -= GSS_S_CONTINUE_NEEDED; } } - /* release intermediate buffers */ - releaseGSSCB(env, jcb, cb); - resetGSSBuffer(env, jinToken, &inToken); + + /* release intermediate buffers before checking status */ + deleteGSSCB(cb); + resetGSSBuffer(&inToken); jresult = getJavaBuffer(env, &outToken); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } checkStatus(env, jobj, major, minor, "[GSSLibStub_initContext]"); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } return jresult; } @@ -922,27 +957,27 @@ gss_name_t targetName; jobject jtargetName; - debug(env, "[GSSLibStub_acceptContext]"); + TRACE0("[GSSLibStub_acceptContext]"); contextHdl = (gss_ctx_id_t)jlong_to_ptr( (*env)->GetLongField(env, jcontextSpi, FID_NativeGSSContext_pContext)); credHdl = (gss_cred_id_t) jlong_to_ptr(pCred); initGSSBuffer(env, jinToken, &inToken); - cb = getGSSCB(env, jcb); if ((*env)->ExceptionCheck(env)) { - free(cb); - resetGSSBuffer(env, jinToken, &inToken); return NULL; } - srcName = GSS_C_NO_NAME; + cb = newGSSCB(env, jcb); + if ((*env)->ExceptionCheck(env)) { + resetGSSBuffer(&inToken); + return NULL; + } + srcName = targetName = GSS_C_NO_NAME; delCred = GSS_C_NO_CREDENTIAL; setTarget = (credHdl == GSS_C_NO_CREDENTIAL); aFlags = 0; - sprintf(debugBuf, - "[GSSLibStub_acceptContext] before: pCred=%ld, pContext=%ld", + TRACE2( "[GSSLibStub_acceptContext] before: pCred=%ld, pContext=%ld", (long) credHdl, (long) contextHdl); - debug(env, debugBuf); /* gss_accept_sec_context(...) => GSS_S_CONTINUE_NEEDED(!), GSS_S_DEFECTIVE_TOKEN, GSS_S_DEFECTIVE_CREDENTIAL(!), @@ -953,91 +988,107 @@ (*ftab->acceptSecContext)(&minor, &contextHdl, credHdl, &inToken, cb, &srcName, &aMech, &outToken, &aFlags, &aTime, &delCred); + /* release intermediate buffers before checking status */ - sprintf(debugBuf, - "[GSSLibStub_acceptContext] after: pCred=%ld, pContext=%ld, pDelegCred=%ld", + deleteGSSCB(cb); + resetGSSBuffer(&inToken); + + TRACE3("[GSSLibStub_acceptContext] after: pCred=%ld, pContext=%ld, pDelegCred=%ld", (long)credHdl, (long)contextHdl, (long) delCred); - debug(env, debugBuf); if (GSS_ERROR(major) == GSS_S_COMPLETE) { /* update member values if needed */ (*env)->SetLongField(env, jcontextSpi, FID_NativeGSSContext_pContext, ptr_to_jlong(contextHdl)); - sprintf(debugBuf, "[GSSLibStub_acceptContext] set pContext=%ld", + TRACE1("[GSSLibStub_acceptContext] set pContext=%ld", (long)contextHdl); - debug(env, debugBuf); + // WORKAROUND for a Heimdal bug if (delCred == GSS_C_NO_CREDENTIAL) { aFlags &= 0xfffffffe; } (*env)->SetIntField(env, jcontextSpi, FID_NativeGSSContext_flags, aFlags); - sprintf(debugBuf, "[GSSLibStub_acceptContext] set flags=0x%x", - aFlags); - debug(env, debugBuf); + + TRACE1("[GSSLibStub_acceptContext] set flags=0x%x", aFlags); + if (setTarget) { major2 = (*ftab->inquireContext)(&minor2, contextHdl, NULL, &targetName, NULL, NULL, NULL, NULL, NULL); + checkStatus(env, jobj, major2, minor2, + "[GSSLibStub_acceptContext] inquire"); + if ((*env)->ExceptionCheck(env)) { + goto error; + } + jtargetName = (*env)->NewObject(env, CLS_GSSNameElement, MID_GSSNameElement_ctor, ptr_to_jlong(targetName), jobj); + if ((*env)->ExceptionCheck(env)) { + goto error; + } - /* return immediately if an exception has occurred */ - if ((*env)->ExceptionCheck(env)) { - resetGSSBuffer(env, jinToken, &inToken); - return NULL; - } - sprintf(debugBuf, "[GSSLibStub_acceptContext] set targetName=%ld", + TRACE1("[GSSLibStub_acceptContext] set targetName=%ld", (long)targetName); - debug(env, debugBuf); + (*env)->SetObjectField(env, jcontextSpi, FID_NativeGSSContext_targetName, jtargetName); + if ((*env)->ExceptionCheck(env)) { + goto error; + } } if (srcName != GSS_C_NO_NAME) { jsrcName = (*env)->NewObject(env, CLS_GSSNameElement, MID_GSSNameElement_ctor, ptr_to_jlong(srcName), jobj); - /* return immediately if an exception has occurred */ if ((*env)->ExceptionCheck(env)) { - resetGSSBuffer(env, jinToken, &inToken); - return NULL; + goto error; } - sprintf(debugBuf, "[GSSLibStub_acceptContext] set srcName=%ld", - (long)srcName); - debug(env, debugBuf); + + TRACE1("[GSSLibStub_acceptContext] set srcName=%ld", (long)srcName); + (*env)->SetObjectField(env, jcontextSpi, FID_NativeGSSContext_srcName, jsrcName); + if ((*env)->ExceptionCheck(env)) { + goto error; + } } if (major == GSS_S_COMPLETE) { - debug(env, "[GSSLibStub_acceptContext] context established"); + TRACE0("[GSSLibStub_acceptContext] context established"); (*env)->SetIntField(env, jcontextSpi, FID_NativeGSSContext_lifetime, getJavaTime(aTime)); - (*env)->SetBooleanField(env, jcontextSpi, FID_NativeGSSContext_isEstablished, JNI_TRUE); jMech = getJavaOID(env, aMech); + if ((*env)->ExceptionCheck(env)) { + goto error; + } (*env)->SetObjectField(env, jcontextSpi, FID_NativeGSSContext_actualMech, jMech); + if ((*env)->ExceptionCheck(env)) { + goto error; + } if (delCred != GSS_C_NO_CREDENTIAL) { jdelCred = (*env)->NewObject(env, CLS_GSSCredElement, MID_GSSCredElement_ctor, ptr_to_jlong(delCred), jsrcName, jMech); - /* return immediately if an exception has occurred */ if ((*env)->ExceptionCheck(env)) { - resetGSSBuffer(env, jinToken, &inToken); - return NULL; + goto error; } (*env)->SetObjectField(env, jcontextSpi, FID_NativeGSSContext_delegatedCred, jdelCred); - sprintf(debugBuf, "[GSSLibStub_acceptContext] set delegatedCred=%ld", + TRACE1("[GSSLibStub_acceptContext] set delegatedCred=%ld", (long) delCred); - debug(env, debugBuf); + + if ((*env)->ExceptionCheck(env)) { + goto error; + } } } else if (major & GSS_S_CONTINUE_NEEDED) { - debug(env, "[GSSLibStub_acceptContext] context not established"); + TRACE0("[GSSLibStub_acceptContext] context not established"); if (aFlags & GSS_C_PROT_READY_FLAG) { (*env)->SetIntField(env, jcontextSpi, FID_NativeGSSContext_lifetime, @@ -1046,13 +1097,20 @@ major -= GSS_S_CONTINUE_NEEDED; } } - /* release intermediate buffers */ - releaseGSSCB(env, jcb, cb); - resetGSSBuffer(env, jinToken, &inToken); - jresult = getJavaBuffer(env, &outToken); + return getJavaBuffer(env, &outToken); - checkStatus(env, jobj, major, minor, "[GSSLibStub_acceptContext]"); - return jresult; +error: + (*ftab->releaseBuffer)(&minor, &outToken); + if (srcName != GSS_C_NO_NAME) { + (*ftab->releaseName)(&minor, &srcName); + } + if (targetName != GSS_C_NO_NAME) { + (*ftab->releaseName)(&minor, &targetName); + } + if (delCred != GSS_C_NO_CREDENTIAL) { + (*ftab->releaseCred) (&minor, &delCred); + } + return NULL; } /* @@ -1076,8 +1134,7 @@ contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext); - sprintf(debugBuf, "[GSSLibStub_inquireContext] %ld", (long)contextHdl); - debug(env, debugBuf); + TRACE1("[GSSLibStub_inquireContext] %ld", (long)contextHdl); srcName = targetName = GSS_C_NO_NAME; time = 0; @@ -1088,12 +1145,13 @@ &targetName, &time, NULL, &flags, &isInitiator, &isEstablished); /* update member values if needed */ - sprintf(debugBuf, "[GSSLibStub_inquireContext] srcName %ld", (long)srcName); - debug(env, debugBuf); - sprintf(debugBuf, "[GSSLibStub_inquireContext] targetName %ld", - (long)targetName); - debug(env, debugBuf); + TRACE2("[GSSLibStub_inquireContext] srcName %ld, targetName %ld", + (long)srcName, (long)targetName); + checkStatus(env, jobj, major, minor, "[GSSLibStub_inquireContext]"); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } result[0] = ptr_to_jlong(srcName); result[1] = ptr_to_jlong(targetName); result[2] = (jlong) isInitiator; @@ -1102,11 +1160,13 @@ result[5] = (jlong) getJavaTime(time); jresult = (*env)->NewLongArray(env, 6); + if (jresult == NULL) { + return NULL; + } (*env)->SetLongArrayRegion(env, jresult, 0, 6, result); - - /* release intermediate buffers */ - - checkStatus(env, jobj, major, minor, "[GSSLibStub_inquireContext]"); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } return jresult; } @@ -1126,8 +1186,7 @@ contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext); - sprintf(debugBuf, "[GSSLibStub_getContextMech] %ld", (long int)pContext); - debug(env, debugBuf); + TRACE1("[GSSLibStub_getContextMech] %ld", (long int)pContext); major = (*ftab->inquireContext)(&minor, contextHdl, NULL, NULL, NULL, &mech, NULL, NULL, NULL); @@ -1156,9 +1215,8 @@ contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext); - sprintf(debugBuf, "[GSSLibStub_getContextName] %ld, isSrc=%d", + TRACE2("[GSSLibStub_getContextName] %ld, isSrc=%d", (long)contextHdl, isSrc); - debug(env, debugBuf); nameHdl = GSS_C_NO_NAME; if (isSrc == JNI_TRUE) { @@ -1175,8 +1233,7 @@ return jlong_zero; } - sprintf(debugBuf, "[GSSLibStub_getContextName] pName=%ld", (long) nameHdl); - debug(env, debugBuf); + TRACE1("[GSSLibStub_getContextName] pName=%ld", (long) nameHdl); return ptr_to_jlong(nameHdl); } @@ -1195,8 +1252,8 @@ OM_uint32 time; contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext); - sprintf(debugBuf, "[GSSLibStub_getContextTime] %ld", (long)contextHdl); - debug(env, debugBuf); + + TRACE1("[GSSLibStub_getContextTime] %ld", (long)contextHdl); if (contextHdl == GSS_C_NO_CONTEXT) return 0; @@ -1207,6 +1264,9 @@ major = GSS_CALLING_ERROR(major) | GSS_SUPPLEMENTARY_INFO(major); } checkStatus(env, jobj, major, minor, "[GSSLibStub_getContextTime]"); + if ((*env)->ExceptionCheck(env)) { + return 0; + } return getJavaTime(time); } @@ -1224,8 +1284,8 @@ gss_ctx_id_t contextHdl; contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext); - sprintf(debugBuf, "[GSSLibStub_deleteContext] %ld", (long)contextHdl); - debug(env, debugBuf); + + TRACE1("[GSSLibStub_deleteContext] %ld", (long)contextHdl); if (contextHdl == GSS_C_NO_CONTEXT) return ptr_to_jlong(GSS_C_NO_CONTEXT); @@ -1233,6 +1293,9 @@ major = (*ftab->deleteSecContext)(&minor, &contextHdl, GSS_C_NO_BUFFER); checkStatus(env, jobj, major, minor, "[GSSLibStub_deleteContext]"); + if ((*env)->ExceptionCheck(env)) { + return jlong_zero; + } return (jlong) ptr_to_jlong(contextHdl); } @@ -1255,20 +1318,27 @@ gss_qop_t qop; contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext); - sprintf(debugBuf, "[GSSLibStub_wrapSizeLimit] %ld", (long)contextHdl); - debug(env, debugBuf); + + TRACE1("[GSSLibStub_wrapSizeLimit] %ld", (long)contextHdl); - // Check context handle?? + if (contextHdl == GSS_C_NO_CONTEXT) { + // Twik per javadoc + checkStatus(env, jobj, GSS_S_NO_CONTEXT, 0, + "[GSSLibStub_wrapSizeLimit]"); + return 0; + } qop = (gss_qop_t) jqop; outSize = (OM_uint32) joutSize; - maxInSize = 0; /* gss_wrap_size_limit(...) => GSS_S_NO_CONTEXT(!), GSS_S_CONTEXT_EXPIRED, GSS_S_BAD_QOP */ major = (*ftab->wrapSizeLimit)(&minor, contextHdl, reqFlag, qop, outSize, &maxInSize); checkStatus(env, jobj, major, minor, "[GSSLibStub_wrapSizeLimit]"); + if ((*env)->ExceptionCheck(env)) { + return 0; + } return (jint) maxInSize; } @@ -1288,8 +1358,8 @@ jbyteArray jresult; contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext); - sprintf(debugBuf, "[GSSLibStub_exportContext] %ld", (long)contextHdl); - debug(env, debugBuf); + + TRACE1("[GSSLibStub_exportContext] %ld", (long)contextHdl); if (contextHdl == GSS_C_NO_CONTEXT) { // Twik per javadoc @@ -1303,7 +1373,14 @@ /* release intermediate buffers */ jresult = getJavaBuffer(env, &interProcToken); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } checkStatus(env, jobj, major, minor, "[GSSLibStub_exportContext]"); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + return jresult; } @@ -1325,8 +1402,8 @@ jbyteArray jresult; contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext); - sprintf(debugBuf, "[GSSLibStub_getMic] %ld", (long)contextHdl); - debug(env, debugBuf); + + TRACE1("[GSSLibStub_getMic] %ld", (long)contextHdl); if (contextHdl == GSS_C_NO_CONTEXT) { // Twik per javadoc @@ -1336,6 +1413,9 @@ contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext); qop = (gss_qop_t) jqop; initGSSBuffer(env, jmsg, &msg); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } /* gss_get_mic(...) => GSS_S_CONTEXT_EXPIRED, GSS_S_NO_CONTEXT(!), GSS_S_BAD_QOP */ @@ -1343,10 +1423,16 @@ (*ftab->getMic)(&minor, contextHdl, qop, &msg, &msgToken); /* release intermediate buffers */ - resetGSSBuffer(env, jmsg, &msg); + resetGSSBuffer(&msg); jresult = getJavaBuffer(env, &msgToken); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + checkStatus(env, jobj, major, minor, "[GSSLibStub_getMic]"); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } - checkStatus(env, jobj, major, minor, "[GSSLibStub_getMic]"); return jresult; } @@ -1370,8 +1456,8 @@ gss_qop_t qop; contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext); - sprintf(debugBuf, "[GSSLibStub_verifyMic] %ld", (long)contextHdl); - debug(env, debugBuf); + + TRACE1("[GSSLibStub_verifyMic] %ld", (long)contextHdl); if (contextHdl == GSS_C_NO_CONTEXT) { // Twik per javadoc @@ -1379,9 +1465,19 @@ "[GSSLibStub_verifyMic]"); return; } + + qop = (gss_qop_t) (*env)->CallIntMethod(env, jprop, MID_MessageProp_getQOP); + if ((*env)->ExceptionCheck(env)) { return; } + initGSSBuffer(env, jmsg, &msg); + if ((*env)->ExceptionCheck(env)) { return; } + initGSSBuffer(env, jmsgToken, &msgToken); - qop = (gss_qop_t) (*env)->CallIntMethod(env, jprop, MID_MessageProp_getQOP); + if ((*env)->ExceptionCheck(env)) { + resetGSSBuffer(&msg); + return; + } + /* gss_verify_mic(...) => GSS_S_DEFECTIVE_TOKEN, GSS_S_BAD_MIC, GSS_S_CONTEXT_EXPIRED, GSS_S_DUPLICATE_TOKEN(!), GSS_S_OLD_TOKEN(!), GSS_S_UNSEQ_TOKEN(!), GSS_S_GAP_TOKEN(!), GSS_S_NO_CONTEXT(!) */ @@ -1389,13 +1485,24 @@ (*ftab->verifyMic)(&minor, contextHdl, &msg, &msgToken, &qop); /* release intermediate buffers */ - resetGSSBuffer(env, jmsg, &msg); - resetGSSBuffer(env, jmsgToken, &msgToken); + resetGSSBuffer(&msg); + resetGSSBuffer(&msgToken); + + checkStatus(env, jobj, GSS_ERROR(major), minor, "[GSSLibStub_verifyMic]"); + if ((*env)->ExceptionCheck(env)) { + return; + } (*env)->CallVoidMethod(env, jprop, MID_MessageProp_setQOP, qop); + if ((*env)->ExceptionCheck(env)) { + return; + } + setSupplementaryInfo(env, jobj, jprop, GSS_SUPPLEMENTARY_INFO(major), minor); - checkStatus(env, jobj, GSS_ERROR(major), minor, "[GSSLibStub_verifyMic]"); + if ((*env)->ExceptionCheck(env)) { + return; + } } /* @@ -1420,8 +1527,8 @@ jbyteArray jresult; contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext); - sprintf(debugBuf, "[GSSLibStub_wrap] %ld", (long)contextHdl); - debug(env, debugBuf); + + TRACE1("[GSSLibStub_wrap] %ld", (long)contextHdl); if (contextHdl == GSS_C_NO_CONTEXT) { // Twik per javadoc @@ -1431,22 +1538,43 @@ confFlag = (*env)->CallBooleanMethod(env, jprop, MID_MessageProp_getPrivacy); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + qop = (gss_qop_t) (*env)->CallIntMethod(env, jprop, MID_MessageProp_getQOP); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + initGSSBuffer(env, jmsg, &msg); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + /* gss_wrap(...) => GSS_S_CONTEXT_EXPIRED, GSS_S_NO_CONTEXT(!), GSS_S_BAD_QOP */ major = (*ftab->wrap)(&minor, contextHdl, confFlag, qop, &msg, &confState, &msgToken); + /* release intermediate buffers */ + resetGSSBuffer(&msg); + jresult = getJavaBuffer(env, &msgToken); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + + checkStatus(env, jobj, major, minor, "[GSSLibStub_wrap]"); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + (*env)->CallVoidMethod(env, jprop, MID_MessageProp_setPrivacy, (confState? JNI_TRUE:JNI_FALSE)); - - /* release intermediate buffers */ - resetGSSBuffer(env, jmsg, &msg); - jresult = getJavaBuffer(env, &msgToken); - - checkStatus(env, jobj, major, minor, "[GSSLibStub_wrap]"); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } return jresult; } @@ -1471,15 +1599,20 @@ jbyteArray jresult; contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext); - sprintf(debugBuf, "[GSSLibStub_unwrap] %ld", (long)contextHdl); - debug(env, debugBuf); + + TRACE1("[GSSLibStub_unwrap] %ld", (long)contextHdl); if (contextHdl == GSS_C_NO_CONTEXT) { // Twik per javadoc checkStatus(env, jobj, GSS_S_CONTEXT_EXPIRED, 0, "[GSSLibStub_unwrap]"); return NULL; } + initGSSBuffer(env, jmsgToken, &msgToken); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + confState = 0; qop = GSS_C_QOP_DEFAULT; /* gss_unwrap(...) => GSS_S_DEFECTIVE_TOKEN, GSS_S_BAD_MIC, @@ -1487,17 +1620,34 @@ GSS_S_UNSEQ_TOKEN(!), GSS_S_GAP_TOKEN(!), GSS_S_NO_CONTEXT(!) */ major = (*ftab->unwrap)(&minor, contextHdl, &msgToken, &msg, &confState, &qop); + + /* release intermediate buffers */ + resetGSSBuffer(&msgToken); + jresult = getJavaBuffer(env, &msg); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + + checkStatus(env, jobj, GSS_ERROR(major), minor, "[GSSLibStub_unwrap]"); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + /* update the message prop with relevant info */ (*env)->CallVoidMethod(env, jprop, MID_MessageProp_setPrivacy, (confState != 0)); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } (*env)->CallVoidMethod(env, jprop, MID_MessageProp_setQOP, qop); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } setSupplementaryInfo(env, jobj, jprop, GSS_SUPPLEMENTARY_INFO(major), - minor); + minor); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } - /* release intermediate buffers */ - resetGSSBuffer(env, jmsgToken, &msgToken); - jresult = getJavaBuffer(env, &msg); - - checkStatus(env, jobj, GSS_ERROR(major), minor, "[GSSLibStub_unwrap]"); return jresult; }
--- a/src/share/native/sun/security/jgss/wrapper/NativeUtil.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/native/sun/security/jgss/wrapper/NativeUtil.c Tue Sep 02 11:42:02 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 @@ -28,8 +28,6 @@ #include "jlong.h" #include <jni.h> -extern void throwOutOfMemoryError(JNIEnv *env, const char *message); - const int JAVA_DUPLICATE_TOKEN_CODE = 19; /* DUPLICATE_TOKEN */ const int JAVA_OLD_TOKEN_CODE = 20; /* OLD_TOKEN */ const int JAVA_UNSEQ_TOKEN_CODE = 21; /* UNSEQ_TOKEN */ @@ -82,7 +80,6 @@ jmethodID MID_GSSNameElement_ctor; jmethodID MID_GSSCredElement_ctor; jmethodID MID_NativeGSSContext_ctor; -jmethodID MID_SunNativeProvider_debug; jfieldID FID_GSSLibStub_pMech; jfieldID FID_NativeGSSContext_pContext; jfieldID FID_NativeGSSContext_srcName; @@ -93,7 +90,8 @@ jfieldID FID_NativeGSSContext_flags; jfieldID FID_NativeGSSContext_lifetime; jfieldID FID_NativeGSSContext_actualMech; -char debugBuf[256]; + +int JGSS_DEBUG; JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { @@ -291,13 +289,6 @@ printf("Couldn't find NativeGSSContext(long, GSSLibStub) constructor\n"); return JNI_ERR; } - MID_SunNativeProvider_debug = - (*env)->GetStaticMethodID(env, CLS_SunNativeProvider, "debug", - "(Ljava/lang/String;)V"); - if (MID_SunNativeProvider_debug == NULL) { - printf("Couldn't find SunNativeProvider.debug(String) method\n"); - return JNI_ERR; - } /* Compute and cache the field ID */ cls = (*env)->FindClass(env, "sun/security/jgss/wrapper/GSSLibStub"); if (cls == NULL) { @@ -448,14 +439,28 @@ } return GSS_S_COMPLETE; } + + +/* Throws a Java Exception by name */ +void throwByName(JNIEnv *env, const char *name, const char *msg) { + jclass cls = (*env)->FindClass(env, name); + + if (cls != NULL) { + (*env)->ThrowNew(env, cls, msg); + } +} + +void throwOutOfMemoryError(JNIEnv *env, const char *message) { + throwByName(env, "java/lang/OutOfMemoryError", message); +} + /* * Utility routine for creating a java.lang.String object - * using the specified gss_buffer_t structure. After the, - * String object is created, the specified gss_buffer_t - * structure is released. + * using the specified gss_buffer_t structure. The specified + * gss_buffer_t structure is always released. */ jstring getJavaString(JNIEnv *env, gss_buffer_t bytes) { - jstring result; + jstring result = NULL; OM_uint32 minor; int len; jbyteArray jbytes; @@ -465,9 +470,18 @@ NOTE: do NOT include the trailing NULL */ len = bytes->length; jbytes = (*env)->NewByteArray(env, len); + if (jbytes == NULL) { + goto finish; + } + (*env)->SetByteArrayRegion(env, jbytes, 0, len, (jbyte *) bytes->value); + if ((*env)->ExceptionCheck(env)) { + goto finish; + } + result = (*env)->NewObject(env, CLS_String, MID_String_ctor, jbytes); + finish: (*env)->DeleteLocalRef(env, jbytes); (*ftab->releaseBuffer)(&minor, bytes); return result; @@ -490,14 +504,15 @@ } else { mech = GSS_C_NO_OID; } + /* gss_display_status(...) => GSS_S_BAD_MECH, GSS_S_BAD_STATUS */ + // TBD: check messageContext value and repeat the call if necessary major = (*ftab->displayStatus)(&minor, statusValue, GSS_C_MECH_CODE, mech, - &messageContext, &statusString); - /* release intermediate buffers */ - msg = getJavaString(env, &statusString); - (*ftab->releaseBuffer)(&minor, &statusString); - return msg; + &messageContext, &statusString); + + return getJavaString(env, &statusString); } + /* * Utility routine checking the specified major and minor * status codes. GSSExceptions will be thrown if they are @@ -517,11 +532,9 @@ routineErr = GSS_ROUTINE_ERROR(major); supplementaryInfo = GSS_SUPPLEMENTARY_INFO(major); - sprintf(debugBuf, "%s Status major/minor = %x/%d", methodName, major, minor); - debug(env, debugBuf); - sprintf(debugBuf, "%s Status c/r/s = %d/%d/%d ", methodName, callingErr>>24, - routineErr>>16, supplementaryInfo); - debug(env, debugBuf); + TRACE3("%s Status major/minor = %x/%d", methodName, major, minor); + TRACE3("c/r/s = %d/%d/%d ", callingErr>>24, routineErr>>16, + supplementaryInfo); jmajor = getJavaErrorCode(routineErr | supplementaryInfo); jminor = minor; @@ -529,11 +542,17 @@ jmsg = NULL; if (minor != 0) { jmsg = getMinorMessage(env, jstub, minor); + if ((*env)->ExceptionCheck(env)) { + return; + } } + gssEx = (*env)->NewObject(env, CLS_GSSException, MID_GSSException_ctor3, jmajor, jminor, jmsg); - (*env)->Throw(env, gssEx); + if (gssEx != NULL) { + (*env)->Throw(env, gssEx); + } } else { /* Error in calling the GSS api */ if (callingErr == GSS_S_CALL_INACCESSIBLE_READ) { @@ -545,56 +564,88 @@ } jmajor = 13; /* use GSSException.FAILURE for now */ jmsg = (*env)->NewStringUTF(env, msg); + if (jmsg == NULL) { + return; + } gssEx = (*env)->NewObject(env, CLS_GSSException, MID_GSSException_ctor3, jmajor, jminor, jmsg); - (*env)->Throw(env, gssEx); + if (gssEx != NULL) { + (*env)->Throw(env, gssEx); + } } } + /* * Utility routine for initializing gss_buffer_t structure * with the byte[] in the specified jbyteArray object. - * NOTE: need to call resetGSSBuffer(...) to free up - * the resources. + * NOTE: must call resetGSSBuffer() to free up the resources + * inside the gss_buffer_t structure. */ void initGSSBuffer(JNIEnv *env, jbyteArray jbytes, - gss_buffer_t cbytes) { + gss_buffer_t cbytes) { + + int len; + void* value; + if (jbytes != NULL) { - cbytes->length = (*env)->GetArrayLength(env, jbytes); - cbytes->value = (*env)->GetByteArrayElements(env, jbytes, NULL); + len = (*env)->GetArrayLength(env, jbytes); + value = malloc(len); + if (value == NULL) { + throwOutOfMemoryError(env, NULL); + return; + } else { + (*env)->GetByteArrayRegion(env, jbytes, 0, len, value); + if ((*env)->ExceptionCheck(env)) { + free(value); + return; + } else { + cbytes->length = len; + cbytes->value = value; + } + } } else { cbytes->length = 0; cbytes->value = NULL; } } + /* - * Utility routine for unpinning/releasing the byte[] - * associated with the specified jbyteArray object. + * Utility routine for freeing the bytes malloc'ed + * in initGSSBuffer() method. * NOTE: used in conjunction with initGSSBuffer(...). */ -void resetGSSBuffer(JNIEnv *env, jbyteArray jbytes, - gss_buffer_t cbytes) { - if ((cbytes != NULL) && (cbytes != GSS_C_NO_BUFFER) && - (cbytes->length != 0)) { - (*env)->ReleaseByteArrayElements(env, jbytes, cbytes->value, - JNI_ABORT); +void resetGSSBuffer(gss_buffer_t cbytes) { + if ((cbytes != NULL) && (cbytes != GSS_C_NO_BUFFER)) { + free(cbytes->value); + cbytes->length = 0; + cbytes->value = NULL; } } + /* * Utility routine for creating a jbyteArray object using * the byte[] value in specified gss_buffer_t structure. - * NOTE: the specified gss_buffer_t structure will be - * released in this routine. + * NOTE: the specified gss_buffer_t structure is always + * released. */ jbyteArray getJavaBuffer(JNIEnv *env, gss_buffer_t cbytes) { - jbyteArray result; + jbyteArray result = NULL; OM_uint32 minor; // don't care, just so it compiles - if ((cbytes != NULL) && (cbytes != GSS_C_NO_BUFFER) && - (cbytes->length != 0)) { - result = (*env)->NewByteArray(env, cbytes->length); - (*env)->SetByteArrayRegion(env, result, 0, cbytes->length, - cbytes->value); + if (cbytes != NULL) { + if ((cbytes != GSS_C_NO_BUFFER) && (cbytes->length != 0)) { + result = (*env)->NewByteArray(env, cbytes->length); + if (result == NULL) { + goto finish; + } + (*env)->SetByteArrayRegion(env, result, 0, cbytes->length, + cbytes->value); + if ((*env)->ExceptionCheck(env)) { + result = NULL; + } + } + finish: (*ftab->releaseBuffer)(&minor, cbytes); return result; } @@ -604,8 +655,7 @@ /* * Utility routine for creating a non-mech gss_OID using * the specified org.ietf.jgss.Oid object. - * NOTE: need to call deleteGSSOID(...) afterwards to - * release the created gss_OID structure. + * NOTE: must call deleteGSSOID(...) to free up the gss_OID. */ gss_OID newGSSOID(JNIEnv *env, jobject jOid) { jbyteArray jbytes; @@ -614,8 +664,7 @@ if (jOid != NULL) { jbytes = (*env)->CallObjectMethod(env, jOid, MID_Oid_getDER); if ((*env)->ExceptionCheck(env)) { - gssEx = (*env)->ExceptionOccurred(env); - (*env)->Throw(env, gssEx); + return GSS_C_NO_OID; } cOid = malloc(sizeof(struct gss_OID_desc_struct)); if (cOid == NULL) { @@ -626,17 +675,24 @@ cOid->elements = malloc(cOid->length); if (cOid->elements == NULL) { throwOutOfMemoryError(env,NULL); - free(cOid); - return GSS_C_NO_OID; + goto cleanup; } (*env)->GetByteArrayRegion(env, jbytes, 2, cOid->length, cOid->elements); - (*env)->DeleteLocalRef(env, jbytes); + if ((*env)->ExceptionCheck(env)) { + goto cleanup; + } return cOid; } else { return GSS_C_NO_OID; } + cleanup: + (*env)->DeleteLocalRef(env, jbytes); + free(cOid->elements); + free(cOid); + return GSS_C_NO_OID; } + /* * Utility routine for releasing the specified gss_OID * structure. @@ -648,6 +704,7 @@ free(oid); } } + /* * Utility routine for creating a org.ietf.jgss.Oid * object using the specified gss_OID structure. @@ -656,7 +713,7 @@ int cLen; char oidHdr[2]; jbyteArray jbytes; - jobject result; + jobject result = NULL; if ((cOid == NULL) || (cOid == GSS_C_NO_OID)) { return NULL; @@ -665,12 +722,20 @@ oidHdr[0] = 6; oidHdr[1] = cLen; jbytes = (*env)->NewByteArray(env, cLen+2); + if (jbytes == NULL) { + return NULL; + } (*env)->SetByteArrayRegion(env, jbytes, 0, 2, (jbyte *) oidHdr); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } (*env)->SetByteArrayRegion(env, jbytes, 2, cLen, (jbyte *) cOid->elements); - + if ((*env)->ExceptionCheck(env)) { + return NULL; + } result = (*env)->NewObject(env, CLS_Oid, MID_Oid_ctor1, jbytes); if ((*env)->ExceptionCheck(env)) { - (*env)->Throw(env, (*env)->ExceptionOccurred(env)); + return NULL; } (*env)->DeleteLocalRef(env, jbytes); return result; @@ -681,7 +746,7 @@ * NOTE: need to call deleteGSSOIDSet(...) afterwards * to release the created gss_OID_set structure. */ -gss_OID_set newGSSOIDSet(JNIEnv *env, gss_OID oid) { +gss_OID_set newGSSOIDSet(gss_OID oid) { gss_OID_set oidSet; OM_uint32 minor; // don't care; just so it compiles @@ -722,26 +787,26 @@ if (cOidSet != NULL && cOidSet != GSS_C_NO_OID_SET) { numOfOids = cOidSet->count; jOidSet = (*env)->NewObjectArray(env, numOfOids, CLS_Oid, NULL); - if (jOidSet != NULL) { - for (i = 0; i < numOfOids; i++) { - jOid = getJavaOID(env, &(cOidSet->elements[i])); - (*env)->SetObjectArrayElement(env, jOidSet, i, jOid); - (*env)->DeleteLocalRef(env, jOid); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + for (i = 0; i < numOfOids; i++) { + jOid = getJavaOID(env, &(cOidSet->elements[i])); + if ((*env)->ExceptionCheck(env)) { + return NULL; } + (*env)->SetObjectArrayElement(env, jOidSet, i, jOid); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + (*env)->DeleteLocalRef(env, jOid); } return jOidSet; } return NULL; } -void debug(JNIEnv *env, char *msg) { - jstring jmsg = (*env)->NewStringUTF(env, msg); - (*env)->CallStaticVoidMethod(env, CLS_SunNativeProvider, - MID_SunNativeProvider_debug, jmsg); - (*env)->DeleteLocalRef(env, jmsg); -} - -int sameMech(JNIEnv *env, gss_OID mech, gss_OID mech2) { +int sameMech(gss_OID mech, gss_OID mech2) { int result = JNI_FALSE; // default to not equal if (mech->length == mech2->length) {
--- a/src/share/native/sun/security/jgss/wrapper/NativeUtil.h Thu Aug 28 14:04:38 2014 -0700 +++ b/src/share/native/sun/security/jgss/wrapper/NativeUtil.h Tue Sep 02 11:42:02 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 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 @@ -37,12 +37,13 @@ extern OM_uint32 getGSSTime(jint); extern void checkStatus(JNIEnv *, jobject, OM_uint32, OM_uint32, char*); extern jint checkTime(OM_uint32); + extern void throwOutOfMemoryError(JNIEnv *, const char*); extern void initGSSBuffer(JNIEnv *, jbyteArray, gss_buffer_t); - extern void resetGSSBuffer(JNIEnv *, jbyteArray, gss_buffer_t); + extern void resetGSSBuffer(gss_buffer_t); extern gss_OID newGSSOID(JNIEnv *, jobject); extern void deleteGSSOID(gss_OID); - extern gss_OID_set newGSSOIDSet(JNIEnv *, gss_OID); + extern gss_OID_set newGSSOIDSet(gss_OID); extern void deleteGSSOIDSet(gss_OID_set); extern jbyteArray getJavaBuffer(JNIEnv *, gss_buffer_t); @@ -51,13 +52,12 @@ extern jobjectArray getJavaOIDArray(JNIEnv *, gss_OID_set); extern jstring getMinorMessage(JNIEnv *, jobject, OM_uint32); - extern void debug(JNIEnv *, char *); - extern int sameMech(JNIEnv *, gss_OID, gss_OID); + extern int sameMech(gss_OID, gss_OID); JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *, void *); JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *, void *); - extern char debugBuf[]; + extern int JGSS_DEBUG; extern jclass CLS_Object; extern jclass CLS_GSSNameElement; @@ -85,6 +85,12 @@ extern jfieldID FID_NativeGSSContext_flags; extern jfieldID FID_NativeGSSContext_lifetime; extern jfieldID FID_NativeGSSContext_actualMech; + #define TRACE0(s) { if (JGSS_DEBUG) { puts(s); fflush(stdout); }} + #define TRACE1(s, p1) { if (JGSS_DEBUG) { printf(s"\n", p1); fflush(stdout); }} + #define TRACE2(s, p1, p2) { if (JGSS_DEBUG) { printf(s"\n", p1, p2); fflush(stdout); }} + #define TRACE3(s, p1, p2, p3) { if (JGSS_DEBUG) { printf(s"\n", p1, p2, p3); fflush(stdout); }} + + #ifdef __cplusplus } #endif
--- a/src/solaris/native/java/io/FileOutputStream_md.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/solaris/native/java/io/FileOutputStream_md.c Tue Sep 02 11:42:02 2014 -0700 @@ -53,8 +53,8 @@ */ JNIEXPORT void JNICALL -Java_java_io_FileOutputStream_open(JNIEnv *env, jobject this, - jstring path, jboolean append) { +Java_java_io_FileOutputStream_open0(JNIEnv *env, jobject this, + jstring path, jboolean append) { fileOpen(env, this, path, fos_fd, O_WRONLY | O_CREAT | (append ? O_APPEND : O_TRUNC)); }
--- a/src/solaris/native/java/net/net_util_md.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/solaris/native/java/net/net_util_md.c Tue Sep 02 11:42:02 2014 -0700 @@ -1310,7 +1310,7 @@ * or sending UDP packet. * 2. IPv6 on Linux: By default Linux ignores flowinfo * field so enable IPV6_FLOWINFO_SEND so that flowinfo - * will be examined. + * will be examined. We also set the IPv4 TOS option in this case. * 3. IPv4: set socket option based on ToS and Precedence * fields (otherwise get invalid argument) */ @@ -1326,8 +1326,10 @@ #if defined(AF_INET6) && defined(__linux__) if (ipv6_available()) { int optval = 1; - return setsockopt(fd, IPPROTO_IPV6, IPV6_FLOWINFO_SEND, - (void *)&optval, sizeof(optval)); + if (setsockopt(fd, IPPROTO_IPV6, IPV6_FLOWINFO_SEND, + (void *)&optval, sizeof(optval)) < 0) { + return -1; + } } #endif
--- a/src/solaris/native/sun/awt/X11Color.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/solaris/native/sun/awt/X11Color.c Tue Sep 02 11:42:02 2014 -0700 @@ -1377,7 +1377,7 @@ /* Unlock now to initialize the SystemColor class */ if (lock) { - AWT_UNLOCK (); + AWT_UNLOCK_CHECK_EXCEPTION(env); } sysColors = (*env)->FindClass (env, "java/awt/SystemColor"); CHECK_NULL(sysColors);
--- a/src/solaris/native/sun/awt/awt.h Thu Aug 28 14:04:38 2014 -0700 +++ b/src/solaris/native/sun/awt/awt.h Tue Sep 02 11:42:02 2014 -0700 @@ -75,6 +75,12 @@ AWT_NOFLUSH_UNLOCK(); \ } while (0) +#define AWT_UNLOCK_CHECK_EXCEPTION(env) \ + do { \ + AWT_UNLOCK(); \ + JNU_CHECK_EXCEPTION(env); \ + } while (0) + #define AWT_LOCK_IMPL() \ (*env)->CallStaticVoidMethod(env, tkClass, awtLockMID)
--- a/src/solaris/native/sun/awt/awt_GraphicsEnv.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/solaris/native/sun/awt/awt_GraphicsEnv.c Tue Sep 02 11:42:02 2014 -0700 @@ -1348,7 +1348,9 @@ } /* Make Color Model object for this GraphicsConfiguration */ - colorModel = awtJNI_GetColorModel (env, adata); + colorModel = (*env)->ExceptionCheck(env) + ? NULL : awtJNI_GetColorModel (env, adata); + AWT_UNLOCK (); return colorModel; @@ -2052,7 +2054,7 @@ AWT_FLUSH_UNLOCK(); - if (!success) { + if (!success && !(*env)->ExceptionCheck(env)) { JNU_ThrowInternalError(env, "Could not set display mode"); } #endif /* !HEADLESS */
--- a/src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.c Tue Sep 02 11:42:02 2014 -0700 @@ -246,8 +246,14 @@ } str = (*env)->NewStringUTF(env, entry); - if (str && !(*env)->ExceptionCheck(env)) { + if((*env)->ExceptionCheck(env)){ + break; + } + if (str) { (*env)->SetObjectArrayElement(env, array, i, str); + if((*env)->ExceptionCheck(env)){ + break; + } } }
--- a/src/solaris/native/sun/nio/ch/Net.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/solaris/native/sun/nio/ch/Net.c Tue Sep 02 11:42:02 2014 -0700 @@ -478,7 +478,8 @@ JNIEXPORT void JNICALL Java_sun_nio_ch_Net_setIntOption0(JNIEnv *env, jclass clazz, jobject fdo, - jboolean mayNeedConversion, jint level, jint opt, jint arg) + jboolean mayNeedConversion, jint level, + jint opt, jint arg, jboolean isIPv6) { int result; struct linger linger; @@ -521,6 +522,12 @@ JNU_JAVANETPKG "SocketException", "sun.nio.ch.Net.setIntOption"); } +#ifdef __linux__ + if (level == IPPROTO_IPV6 && opt == IPV6_TCLASS && isIPv6) { + // set the V4 option also + setsockopt(fdval(env, fdo), IPPROTO_IP, IP_TOS, parg, arglen); + } +#endif } JNIEXPORT jint JNICALL
--- a/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/solaris/native/sun/nio/fs/UnixNativeDispatcher.c Tue Sep 02 11:42:02 2014 -0700 @@ -315,7 +315,7 @@ int res = -1; RESTARTABLE(dup((int)fd), res); - if (fd == -1) { + if (res == -1) { throwUnixException(env, errno); } return (jint)res; @@ -343,13 +343,14 @@ JNIEXPORT void JNICALL Java_sun_nio_fs_UnixNativeDispatcher_fclose(JNIEnv* env, jclass this, jlong stream) { - int res; FILE* fp = jlong_to_ptr(stream); - do { - res = fclose(fp); - } while (res == EOF && errno == EINTR); - if (res == EOF) { + /* NOTE: fclose() wrapper is only used with read-only streams. + * If it ever is used with write streams, it might be better to add + * RESTARTABLE(fflush(fp)) before closing, to make sure the stream + * is completely written even if fclose() failed. + */ + if (fclose(fp) == EOF && errno != EINTR) { throwUnixException(env, errno); } } @@ -657,11 +658,9 @@ JNIEXPORT void JNICALL Java_sun_nio_fs_UnixNativeDispatcher_closedir(JNIEnv* env, jclass this, jlong dir) { - int err; DIR* dirp = jlong_to_ptr(dir); - RESTARTABLE(closedir(dirp), err); - if (errno == -1) { + if (closedir(dirp) == -1 && errno != EINTR) { throwUnixException(env, errno); } }
--- a/src/windows/native/java/io/FileOutputStream_md.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/windows/native/java/io/FileOutputStream_md.c Tue Sep 02 11:42:02 2014 -0700 @@ -54,8 +54,8 @@ */ JNIEXPORT void JNICALL -Java_java_io_FileOutputStream_open(JNIEnv *env, jobject this, - jstring path, jboolean append) { +Java_java_io_FileOutputStream_open0(JNIEnv *env, jobject this, + jstring path, jboolean append) { fileOpen(env, this, path, fos_fd, O_WRONLY | O_CREAT | (append ? O_APPEND : O_TRUNC)); }
--- a/src/windows/native/java/net/net_util_md.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/windows/native/java/net/net_util_md.c Tue Sep 02 11:42:02 2014 -0700 @@ -443,6 +443,13 @@ { int rv; + if (level == IPPROTO_IPV6 && optname == IPV6_TCLASS) { + int *intopt = (int *)optval; + *intopt = 0; + *optlen = sizeof(*intopt); + return 0; + } + rv = getsockopt(s, level, optname, optval, optlen);
--- a/src/windows/native/sun/nio/ch/Net.c Thu Aug 28 14:04:38 2014 -0700 +++ b/src/windows/native/sun/nio/ch/Net.c Tue Sep 02 11:42:02 2014 -0700 @@ -295,9 +295,9 @@ /** * HACK: IP_TOS is deprecated on Windows and querying the option * returns a protocol error. NET_GetSockOpt handles this and uses - * a fallback mechanism. + * a fallback mechanism. Same applies to IPV6_TCLASS */ - if (level == IPPROTO_IP && opt == IP_TOS) { + if ((level == IPPROTO_IP && opt == IP_TOS) || (level == IPPROTO_IPV6 && opt == IPV6_TCLASS)) { mayNeedConversion = JNI_TRUE; } @@ -319,7 +319,7 @@ JNIEXPORT void JNICALL Java_sun_nio_ch_Net_setIntOption0(JNIEnv *env, jclass clazz, jobject fdo, - jboolean mayNeedConversion, jint level, jint opt, jint arg) + jboolean mayNeedConversion, jint level, jint opt, jint arg, jboolean ipv6) { struct linger linger; char *parg; @@ -340,6 +340,11 @@ arglen = sizeof(arg); } + if (level == IPPROTO_IPV6 && opt == IPV6_TCLASS) { + /* No op */ + return; + } + if (mayNeedConversion) { n = NET_SetSockOpt(fdval(env, fdo), level, opt, parg, arglen); } else {
--- a/src/windows/native/sun/windows/WPrinterJob.cpp Thu Aug 28 14:04:38 2014 -0700 +++ b/src/windows/native/sun/windows/WPrinterJob.cpp Tue Sep 02 11:42:02 2014 -0700 @@ -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 @@ -995,14 +995,7 @@ if (type == GETJOBCOUNT) { ret = pPrinterInfo->cJobs; } else if (type == ACCEPTJOB) { - if (pPrinterInfo->Status & - (PRINTER_STATUS_ERROR | - PRINTER_STATUS_NOT_AVAILABLE | - PRINTER_STATUS_NO_TONER | - PRINTER_STATUS_OUT_OF_MEMORY | - PRINTER_STATUS_OFFLINE | - PRINTER_STATUS_USER_INTERVENTION | - PRINTER_STATUS_DOOR_OPEN)) { + if (pPrinterInfo->Status & PRINTER_STATUS_PENDING_DELETION) { ret = 0; } else {
--- a/src/windows/native/sun/windows/awt_InputMethod.cpp Thu Aug 28 14:04:38 2014 -0700 +++ b/src/windows/native/sun/windows/awt_InputMethod.cpp Tue Sep 02 11:42:02 2014 -0700 @@ -482,6 +482,7 @@ for (current = 0; current < destIndex; current++) { if (strcmp(javaLocaleNames[current], srcLocaleName) == 0) { // duplicated. ignore this HKL + free((void *)srcLocaleName); break; } }
--- a/src/windows/native/sun/windows/awt_Win32GraphicsDevice.cpp Thu Aug 28 14:04:38 2014 -0700 +++ b/src/windows/native/sun/windows/awt_Win32GraphicsDevice.cpp Tue Sep 02 11:42:02 2014 -0700 @@ -835,13 +835,17 @@ TRY; /* class ids */ - AwtWin32GraphicsDevice::indexCMClass = - (jclass)env->NewGlobalRef(env->FindClass("java/awt/image/IndexColorModel")); + jclass iCMClass = env->FindClass("java/awt/image/IndexColorModel"); + CHECK_NULL(iCMClass); + AwtWin32GraphicsDevice::indexCMClass = (jclass) env->NewGlobalRef(iCMClass); + env->DeleteLocalRef(iCMClass); DASSERT(AwtWin32GraphicsDevice::indexCMClass); CHECK_NULL(AwtWin32GraphicsDevice::indexCMClass); - AwtWin32GraphicsDevice::wToolkitClass = - (jclass)env->NewGlobalRef(env->FindClass("sun/awt/windows/WToolkit")); + jclass wTClass = env->FindClass("sun/awt/windows/WToolkit"); + CHECK_NULL(wTClass); + AwtWin32GraphicsDevice::wToolkitClass = (jclass)env->NewGlobalRef(wTClass); + env->DeleteLocalRef(wTClass); DASSERT(AwtWin32GraphicsDevice::wToolkitClass); CHECK_NULL(AwtWin32GraphicsDevice::wToolkitClass);
--- a/test/ProblemList.txt Thu Aug 28 14:04:38 2014 -0700 +++ b/test/ProblemList.txt Tue Sep 02 11:42:02 2014 -0700 @@ -251,9 +251,6 @@ # jdk_tools -# 8028474 -sun/jvmstat/monitor/MonitoredVm/MonitorVmStartTerminate.sh generic-all - # Tests take too long, on sparcs see 7143279 tools/pack200/CommandLineTests.java solaris-all, macosx-all tools/pack200/Pack200Test.java solaris-all, macosx-all
--- a/test/TEST.groups Thu Aug 28 14:04:38 2014 -0700 +++ b/test/TEST.groups Tue Sep 02 11:42:02 2014 -0700 @@ -314,6 +314,7 @@ java/io/Serializable/serialver \ java/lang/invoke/lambda/LambdaAccessControlDoPrivilegedTest.java \ java/lang/invoke/lambda/LambdaAccessControlTest.java \ + java/lang/invoke/lambda/LambdaAsm.java \ java/lang/System/MacEncoding/TestFileEncoding.java \ java/net/URLClassLoader/closetest/GetResourceAsStream.java \ java/util/Collections/EmptyIterator.java \ @@ -370,6 +371,11 @@ java/text/Bidi/Bug7051769.java \ javax/crypto/Cipher/CipherStreamClose.java \ javax/management/monitor/AttributeArbitraryDataTypeTest.java \ + javax/management/mxbean/AmbiguousConstructorTest.java \ + javax/management/mxbean/ExceptionDiagnosisTest.java \ + javax/management/mxbean/LeakTest.java \ + javax/management/mxbean/MXBeanTest.java \ + javax/management/mxbean/PropertyNamesTest.java \ jdk/lambda/vm/InterfaceAccessFlagsTest.java \ sun/misc/URLClassPath/ClassnameCharTest.java @@ -465,6 +471,7 @@ sun/security/acl \ sun/security/jgss \ sun/security/krb5 \ + java/lang/annotation/AnnotationType/AnnotationTypeDeadlockTest.java \ java/lang/System/MacEncoding/TestFileEncoding.java \ java/nio/channels/AsynchronousSocketChannel/Leaky.java \ java/security/PermissionCollection/Concurrent.java \ @@ -472,6 +479,8 @@ java/security/cert/GetInstance.java \ java/util/logging/DrainFindDeadlockTest.java \ java/util/logging/LoggingMXBeanTest.java \ + java/util/logging/TestLogConfigurationDeadLock.java \ + java/util/logging/TestLoggerBundleSync.java \ sun/net/www/http/KeepAliveCache/B5045306.java \ sun/security/provider/PolicyFile/Alias.java \ sun/security/provider/PolicyFile/Comparator.java \ @@ -523,6 +532,7 @@ java/lang/PrimitiveSumMinMaxTest.java \ java/lang/String/StringJoinTest.java \ java/lang/Thread/StopThrowable.java \ + java/net/Authenticator/B4769350.java \ java/net/Authenticator/Deadlock.java \ java/net/CookieHandler/LocalHostCookie.java \ java/net/CookieHandler/CookieManagerTest.java \ @@ -573,7 +583,6 @@ java/util/zip/ZipFile/StreamZipEntriesTest.java \ java/util/zip/ZipFile/DeleteTempJar.java \ javax/crypto/Cipher/CipherStreamClose.java \ - sun/misc/URLClassPath/ClassnameCharTest.java \ sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/HttpsCreateSockTest.java \ sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/HttpsSocketFacTest.java
--- a/test/java/lang/ProcessBuilder/InheritIO/InheritIO.sh Thu Aug 28 14:04:38 2014 -0700 +++ b/test/java/lang/ProcessBuilder/InheritIO/InheritIO.sh Tue Sep 02 11:42:02 2014 -0700 @@ -36,9 +36,12 @@ exit 1 fi +if [ "x${COMPILEJAVA}" = "x" ]; then + COMPILEJAVA="${TESTJAVA}" +fi JAVA="${TESTJAVA}/bin/java" -JAVAC="${TESTJAVA}/bin/javac" +JAVAC="${COMPILEJAVA}/bin/javac" cp -f ${TESTSRC}/InheritIO.java .
--- a/test/java/lang/annotation/typeAnnotations/ConstructorReceiverTest.java Thu Aug 28 14:04:38 2014 -0700 +++ b/test/java/lang/annotation/typeAnnotations/ConstructorReceiverTest.java Tue Sep 02 11:42:02 2014 -0700 @@ -23,7 +23,7 @@ /* * @test - * @bug 8023651 + * @bug 8023651 8044629 * @summary Test that the receiver annotations and the return annotations of * constructors behave correctly. * @run testng ConstructorReceiverTest @@ -38,11 +38,16 @@ import static org.testng.Assert.*; public class ConstructorReceiverTest { + public static final Integer EMPTY_ANNOTATED_TYPE = Integer.valueOf(-1); + // Format is { // { Class to get ctor for, // ctor param class, // value of anno of return type, - // value of anno for receiver or null if there should be no receiver anno + // value of anno for receiver, + // or null if there should be no receiver, + // or EMPTY_ANNOTATED_TYPE of there should be a receiver but + // no annotation // }, // ... // } @@ -51,13 +56,15 @@ { ConstructorReceiverTest.Middle.class, ConstructorReceiverTest.class, Integer.valueOf(10), Integer.valueOf(15) }, { ConstructorReceiverTest.Middle.Inner.class, ConstructorReceiverTest.Middle.class, Integer.valueOf(100), Integer.valueOf(150) }, { ConstructorReceiverTest.Middle.Inner.Innermost.class, ConstructorReceiverTest.Middle.Inner.class, Integer.valueOf(1000), Integer.valueOf(1500) }, - { ConstructorReceiverTest.Middle.InnerNoReceiver.class, ConstructorReceiverTest.Middle.class, Integer.valueOf(300), null }, + { ConstructorReceiverTest.Middle.InnerNoReceiver.class, ConstructorReceiverTest.Middle.class, Integer.valueOf(300), EMPTY_ANNOTATED_TYPE }, { ConstructorReceiverTest.Nested.class, null, Integer.valueOf(20), null }, { ConstructorReceiverTest.Nested.NestedMiddle.class, ConstructorReceiverTest.Nested.class, Integer.valueOf(200), Integer.valueOf(250)}, { ConstructorReceiverTest.Nested.NestedMiddle.NestedInner.class, ConstructorReceiverTest.Nested.NestedMiddle.class, Integer.valueOf(2000), Integer.valueOf(2500)}, - { ConstructorReceiverTest.Nested.NestedMiddle.NestedInnerNoReceiver.class, ConstructorReceiverTest.Nested.NestedMiddle.class, Integer.valueOf(4000), null}, + { ConstructorReceiverTest.Nested.NestedMiddle.NestedInnerNoReceiver.class, ConstructorReceiverTest.Nested.NestedMiddle.class, Integer.valueOf(4000), EMPTY_ANNOTATED_TYPE}, + { ConstructorReceiverTest.Nested.NestedMiddle.SecondNestedInnerNoReceiver.class, ConstructorReceiverTest.Nested.NestedMiddle.class, Integer.valueOf(5000), EMPTY_ANNOTATED_TYPE}, }; + @DataProvider public Object[][] data() { return TESTS; } @@ -71,14 +78,27 @@ c = toTest.getDeclaredConstructor(ctorParamType); AnnotatedType annotatedReceiverType = c.getAnnotatedReceiverType(); - Annotation[] receiverAnnotations = annotatedReceiverType.getAnnotations(); + // Some Constructors doesn't conceptually have a receiver, they should return null if (receiverVal == null) { - assertEquals(receiverAnnotations.length, 0, Arrays.asList(receiverAnnotations).toString() + - " should be empty. Looking at 'length': "); + assertNull(annotatedReceiverType, "getAnnotatedReciverType should return null for Constructor: " + c); return; } + // check that getType() matches the receiver + assertEquals(annotatedReceiverType.getType(), + ctorParamType, + "getType() doesn't match receiver type: " + ctorParamType); + + Annotation[] receiverAnnotations = annotatedReceiverType.getAnnotations(); + + // Some Constructors have no annotations on but in theory can have a receiver + if (receiverVal.equals(EMPTY_ANNOTATED_TYPE)) { + assertEquals(receiverAnnotations.length, 0, "expecting an empty annotated type for: " + c); + return; + } + + // The rest should have annotations assertEquals(receiverAnnotations.length, 1, "expecting a 1 element array. Looking at 'length': "); assertEquals(((Annot)receiverAnnotations[0]).value(), receiverVal.intValue(), " wrong annotation found. Found " + receiverAnnotations[0] + @@ -136,6 +156,10 @@ class NestedInnerNoReceiver { @Annot(4000) public NestedInnerNoReceiver() {} } + + class SecondNestedInnerNoReceiver { + @Annot(5000) public SecondNestedInnerNoReceiver(NestedMiddle NestedMiddle.this) {} + } } }
--- a/test/java/lang/annotation/typeAnnotations/GetAnnotatedReceiverType.java Thu Aug 28 14:04:38 2014 -0700 +++ b/test/java/lang/annotation/typeAnnotations/GetAnnotatedReceiverType.java Tue Sep 02 11:42:02 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,10 +23,11 @@ /* * @test - * @bug 8024915 + * @bug 8024915 8044629 */ import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Executable; import java.util.Arrays; public class GetAnnotatedReceiverType { @@ -42,41 +43,115 @@ public Inner1(GetAnnotatedReceiverType GetAnnotatedReceiverType.this) {} } + public static class Nested { + public Nested() {} + + public class NestedInner { + public NestedInner() { } + + public Class<?> getLocalClass () { + class NestedInnerLocal { public NestedInnerLocal() {} } + return NestedInnerLocal.class; + } + + public Class<?> getAnonymousClass() { + return new Object() {}.getClass(); + } + } + } + + public class Inner2 { + public Inner2() { } + + public class Inner3 { + public Inner3() { } + + public Class<?> getLocalClass () { + class InnerLocal { public InnerLocal() {} } + return InnerLocal.class; + } + + public Class<?> getAnonymousClass() { + return new Object() {}.getClass(); + } + } + + public Class<?> getLocalClass () { + class InnerLocal { public InnerLocal() {} } + return InnerLocal.class; + } + + public Class<?> getAnonymousClass() { + return new Object() {}.getClass(); + } + } + private static int failures = 0; private static int tests = 0; public static void main(String[] args) throws NoSuchMethodException { - checkEmptyAT(GetAnnotatedReceiverType.class.getMethod("method").getAnnotatedReceiverType(), + checkEmptyAT(GetAnnotatedReceiverType.class.getMethod("method"), "getAnnotatedReceiverType for \"method\" should return an empty AnnotatedType"); - checkEmptyAT(Inner0.class.getConstructor(GetAnnotatedReceiverType.class).getAnnotatedReceiverType(), + checkEmptyAT(Inner0.class.getConstructor(GetAnnotatedReceiverType.class), "getAnnotatedReceiverType for a ctor without a \"this\" should return an empty AnnotatedType"); - checkEmptyAT(GetAnnotatedReceiverType.class.getMethod("method0").getAnnotatedReceiverType(), + checkEmptyAT(GetAnnotatedReceiverType.class.getMethod("method0"), "getAnnotatedReceiverType for \"method0\" should return an empty AnnotatedType"); - checkEmptyAT(Inner1.class.getConstructor(GetAnnotatedReceiverType.class).getAnnotatedReceiverType(), + checkEmptyAT(Inner1.class.getConstructor(GetAnnotatedReceiverType.class), "getAnnotatedReceiverType for a ctor with a \"this\" should return an empty AnnotatedType"); - checkNull(GetAnnotatedReceiverType.class.getMethod("method4").getAnnotatedReceiverType(), + checkNull(GetAnnotatedReceiverType.class.getMethod("method4"), "getAnnotatedReceiverType() on a static method should return null"); + // More nested, inner, local and anonymous classes + Nested nested = new Nested(); + Nested.NestedInner instance = nested.new NestedInner(); + checkNull(nested.getClass().getConstructors()[0], + "getAnnotatedReceiverType() on a constructor for a static class should return null"); + checkEmptyAT(instance.getClass().getConstructors()[0], + "getAnnotatedReceiverType for a ctor without a \"this\" should return an empty AnnotatedType"); + checkNull(instance.getLocalClass().getConstructors()[0], + "getAnnotatedReceiverType() on a constructor for a local class should return null"); + checkNull(instance.getAnonymousClass().getDeclaredConstructors()[0], + "getAnnotatedReceiverType() on a constructor for an anonymous class should return null"); + + GetAnnotatedReceiverType outer = new GetAnnotatedReceiverType(); + Inner2 instance2 = outer.new Inner2(); + checkEmptyAT(instance2.getClass().getConstructors()[0], + "getAnnotatedReceiverType for a ctor without a \"this\" should return an empty AnnotatedType"); + checkNull(instance2.getLocalClass().getConstructors()[0], + "getAnnotatedReceiverType() on a constructor for a local class should return null"); + checkNull(instance2.getAnonymousClass().getDeclaredConstructors()[0], + "getAnnotatedReceiverType() on a constructor for an anonymous class should return null"); + + Inner2.Inner3 instance3 = instance2.new Inner3(); + checkEmptyAT(instance3.getClass().getConstructors()[0], + "getAnnotatedReceiverType for a ctor without a \"this\" should return an empty AnnotatedType"); + checkNull(instance3.getLocalClass().getConstructors()[0], + "getAnnotatedReceiverType() on a constructor for a local class should return null"); + checkNull(instance3.getAnonymousClass().getDeclaredConstructors()[0], + "getAnnotatedReceiverType() on a constructor for an anonymous class should return null"); + if (failures != 0) throw new RuntimeException("Test failed, see log for details"); - else if (tests != 5) + else if (tests != 15) throw new RuntimeException("Not all cases ran, failing"); } - private static void checkNull(Object o, String msg) { - if (o != null) { + private static void checkNull(Executable e, String msg) { + AnnotatedType a = e.getAnnotatedReceiverType(); + if (a != null) { failures++; - System.err.println(msg); + System.err.println(msg + ": " + e); } tests++; } - private static void checkEmptyAT(AnnotatedType a, String msg) { + private static void checkEmptyAT(Executable e, String msg) { + AnnotatedType a = e.getAnnotatedReceiverType(); if (a.getAnnotations().length != 0) { failures++; - System.err.print(msg); + System.err.print(msg + ": " + e); } tests++; }
--- a/test/java/lang/annotation/typeAnnotations/TestExecutableGetAnnotatedType.java Thu Aug 28 14:04:38 2014 -0700 +++ b/test/java/lang/annotation/typeAnnotations/TestExecutableGetAnnotatedType.java Tue Sep 02 11:42:02 2014 -0700 @@ -73,13 +73,11 @@ testParameters(e.getParameters()); } - // should test constructors as well, see JDK-8044629 @Test(dataProvider = "genericMethodData") public void testGenericReceiverType(Executable e) throws Exception { testReceiverType0(e); } - // should test constructors as well, see JDK-8044629 @Test(dataProvider = "methodData") public void testReceiverType(Executable e) throws Exception { testReceiverType0(e);
--- a/test/java/util/logging/TestLoggerBundleSync.java Thu Aug 28 14:04:38 2014 -0700 +++ b/test/java/util/logging/TestLoggerBundleSync.java Tue Sep 02 11:42:02 2014 -0700 @@ -58,6 +58,7 @@ */ public class TestLoggerBundleSync { + static final boolean VERBOSE = false; static volatile Exception thrown = null; static volatile boolean goOn = true; @@ -65,6 +66,7 @@ static final long TIME = 4 * 1000; // 4 sec. static final long STEP = 1 * 1000; // message every 1 sec. static final int LCOUNT = 50; // change bundle 50 times... + static final AtomicLong ignoreLogCount = new AtomicLong(0); static final AtomicLong setRBcount = new AtomicLong(0); static final AtomicLong setRBNameCount = new AtomicLong(0); static final AtomicLong getRBcount = new AtomicLong(0); @@ -150,6 +152,7 @@ long sSetRBNameCount = setRBNameCount.get(); long sCheckCount = checkCount.get(); long sNextLong = nextLong.get(); + long sIgnoreLogCount = ignoreLogCount.get(); List<Thread> threads = new ArrayList<>(); for (Class<? extends ResourceBundle> type : classes) { threads.add(new SetRB(type)); @@ -181,21 +184,58 @@ + " resource bundles set by " + classes.size() + " Thread(s),"); System.out.println("\t " + (setRBNameCount.get() - sSetRBNameCount) + " resource bundle names set by " + classes.size() + " Thread(s),"); + System.out.println("\t " + (ignoreLogCount.get() - sIgnoreLogCount) + + " log messages emitted by other GetRB threads were ignored" + + " to ensure MT test consistency,"); System.out.println("\t ThreadMXBean.findDeadlockedThreads called " + (checkCount.get() -sCheckCount) + " times by 1 Thread."); } final static class GetRB extends Thread { - final static class MyHandler extends Handler { + final class MyHandler extends Handler { volatile ResourceBundle rb; volatile String rbName; volatile int count = 0; @Override public synchronized void publish(LogRecord record) { - count++; - rb = record.getResourceBundle(); - rbName = record.getResourceBundleName(); + Object[] params = record.getParameters(); + // Each GetRB thread has its own handler, but since they + // log into the same logger, each handler may receive + // messages emitted by other threads. + // This means that GetRB#2.handler may receive a message + // emitted by GetRB#1 at a time where the resource bundle + // was still null. + // To avoid falling into this trap, the GetRB thread passes + // 'this' as argument to the messages it logs - which does + // allow us here to ignore messages that where not emitted + // by our own GetRB.this thread... + if (params.length == 1) { + if (params[0] == GetRB.this) { + // The message was emitted by our thread. + count++; + rb = record.getResourceBundle(); + rbName = record.getResourceBundleName(); + } else { + // The message was emitted by another thread: just + // ignore it, as it may have been emitted at a time + // where the resource bundle was still null, and + // processing it may overwrite the 'rb' and 'rbName' + // recorded from the message emitted by our own thread. + if (VERBOSE) { + System.out.println("Ignoring message logged by " + params[0]); + } + ignoreLogCount.incrementAndGet(); + } + } else { + ignoreLogCount.incrementAndGet(); + System.err.println("Unexpected message received"); + } + } + + void reset() { + rbName = null; + rb = null; } @Override @@ -207,6 +247,7 @@ } }; final MyHandler handler = new MyHandler(); + @Override public void run() { try { @@ -234,9 +275,10 @@ + handler.getLevel()); } final int countBefore = handler.count; + handler.reset(); ll.setLevel(Level.FINEST); ll.addHandler(handler); - ll.fine("dummy"); + ll.log(Level.FINE, "dummy {0}", this); ll.removeHandler(handler); final int countAfter = handler.count; if (countBefore == countAfter) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/sun/java2d/OpenGL/DrawHugeImageTest.java Tue Sep 02 11:42:02 2014 -0700 @@ -0,0 +1,108 @@ +/* + * 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 8040617 + * @summary Test verifies that an attempt to get an accelerated copy of + * a huge buffered image does not result in an OOME. + * + * @run main DrawHugeImageTest + */ + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsEnvironment; +import java.awt.image.BufferedImage; +import java.awt.image.VolatileImage; + +public class DrawHugeImageTest { + // we have to render the BI source several times in order + // to get an accelerated copy to be used. + static { + System.setProperty("sun.java2d.accthreshold", "1"); + } + private static final int max_rendering_count = 5; + + private static final Color srcColor = Color.red; + private static final Color dstColor = Color.blue; + + public static void main(String[] args) { + BufferedImage src = createSrc(); + + VolatileImage dst = createDst(); + System.out.println("Dst: " + dst); + boolean status; + int count = max_rendering_count; + + do { + System.out.println("render image: " + (max_rendering_count - count)); + status = render(src, dst); + + } while (status && count-- > 0); + + if (!status || count > 0) { + throw new RuntimeException("Test failed: " + count); + } + } + + private static boolean render(BufferedImage src, VolatileImage dst) { + int cnt = 5; + do { + Graphics2D g = dst.createGraphics(); + g.setColor(dstColor); + g.fillRect(0, 0, dst.getWidth(), dst.getHeight()); + g.drawImage(src, 0, 0, null); + g.dispose(); + } while (dst.contentsLost() && (--cnt > 0)); + + if (cnt == 0) { + System.err.println("Test failed: unable to render to volatile destination"); + return false; + } + + BufferedImage s = dst.getSnapshot(); + + return s.getRGB(1,1) == srcColor.getRGB(); + } + + private static BufferedImage createSrc() { + final int w = 20000; + final int h = 5; + + BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR); + Graphics2D g = img.createGraphics(); + g.setColor(srcColor); + g.fillRect(0, 0, w, h); + g.dispose(); + + return img; + } + + private static VolatileImage createDst() { + GraphicsConfiguration gc = + GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); + + return gc.createCompatibleVolatileImage(200, 200); + } +}
--- a/test/sun/jvmstat/monitor/MonitoredVm/MonitorVmStartTerminate.java Thu Aug 28 14:04:38 2014 -0700 +++ b/test/sun/jvmstat/monitor/MonitoredVm/MonitorVmStartTerminate.java Tue Sep 02 11:42:02 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 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 @@ -21,228 +21,305 @@ * questions. */ -import java.util.concurrent.CountDownLatch; -import java.util.regex.*; -import java.util.*; -import java.net.URISyntaxException; +import java.io.File; import java.io.IOException; -import sun.jvmstat.monitor.*; -import sun.jvmstat.monitor.event.*; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.Semaphore; -public class MonitorVmStartTerminate { +import jdk.testlibrary.OutputBuffer; +import jdk.testlibrary.ProcessTools; +import sun.jvmstat.monitor.MonitorException; +import sun.jvmstat.monitor.MonitoredHost; +import sun.jvmstat.monitor.MonitoredVm; +import sun.jvmstat.monitor.MonitoredVmUtil; +import sun.jvmstat.monitor.VmIdentifier; +import sun.jvmstat.monitor.event.HostEvent; +import sun.jvmstat.monitor.event.HostListener; +import sun.jvmstat.monitor.event.VmStatusChangeEvent; + +/* - private static final int SLEEPERS = 10; - private static final int SLEEPTIME = 5000; // sleep time for a sleeper - private static final int EXECINTERVAL = 3000; // wait time between exec's + Test starts ten Java processes, each with a unique id. + + Each process creates a file named after the id and then it waits for + the test to remove the file, at which the Java process exits. + + The processes are monitored by the test to make sure notifications + are sent when they are started/terminated. + + To avoid Java processes being left behind, in case of an unexpected + failure, shutdown hooks are installed that remove files when the test + exits. If files are not removed, i.e. due to a JVM crash, the Java + processes will exit themselves after 1000 s. - public static void main(String args[]) throws Exception { +*/ - long now = System.currentTimeMillis(); +/* + * @test + * @bug 4990825 + * @summary attach to external but local JVM processes + * @library /lib/testlibrary + * @build jdk.testlibrary.* + * @run main/othervm MonitorVmStartTerminate + */ +public final class MonitorVmStartTerminate { - String sleeperArgs = SLEEPTIME + " " + now; - String sleeperPattern = "Sleeper " + sleeperArgs + " \\d+$"; + private static final int PROCESS_COUNT = 10; + + public static void main(String... args) throws Exception { MonitoredHost host = MonitoredHost.getMonitoredHost("localhost"); - host.setInterval(200); + host.setInterval(1); // 1 ms + + String id = UUID.randomUUID().toString(); - Matcher matcher = Pattern.compile(sleeperPattern).matcher(""); - SleeperListener listener = new SleeperListener(host, matcher, SLEEPERS); - host.addHostListener(listener); - - SleeperStarter ss = new SleeperStarter(SLEEPERS, EXECINTERVAL, - sleeperArgs); - ss.start(); + List<JavaProcess> javaProcesses = new ArrayList<>(); + for (int i = 0; i < PROCESS_COUNT; i++) { + javaProcesses.add(new JavaProcess(id + "_" + i)); + } - System.out.println("Waiting for " - + SLEEPERS + " sleepers to terminate"); - try { - ss.join(); - } catch (InterruptedException e) { - throw new Exception("Timed out waiting for sleepers"); + Listener listener = new Listener(host, javaProcesses); + host.addHostListener(listener); + for (JavaProcess javaProcess : javaProcesses) { + javaProcess.start(); } - listener.waitForSleepersToStart(); - listener.waitForSleepersToTerminate(); + + // Wait for all processes to start before terminating + // them, so pids are not reused within a poll interval. + System.out.println("Waiting for all processes to get started notification"); + listener.started.acquire(PROCESS_COUNT); + + for (JavaProcess javaProcess : javaProcesses) { + javaProcess.terminate(); + } + System.out.println("Waiting for all processes to get terminated notification"); + listener.terminated.acquire(PROCESS_COUNT); + + host.removeHostListener(listener); } - public static class SleeperListener implements HostListener { - - private final List<Integer> targets = new ArrayList<>(); - private final CountDownLatch terminateLatch; - private final CountDownLatch startLatch; + private static final class Listener implements HostListener { + private final Semaphore started = new Semaphore(0); + private final Semaphore terminated = new Semaphore(0); private final MonitoredHost host; - private final Matcher patternMatcher; + private final List<JavaProcess> processes; - public SleeperListener(MonitoredHost host, Matcher matcher, int count) { + public Listener(MonitoredHost host, List<JavaProcess> processes) { this.host = host; - this.patternMatcher = matcher; - this.terminateLatch = new CountDownLatch(count); - this.startLatch = new CountDownLatch(count); + this.processes = processes; + printStatus(); } - public void waitForSleepersToTerminate() throws InterruptedException { - terminateLatch.await(); + @Override + @SuppressWarnings("unchecked") + public void vmStatusChanged(VmStatusChangeEvent event) { + releaseStarted(event.getStarted()); + releaseTerminated(event.getTerminated()); + printStatus(); + } + + private void printStatus() { + System.out.printf("started=%d, terminated=%d\n", + started.availablePermits(), terminated.availablePermits()); + } + + @Override + public void disconnected(HostEvent arg0) { + // ignore } - public void waitForSleepersToStart() throws InterruptedException { - startLatch.await(); + private void releaseStarted(Set<Integer> ids) { + System.out.println("realeaseStarted(" + ids + ")"); + for (Integer id : ids) { + releaseStarted(id); + } } - private void printList(Set<Integer> list, String msg) { - System.out.println(msg + ":"); - for (Integer lvmid : list) { - try { - VmIdentifier vmid = new VmIdentifier("//" + lvmid.intValue()); - MonitoredVm target = host.getMonitoredVm(vmid); + private void releaseStarted(Integer id) { + for (JavaProcess jp : processes) { + if (hasMainArgs(id, jp.getMainArgsIdentifier())) { + // store id for terminated identification + jp.setId(id); + System.out.println("RELEASED (id=" + jp.getId() + ", args=" + jp.getMainArgsIdentifier() + ")"); + started.release(); + return; + } + } + } - StringMonitor cmdMonitor = - (StringMonitor)target.findByName("sun.rt.javaCommand"); - String cmd = cmdMonitor.stringValue(); + private void releaseTerminated(Set<Integer> ids) { + System.out.println("releaseTerminated(" + ids + ")"); + for (Integer id : ids) { + releaseTerminated(id); + } + } - System.out.println("\t" + lvmid.intValue() + ": " - + "\"" + cmd + "\"" + ": "); - } catch (URISyntaxException e) { - System.err.println("Unexpected URISyntaxException: " - + e.getMessage()); - } catch (MonitorException e) { - System.out.println("\t" + lvmid.intValue() - + ": error reading monitoring data: " - + " target possibly terminated?"); + private void releaseTerminated(Integer id) { + for (JavaProcess jp : processes) { + if (id.equals(jp.getId())) { + System.out.println("RELEASED (id=" + jp.getId() + ", args=" + jp.getMainArgsIdentifier() + ")"); + terminated.release(); + return; } } } - - private int addStarted(Set<Integer> started) { - int found = 0; - for (Integer lvmid : started) { - try { - VmIdentifier vmid = new VmIdentifier("//" + lvmid.intValue()); - MonitoredVm target = host.getMonitoredVm(vmid); - - StringMonitor cmdMonitor = - (StringMonitor)target.findByName("sun.rt.javaCommand"); - String cmd = cmdMonitor.stringValue(); - - patternMatcher.reset(cmd); - System.out.print("Started: " + lvmid.intValue() - + ": " + "\"" + cmd + "\"" + ": "); + private boolean hasMainArgs(Integer id, String args) { + try { + VmIdentifier vmid = new VmIdentifier("//" + id.intValue()); + MonitoredVm target = host.getMonitoredVm(vmid); + String monitoredArgs = MonitoredVmUtil.mainArgs(target); + if (monitoredArgs != null && monitoredArgs.contains(args)) { + return true; + } + } catch (URISyntaxException | MonitorException e) { + // ok. process probably not running + } + return false; + } + } - if (patternMatcher.matches()) { - System.out.println("matches pattern - recorded"); - targets.add(lvmid); - found++; - } - else { - System.out.println("does not match pattern - ignored"); - } - } catch (URISyntaxException e) { - System.err.println("Unexpected URISyntaxException: " - + e.getMessage()); - } catch (MonitorException e) { - System.err.println("Unexpected MonitorException: " - + e.getMessage()); - } + public final static class JavaProcess { + + private static final class ShutdownHook extends Thread { + private final JavaProcess javaProcess; + + public ShutdownHook(JavaProcess javaProcess) { + this.javaProcess = javaProcess; } - return found; + + public void run() { + javaProcess.terminate(); + } } - private int removeTerminated(Set<Integer> terminated) { - int found = 0; - for (Integer lvmid : terminated) { - /* - * we don't attempt to attach to the target here as it's - * now dead and has no jvmstat share memory file. Just see - * if the process id is among those that we saved when we - * started the targets (note - duplicated allowed and somewhat - * expected on windows); - */ - System.out.print("Terminated: " + lvmid.intValue() + ": "); - if (targets.contains(lvmid)) { - System.out.println("matches pattern - termination recorded"); - targets.remove(lvmid); - found++; - } - else { - System.out.println("does not match pattern - ignored"); - } + public static void main(String[] args) throws InterruptedException { + try { + Path path = Paths.get(args[0]); + createFile(path); + waitForRemoval(path); + } catch (Throwable t) { + t.printStackTrace(); + System.exit(1); } - return found; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; } - @SuppressWarnings("unchecked") - public void vmStatusChanged(VmStatusChangeEvent ev) { - printList(ev.getActive(), "Active"); - printList(ev.getStarted(), "Started"); - printList(ev.getTerminated(), "Terminated"); + private static void createFile(Path path) throws IOException { + Files.write(path, new byte[0], StandardOpenOption.CREATE); + } - int recentlyStarted = addStarted(ev.getStarted()); - int recentlyTerminated = removeTerminated(ev.getTerminated()); - - for (int i = 0; i < recentlyTerminated; i++) { - terminateLatch.countDown(); - } - for (int i = 0; i < recentlyStarted; i++) { - startLatch.countDown(); + private static void waitForRemoval(Path path) { + String timeoutFactorText = System.getProperty("test.timeout.factor", "1.0"); + double timeoutFactor = Double.parseDouble(timeoutFactorText); + long timeoutNanos = 1000_000_000L*(long)(1000*timeoutFactor); + long start = System.nanoTime(); + while (true) { + long now = System.nanoTime(); + long waited = now - start; + System.out.println("Waiting for " + path + " to be removed, " + waited + " ns"); + if (!Files.exists(path)) { + return; + } + if (waited > timeoutNanos) { + System.out.println("Start: " + start); + System.out.println("Now: " + now); + System.out.println("Process timed out after " + waited + " ns. Abort."); + System.exit(1); + } + takeNap(); } } - public void disconnected(HostEvent ev) { + private static void takeNap() { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // ignore + } } - } - - public static class SleeperStarter extends Thread { - private final JavaProcess[] processes; - private final int execInterval; - private final String args; + private final String mainArgsIdentifier; + private final ShutdownHook shutdownHook; + private volatile Integer id; - public SleeperStarter(int sleepers, int execInterval, String args) { - this.execInterval = execInterval; - this.args = args; - this.processes = new JavaProcess[sleepers]; + public JavaProcess(String mainArgsIdentifier) { + this.mainArgsIdentifier = mainArgsIdentifier; + this.shutdownHook = new ShutdownHook(this); } - private synchronized int active() { - int active = processes.length; - for(JavaProcess jp : processes) { - try { - jp.exitValue(); - active--; - } catch (IllegalThreadStateException e) { - // process hasn't exited yet + /** + * Starts a Java process asynchronously. + * + * The process runs until {@link #stop()} is called. If test exits + * unexpectedly the process will be cleaned up by a shutdown hook. + * + * @throws Exception + */ + public void start() throws Exception { + Runtime.getRuntime().addShutdownHook(shutdownHook); + System.out.println("Starting " + getMainArgsIdentifier()); + + Runnable r = new Runnable() { + @Override + public void run() { + try { + executeJava(); + } catch (Throwable t) { + t.printStackTrace(); + } } - } - return active; + }; + new Thread(r).start(); } - public void run() { - System.out.println("Starting " + processes.length + " sleepers"); - - String[] classpath = { - "-classpath", - System.getProperty("java.class.path") - }; + public void terminate() { + try { + System.out.println("Terminating " + mainArgsIdentifier); + // File must be created before proceeding, + // otherwise Java process may loop forever + // waiting for file to be removed. + Path path = Paths.get(mainArgsIdentifier); + while (!Files.exists(path)) { + takeNap(); + } + Files.delete(path); + } catch (IOException e) { + e.printStackTrace(); + } + Runtime.getRuntime().removeShutdownHook(shutdownHook); + } - for (int i = 0; i < processes.length; i++) { - try { - System.out.println("Starting Sleeper " + i); - synchronized(this) { - processes[i] = new JavaProcess("Sleeper", args + " " + i); - processes[i].addOptions(classpath); - } - processes[i].start(); - Thread.sleep(execInterval); - } catch (InterruptedException ignore) { - } catch (IOException e) { - System.err.println( - "IOException trying to start Sleeper " + i + ": " - + e.getMessage()); - } - } + private void executeJava() throws Exception, IOException { + String className = JavaProcess.class.getName(); + String classPath = System.getProperty("test.classes"); + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-Dtest.timeout.factor=" + System.getProperty("test.timeout.factor", "1.0"), + "-cp", classPath, className, mainArgsIdentifier); + OutputBuffer ob = ProcessTools.getOutput(pb.start()); + System.out.println("Java Process " + getMainArgsIdentifier() + " stderr:" + + ob.getStderr()); + System.err.println("Java Process " + getMainArgsIdentifier() + " stdout:" + + ob.getStdout()); + } - // spin waiting for the processes to terminate - while (active() > 0) ; + public String getMainArgsIdentifier() { + return mainArgsIdentifier; } } } -
--- a/test/sun/jvmstat/monitor/MonitoredVm/MonitorVmStartTerminate.sh Thu Aug 28 14:04:38 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -# -# Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License version 2 only, as -# published by the Free Software Foundation. -# -# 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 4990825 -# @summary attach to external but local JVM processes -# @library ../../testlibrary -# @build Sleeper -# @build JavaProcess -# @build MonitorVmStartTerminate -# @run shell MonitorVmStartTerminate.sh -# - -. ${TESTSRC-.}/../../testlibrary/utils.sh - -setup -verify_os - -JAVA="${TESTJAVA}/bin/java" -CP=${TESTJAVA}${FS}lib${FS}tools.jar${PS}${TESTCLASSES}${PS}${TESTCLASSES}${FS}..${FS}..${FS}testlibrary - -${JAVA} ${TESTVMOPTS} -classpath ${CP} MonitorVmStartTerminate
--- a/test/sun/jvmstat/testlibrary/JavaProcess.java Thu Aug 28 14:04:38 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * 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.io.*; - -public class JavaProcess { - - protected Process process = null; - - private String classname; - private StringBuilder classArgs; - private StringBuilder javaOptions; - - private static String java = System.getProperty("java.home") - + File.separator + "bin" - + File.separator + "java"; - - public JavaProcess(String classname) { - this(classname, "", ""); - } - - public JavaProcess(String classname, String classArgs) { - this(classname, "", classArgs); - } - - public JavaProcess(String classname, String javaOptions, String classArgs) { - this.classname = classname; - this.javaOptions = new StringBuilder(javaOptions); - this.classArgs = new StringBuilder(classArgs); - } - - /** - * add java options to the java command - */ - public void addOptions(String[] opts) { - if (javaOptions != null && javaOptions.length() > 0) { - javaOptions.append(" "); - } - - for (int i = 0; i < opts.length; i++) { - if (i != 0) { - javaOptions.append(" "); - } - javaOptions.append(opts[i]); - } - } - - /** - * add arguments to the class arguments - */ - public void addArguments(String[] args) { - if (classArgs != null && classArgs.length() > 0) { - classArgs.append(" "); - } - - for (int i = 0; i < args.length; i++) { - if (i != 0) { - classArgs.append(" "); - } - classArgs.append(args[i]); - } - } - - /** - * start the java process - */ - public void start() throws IOException { - if (process != null) { - return; - } - - String javaCommand = java + " " + javaOptions + " " - + classname + " " + classArgs; - - System.out.println("exec'ing: " + javaCommand); - - process = Runtime.getRuntime().exec(javaCommand); - } - - /** - * destroy the java process - */ - public void destroy() { - if (process != null) { - process.destroy(); - } - process = null; - } - - public int exitValue() { - if (process != null) { - return process.exitValue(); - } - throw new RuntimeException("exitValue called with process == null"); - } - - public InputStream getErrorStream() { - if (process != null) { - return process.getErrorStream(); - } - throw new RuntimeException( - "getErrorStream() called with process == null"); - } - - public InputStream getInputStream() { - if (process != null) { - return process.getInputStream(); - } - throw new RuntimeException( - "getInputStream() called with process == null"); - } - - public OutputStream getOutputStream() { - if (process != null) { - return process.getOutputStream(); - } - throw new RuntimeException( - "getOutputStream() called with process == null"); - } - - public int waitFor() throws InterruptedException { - if (process != null) { - return process.waitFor(); - } - throw new RuntimeException("waitFor() called with process == null"); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/sun/security/krb5/ccache/DefaultFile.java Tue Sep 02 11:42:02 2014 -0700 @@ -0,0 +1,47 @@ +/* + * 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 8054817 + * @summary File ccache only recognizes Linux and Solaris defaults + */ + +import sun.security.krb5.internal.ccache.FileCredentialsCache; + +public class DefaultFile { + public static void main(String[] args) throws Exception { + // There are 2 cases where default ccache name is not + // /tmp/krb5cc_uid. + if (System.getenv("KRB5CCNAME") != null) { + return; + } + if (System.getProperty("os.name").startsWith("Windows")) { + return; + } + String name = FileCredentialsCache.getDefaultCacheName(); + if (!name.startsWith("/tmp/krb5cc_")) { + throw new Exception("default name is " + name); + } + } +}
--- a/test/sun/security/smartcardio/TestDirect.java Thu Aug 28 14:04:38 2014 -0700 +++ b/test/sun/security/smartcardio/TestDirect.java Tue Sep 02 11:42:02 2014 -0700 @@ -30,6 +30,7 @@ // This test requires special hardware. +import java.util.List; import javax.smartcardio.Card; import javax.smartcardio.CardTerminal; import javax.smartcardio.CardTerminals; @@ -38,8 +39,12 @@ public class TestDirect { public static void main(String[] args) throws Exception { TerminalFactory terminalFactory = TerminalFactory.getDefault(); - CardTerminals cardTerminals = terminalFactory.terminals(); - CardTerminal cardTerminal = cardTerminals.list().get(0); + List<CardTerminal> cardTerminals = terminalFactory.terminals().list(); + System.out.println("Terminals: " + cardTerminals); + if (cardTerminals.isEmpty()) { + throw new Exception("No card terminals available"); + } + CardTerminal cardTerminal = cardTerminals.get(0); Card card = cardTerminal.connect("DIRECT"); card.disconnect(true);
--- a/test/tools/launcher/TestSpecialArgs.java Thu Aug 28 14:04:38 2014 -0700 +++ b/test/tools/launcher/TestSpecialArgs.java Tue Sep 02 11:42:02 2014 -0700 @@ -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 @@ -23,7 +23,7 @@ /* * @test - * @bug 7124089 7131021 + * @bug 7124089 7131021 8042469 * @summary Checks for MacOSX specific flags are accepted or rejected, and * MacOSX platforms specific environment is consistent. * @compile -XDignore.symbol.file TestSpecialArgs.java EnvironmentVariables.java @@ -69,6 +69,137 @@ throw new RuntimeException("Error: argument was accepted ????"); } } + + /* + * test argument : -XX:NativeMemoryTracking=value + * A JVM flag, comsumed by the JVM, but requiring launcher + * to set an environmental variable if and only if value is supplied. + * Test and order: + * 1) execute with valid parameter: -XX:NativeMemoryTracking=MyValue + * a) check for correct env variable name: "NMT_LEVEL_" + pid + * b) check that "MyValue" was found in local env. + * 2) execute with invalid parameter: -XX:NativeMemoryTracking= + * !) Won't find "NativeMemoryTracking:" + * Code to create env variable not executed. + * 3) execute with invalid parameter: -XX:NativeMemoryTracking + * !) Won't find "NativeMemoryTracking:" + * Code to create env variable not executed. + * 4) give and invalid value and check to make sure JVM commented + */ + { // NativeMemoryTracking + String launcherPidString = "launcher.pid="; + String envVarPidString = "TRACER_MARKER: NativeMemoryTracking: env var is NMT_LEVEL_"; + String NMT_Option_Value = "off"; + String myClassName = "helloworld"; + boolean haveLauncherPid = false; + + // === Run the tests === + + // ---Test 1a + tr = doExec(envMap,javaCmd, "-XX:NativeMemoryTracking=" + NMT_Option_Value, + "-version"); + + // get the PID from the env var we set for the JVM + String envVarPid = null; + for (String line : tr.testOutput) { + if (line.contains(envVarPidString)) { + int sindex = envVarPidString.length(); + envVarPid = line.substring(sindex); + break; + } + } + // did we find envVarPid? + if (envVarPid == null) { + System.out.println(tr); + throw new RuntimeException("Error: failed to find env Var Pid in tracking info"); + } + // we think we found the pid string. min test, not "". + if (envVarPid.length() < 1) { + System.out.println(tr); + throw new RuntimeException("Error: env Var Pid in tracking info is empty string"); + } + + /* + * On Linux, Launcher Tracking will print the PID. Use this info + * to validate what we got as the PID in the Launcher itself. + * Linux is the only one that prints this, and trying to get it + * here for win is awful. So let the linux test make sure we get + * the valid pid, and for non-linux, just make sure pid string is + * non-zero. + */ + if (isLinux) { + // get what the test says is the launcher pid + String launcherPid = null; + for (String line : tr.testOutput) { + int index = line.indexOf(launcherPidString); + if (index >= 0) { + int sindex = index + launcherPidString.length(); + int tindex = sindex + line.substring(sindex).indexOf("'"); + System.out.println("DEBUG INFO: sindex = " + sindex); + System.out.println("DEBUG INFO: searching substring: " + line.substring(sindex)); + System.out.println("DEBUG INFO: tindex = " + tindex); + // DEBUG INFO + System.out.println(tr); + launcherPid = line.substring(sindex, tindex); + break; + } + } + if (launcherPid == null) { + System.out.println(tr); + throw new RuntimeException("Error: failed to find launcher Pid in launcher tracking info"); + } + + // did we create the env var with the correct pid? + if (!launcherPid.equals(envVarPid)) { + System.out.println(tr); + System.out.println("Error: wrong pid in creating env var"); + System.out.println("Error Info: launcherPid = " + launcherPid); + System.out.println("Error Info: envVarPid = " + envVarPid); + throw new RuntimeException("Error: wrong pid in creating env var"); + } + } + + + // --- Test 1b + if (!tr.contains("NativeMemoryTracking: got value " + NMT_Option_Value)) { + System.out.println(tr); + throw new RuntimeException("Error: Valid param failed to set env variable"); + } + + // --- Test 2 + tr = doExec(envMap,javaCmd, "-XX:NativeMemoryTracking=", + "-version"); + if (tr.contains("NativeMemoryTracking:")) { + System.out.println(tr); + throw new RuntimeException("Error: invalid param caused env variable to be erroneously created"); + } + if (!tr.contains("Syntax error, expecting -XX:NativeMemoryTracking=")) { + System.out.println(tr); + throw new RuntimeException("Error: invalid param not checked by JVM"); + } + + // --- Test 3 + tr = doExec(envMap,javaCmd, "-XX:NativeMemoryTracking", + "-version"); + if (tr.contains("NativeMemoryTracking:")) { + System.out.println(tr); + throw new RuntimeException("Error: invalid param caused env variable to be erroneously created"); + } + if (!tr.contains("Syntax error, expecting -XX:NativeMemoryTracking=")) { + System.out.println(tr); + throw new RuntimeException("Error: invalid param not checked by JVM"); + } + // --- Test 4 + tr = doExec(envMap,javaCmd, "-XX:NativeMemoryTracking=BADVALUE", + "-version"); + if (!tr.contains("expecting -XX:NativeMemoryTracking")) { + System.out.println(tr); + throw new RuntimeException("Error: invalid param did not get JVM Syntax error message"); + } + + } // NativeMemoryTracking + + // MacOSX specific tests ensue...... if (!isMacOSX) return;